Class: Shoes::Slot

Inherits:
Object show all
Includes:
Mod
Defined in:
lib/shoes/slot.rb,
lib/shoes/style.rb

Direct Known Subclasses

Flow, Stack

Instance Attribute Summary (collapse)

Attributes included from Mod

#click_proc, #hover_proc, #hovered, #leave_proc, #margin_bottom, #margin_left, #margin_right, #margin_top, #release_proc

Instance Method Summary (collapse)

Methods included from Mod

#click, #hover, #leave, #release, #set_margin

Constructor Details

- (Slot) initialize(args = {})

Returns a new instance of Slot



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/shoes/slot.rb', line 4

def initialize args={}
  @initials = args
  args.each do |k, v|
    instance_variable_set "@#{k}", v
  end
  
  Slot.class_eval do
    attr_accessor *(args.keys - [:app])
  end

  set_margin

  @radio_group = Gtk::RadioButton.new
  @masked = @hovered = false
  @parent = @app.cslot
  @app.cslot = self
  @contents = []
  (@parent.contents << self) unless @nocontrol
  @shows = true
  if block_given?
    if args[:hidden]
      @shows = false
      BASIC_ATTRIBUTES_DEFAULT.merge! hidden: true
      SLOT_ATTRIBUTES_DEFAULT.merge! hidden: true
      @hidden_flag = true unless @parent.instance_variable_get '@hidden'
    end
    yield
    if @hidden_flag
      BASIC_ATTRIBUTES_DEFAULT.delete :hidden
      SLOT_ATTRIBUTES_DEFAULT.delete :hidden
    end
    @app.cslot = @parent
  else
    @left = @top = 0
  end
end

Instance Attribute Details

- (Object) app(&blk)



45
46
47
# File 'lib/shoes/slot.rb', line 45

def app &blk
  blk ? @app.instance_eval(&blk) : @app
end

- (Object) contents

Returns the value of attribute contents



41
42
43
# File 'lib/shoes/slot.rb', line 41

def contents
  @contents
end

- (Object) initials (readonly)

Returns the value of attribute initials



42
43
44
# File 'lib/shoes/slot.rb', line 42

def initials
  @initials
end

- (Object) masked

Returns the value of attribute masked



41
42
43
# File 'lib/shoes/slot.rb', line 41

def masked
  @masked
end

- (Object) parent (readonly)

Returns the value of attribute parent



42
43
44
# File 'lib/shoes/slot.rb', line 42

def parent
  @parent
end

- (Object) radio_group (readonly)

Returns the value of attribute radio_group



42
43
44
# File 'lib/shoes/slot.rb', line 42

def radio_group
  @radio_group
end

Instance Method Details

- (Object) after(e, &blk)



119
120
121
122
123
# File 'lib/shoes/slot.rb', line 119

def after e, &blk
  n = contents.index e
  n = n ? n+1 : contents.length
  prepend n, &blk
end

- (Object) append(&blk)



102
103
104
# File 'lib/shoes/slot.rb', line 102

def append &blk
  prepend contents.length, &blk
end

- (Object) before(e, &blk)



115
116
117
# File 'lib/shoes/slot.rb', line 115

def before e, &blk
  prepend contents.index(e).to_i, &blk
end

- (Object) clear(all = false, &blk)



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/shoes/slot.rb', line 81

def clear all = false, &blk
  all ? @contents.each(&:clear_all) : @contents.each(&:clear)
  @contents.each{|e| @app.mlcs.delete e; @app.mhcs.delete e}
  @contents = []
  if blk
    args = {}
    initials.keys.each{|k| args[k] = instance_variable_get "@#{k}"}
    args[:nocontrol] = true
    tmp = self.is_a?(Stack) ? Stack.new(@app.slot_attributes(args), &blk) : Flow.new(@app.slot_attributes(args), &blk)
    self.contents = tmp.contents
    contents.each{|e| e.parent = self if e.is_a? Basic}
    Shoes.call_back_procs @app
    Shoes.set_cursor_type @app
  end
end

- (Object) clear_all(&blk)



97
98
99
100
# File 'lib/shoes/slot.rb', line 97

def clear_all &blk
  @app.delete_mouse_events self
  clear true, &blk
end

- (Object) fix_size



79
# File 'lib/shoes/slot.rb', line 79

def fix_size; end

- (Object) hide



131
132
133
134
135
# File 'lib/shoes/slot.rb', line 131

def hide
  @contents.each &:hide
  @shows = false
  self
end

- (Object) move3(x, y)



49
50
51
# File 'lib/shoes/slot.rb', line 49

def move3 x, y
  @left, @top = x, y
end

- (Object) positioning(x, y, max)



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/shoes/slot.rb', line 53

def positioning x, y, max
  @width = (parent.width * @initials[:width]).to_i if @initials[:width].is_a? Float
  @width = (parent.width + @initials[:width]) if @initials[:width] < 0
  @width -= (margin_left + margin_right)
  if parent.is_a?(Flow) and x + @width <= parent.left + parent.width
    move3 x + parent.margin_left, max.top + parent.margin_top
    @height = Shoes.contents_alignment self
    max = self if max.height < @height
    flag = true
  else
    move3 parent.left + parent.margin_left, max.top + max.height + parent.margin_top
    @height = Shoes.contents_alignment self
    max = self
    flag = false
  end
  case @initials[:height]
  when 0
  when Float
    max.height = @height = (parent.height * @initials[:height]).to_i
  else
    max.height = @height = @initials[:height]
  end
  contents.each &:fix_size
  return max, flag
end

- (Object) prepend(n = 0)



106
107
108
109
110
111
112
113
# File 'lib/shoes/slot.rb', line 106

def prepend n = 0
  self.contents, tmp = contents[0...n], contents[n..-1]
  cslot, @app.cslot = @app.cslot, self
  yield
  self.contents += tmp
  @app.cslot = cslot
  Shoes.call_back_procs @app
end

- (Object) show



125
126
127
128
129
# File 'lib/shoes/slot.rb', line 125

def show
  @contents.each &:show
  @shows = true
  self
end

- (Object) style(args = nil)



65
66
67
68
# File 'lib/shoes/style.rb', line 65

def style args = nil
  args ? [:width, :height].each{|s| @initials[s] = args[s] if args[s]} :
    {width: @width, height: @height}
end

- (Object) toggle



137
138
139
140
# File 'lib/shoes/slot.rb', line 137

def toggle
  @shows ? hide : show
  self
end