Class: Fidgit::Container
Abstract
- Inherits:
-
Element
show all
- Extended by:
- Forwardable
- Defined in:
- lib/fidgit/elements/container.rb
Overview
A container that contains Elements.
Constant Summary
Constants inherited
from Element
Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V
Instance Attribute Summary
Attributes inherited from Element
#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z
Instance Method Summary
collapse
-
#add(element) ⇒ Object
-
#button(text, options = {}, &block) ⇒ Object
Create a button within the container.
-
#clear ⇒ Object
-
#color_picker(options = {}, &block) ⇒ Object
Create a color picker within the container.
-
#color_well(options = {}, &block) ⇒ Object
Create a color well within the container.
-
#combo_box(options = {}, &block) ⇒ Object
-
#file_browser(type, options = {}, &block) ⇒ Object
-
#grid(options = {}, &block) ⇒ Object
Pack elements within the block in a grid (matrix) formation.
-
#group(options = {}, &block) ⇒ Object
-
#hit_element(x, y) ⇒ Element?
Returns the element within this container that was hit,.
-
#horizontal(options = {}, &block) ⇒ Object
Pack elements within the block horizontally.
-
#image_frame(image, options = {}, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Container
constructor
A new instance of Container.
-
#insert(position, element) ⇒ Object
-
#label(text, options = {}) ⇒ Object
Create a label within the container.
-
#list(options = {}, &block) ⇒ Object
-
#radio_button(text, value, options = {}, &block) ⇒ Object
-
#remove(element) ⇒ Object
-
#scroll_area(options = {}, &block) ⇒ Object
-
#scroll_window(options = {}, &block) ⇒ Object
-
#slider(options = {}, &block) ⇒ Object
-
#text_area(options = {}, &block) ⇒ Object
-
#to_s ⇒ Object
-
#toggle_button(text, options = {}, &block) ⇒ Object
-
#update ⇒ Object
-
#vertical(options = {}, &block) ⇒ Object
Pack elements within the blockvertically.
-
#write_tree(indent = "", index = 0) ⇒ Object
-
#x=(value) ⇒ Object
-
#y=(value) ⇒ Object
Methods inherited from Element
#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #width, #width=, #with, #x, #y
Methods included from Event
#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe
Constructor Details
#initialize(options = {}) ⇒ Container
Returns a new instance of Container.
24
25
26
27
28
29
30
|
# File 'lib/fidgit/elements/container.rb', line 24
def initialize(options = {})
options[:border_color] = default(:debug, :border_color) if Fidgit.debug_mode?
@children = []
super(options)
end
|
Instance Method Details
#add(element) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/fidgit/elements/container.rb', line 32
def add(element)
element.send :parent=, self
@children.push element
recalc
nil
end
|
Create a button within the container.
57
58
59
|
# File 'lib/fidgit/elements/container.rb', line 57
def button(text, options = {}, &block)
Button.new(text, {parent: self}.merge!(options), &block)
end
|
139
140
141
142
143
144
145
146
|
# File 'lib/fidgit/elements/container.rb', line 139
def clear
@children.each {|child| child.send :parent=, nil }
@children.clear
recalc
nil
end
|
#color_picker(options = {}, &block) ⇒ Object
Create a color picker within the container.
62
63
64
|
# File 'lib/fidgit/elements/container.rb', line 62
def color_picker(options = {}, &block)
ColorPicker.new({parent: self}.merge!(options), &block)
end
|
#color_well(options = {}, &block) ⇒ Object
Create a color well within the container.
67
68
69
|
# File 'lib/fidgit/elements/container.rb', line 67
def color_well(options = {}, &block)
ColorWell.new({parent: self}.merge!(options), &block)
end
|
#combo_box(options = {}, &block) ⇒ Object
71
72
73
|
# File 'lib/fidgit/elements/container.rb', line 71
def combo_box(options = {}, &block)
ComboBox.new({parent: self}.merge!(options), &block)
end
|
#file_browser(type, options = {}, &block) ⇒ Object
75
76
77
|
# File 'lib/fidgit/elements/container.rb', line 75
def file_browser(type, options = {}, &block)
FileBrowser.new(type, {parent: self}.merge!(options), &block)
end
|
#grid(options = {}, &block) ⇒ Object
Pack elements within the block in a grid (matrix) formation.
111
112
113
|
# File 'lib/fidgit/elements/container.rb', line 111
def grid(options = {}, &block)
Grid.new({ parent: self }.merge!(options), &block)
end
|
#group(options = {}, &block) ⇒ Object
79
80
81
|
# File 'lib/fidgit/elements/container.rb', line 79
def group(options = {}, &block)
Group.new({parent: self}.merge!(options), &block)
end
|
#hit_element(x, y) ⇒ Element?
Returns the element within this container that was hit,
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/fidgit/elements/container.rb', line 156
def hit_element(x, y)
@children.reverse_each do |child|
case child
when Container, Composite
if element = child.hit_element(x, y)
return element
end
else
return child if child.hit?(x, y)
end
end
self if hit?(x, y)
end
|
#horizontal(options = {}, &block) ⇒ Object
Pack elements within the block horizontally.
99
100
101
|
# File 'lib/fidgit/elements/container.rb', line 99
def horizontal(options = {}, &block)
Horizontal.new({ parent: self }.merge!(options), &block)
end
|
#image_frame(image, options = {}, &block) ⇒ Object
84
85
86
|
# File 'lib/fidgit/elements/container.rb', line 84
def image_frame(image, options = {}, &block)
ImageFrame.new(image, {parent: self}.merge!(options), &block)
end
|
#insert(position, element) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/fidgit/elements/container.rb', line 48
def insert(position, element)
@children.insert position, element
element.send :parent=, self
recalc
nil
end
|
#label(text, options = {}) ⇒ Object
Create a label within the container.
89
90
91
|
# File 'lib/fidgit/elements/container.rb', line 89
def label(text, options = {})
Label.new(text, {parent: self}.merge!(options))
end
|
#list(options = {}, &block) ⇒ Object
93
94
95
|
# File 'lib/fidgit/elements/container.rb', line 93
def list(options = {}, &block)
List.new({parent: self}.merge!(options), &block)
end
|
115
116
117
|
# File 'lib/fidgit/elements/container.rb', line 115
def radio_button(text, value, options = {}, &block)
RadioButton.new(text, value, {parent: self}.merge!(options), &block)
end
|
#remove(element) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/fidgit/elements/container.rb', line 40
def remove(element)
@children.delete element
element.send :parent=, nil
recalc
nil
end
|
119
120
121
|
# File 'lib/fidgit/elements/container.rb', line 119
def scroll_area(options = {}, &block)
ScrollArea.new({parent: self}.merge!(options), &block)
end
|
123
124
125
|
# File 'lib/fidgit/elements/container.rb', line 123
def scroll_window(options = {}, &block)
ScrollWindow.new({parent: self}.merge!(options), &block)
end
|
#slider(options = {}, &block) ⇒ Object
127
128
129
|
# File 'lib/fidgit/elements/container.rb', line 127
def slider(options = {}, &block)
Slider.new({parent: self}.merge!(options), &block)
end
|
#text_area(options = {}, &block) ⇒ Object
131
132
133
|
# File 'lib/fidgit/elements/container.rb', line 131
def text_area(options = {}, &block)
TextArea.new({parent: self}.merge!(options), &block)
end
|
187
188
189
|
# File 'lib/fidgit/elements/container.rb', line 187
def to_s
"#{super} [#{@children.size} #{@children.size == 1 ? 'child' : 'children'}]"
end
|
135
136
137
|
# File 'lib/fidgit/elements/container.rb', line 135
def toggle_button(text, options = {}, &block)
ToggleButton.new(text, {parent: self}.merge!(options), &block)
end
|
148
149
150
151
152
|
# File 'lib/fidgit/elements/container.rb', line 148
def update
@children.each { |c| c.update }
nil
end
|
#vertical(options = {}, &block) ⇒ Object
Pack elements within the blockvertically.
105
106
107
|
# File 'lib/fidgit/elements/container.rb', line 105
def vertical(options = {}, &block)
Vertical.new({ parent: self }.merge!(options), &block)
end
|
#write_tree(indent = "", index = 0) ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/fidgit/elements/container.rb', line 192
def write_tree(indent = "", index = 0)
puts self
indent = indent + " "
@children.each.with_index do |element, i|
print "#{indent}#{i}: "
case element
when Container
element.write_tree(indent)
else
puts element
end
end
end
|
#x=(value) ⇒ Object
11
12
13
14
|
# File 'lib/fidgit/elements/container.rb', line 11
def x=(value)
@children.each {|c| c.x += value - x }
super(value)
end
|
#y=(value) ⇒ Object
16
17
18
19
|
# File 'lib/fidgit/elements/container.rb', line 16
def y=(value)
@children.each {|c| c.y += value - y }
super(value)
end
|