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.
25
26
27
28
29
30
31
|
# File 'lib/fidgit/elements/container.rb', line 25
def initialize(options = {})
options[:border_color] = default(:debug, :border_color) if Fidgit.debug_mode?
@children = []
super(options)
end
|
Instance Method Details
#add(element) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/fidgit/elements/container.rb', line 33
def add(element)
element.send :parent=, self
@children.push element
recalc
nil
end
|
Create a button within the container.
58
59
60
|
# File 'lib/fidgit/elements/container.rb', line 58
def button(text, options = {}, &block)
Button.new(text, {parent: self}.merge!(options), &block)
end
|
140
141
142
143
144
145
146
147
|
# File 'lib/fidgit/elements/container.rb', line 140
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.
63
64
65
|
# File 'lib/fidgit/elements/container.rb', line 63
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.
68
69
70
|
# File 'lib/fidgit/elements/container.rb', line 68
def color_well(options = {}, &block)
ColorWell.new({parent: self}.merge!(options), &block)
end
|
#combo_box(options = {}, &block) ⇒ Object
72
73
74
|
# File 'lib/fidgit/elements/container.rb', line 72
def combo_box(options = {}, &block)
ComboBox.new({parent: self}.merge!(options), &block)
end
|
#file_browser(type, options = {}, &block) ⇒ Object
76
77
78
|
# File 'lib/fidgit/elements/container.rb', line 76
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.
112
113
114
|
# File 'lib/fidgit/elements/container.rb', line 112
def grid(options = {}, &block)
Grid.new({ parent: self }.merge!(options), &block)
end
|
#group(options = {}, &block) ⇒ Object
80
81
82
|
# File 'lib/fidgit/elements/container.rb', line 80
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,
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/fidgit/elements/container.rb', line 157
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.
100
101
102
|
# File 'lib/fidgit/elements/container.rb', line 100
def horizontal(options = {}, &block)
Horizontal.new({ parent: self }.merge!(options), &block)
end
|
#image_frame(image, options = {}, &block) ⇒ Object
85
86
87
|
# File 'lib/fidgit/elements/container.rb', line 85
def image_frame(image, options = {}, &block)
ImageFrame.new(image, {parent: self}.merge!(options), &block)
end
|
#insert(position, element) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/fidgit/elements/container.rb', line 49
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.
90
91
92
|
# File 'lib/fidgit/elements/container.rb', line 90
def label(text, options = {})
Label.new(text, {parent: self}.merge!(options))
end
|
#list(options = {}, &block) ⇒ Object
94
95
96
|
# File 'lib/fidgit/elements/container.rb', line 94
def list(options = {}, &block)
List.new({parent: self}.merge!(options), &block)
end
|
116
117
118
|
# File 'lib/fidgit/elements/container.rb', line 116
def radio_button(text, value, options = {}, &block)
RadioButton.new(text, value, {parent: self}.merge!(options), &block)
end
|
#remove(element) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/fidgit/elements/container.rb', line 41
def remove(element)
@children.delete element
element.send :parent=, nil
recalc
nil
end
|
120
121
122
|
# File 'lib/fidgit/elements/container.rb', line 120
def scroll_area(options = {}, &block)
ScrollArea.new({parent: self}.merge!(options), &block)
end
|
124
125
126
|
# File 'lib/fidgit/elements/container.rb', line 124
def scroll_window(options = {}, &block)
ScrollWindow.new({parent: self}.merge!(options), &block)
end
|
#slider(options = {}, &block) ⇒ Object
128
129
130
|
# File 'lib/fidgit/elements/container.rb', line 128
def slider(options = {}, &block)
Slider.new({parent: self}.merge!(options), &block)
end
|
#text_area(options = {}, &block) ⇒ Object
132
133
134
|
# File 'lib/fidgit/elements/container.rb', line 132
def text_area(options = {}, &block)
TextArea.new({parent: self}.merge!(options), &block)
end
|
188
189
190
|
# File 'lib/fidgit/elements/container.rb', line 188
def to_s
"#{super} [#{@children.size} #{@children.size == 1 ? 'child' : 'children'}]"
end
|
136
137
138
|
# File 'lib/fidgit/elements/container.rb', line 136
def toggle_button(text, options = {}, &block)
ToggleButton.new(text, {parent: self}.merge!(options), &block)
end
|
149
150
151
152
153
|
# File 'lib/fidgit/elements/container.rb', line 149
def update
@children.each { |c| c.update }
nil
end
|
#vertical(options = {}, &block) ⇒ Object
Pack elements within the blockvertically.
106
107
108
|
# File 'lib/fidgit/elements/container.rb', line 106
def vertical(options = {}, &block)
Vertical.new({ parent: self }.merge!(options), &block)
end
|
#write_tree(indent = "", index = 0) ⇒ Object
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/fidgit/elements/container.rb', line 193
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
12
13
14
15
|
# File 'lib/fidgit/elements/container.rb', line 12
def x=(value)
@children.each {|c| c.x += value - x }
super(value)
end
|
#y=(value) ⇒ Object
17
18
19
20
|
# File 'lib/fidgit/elements/container.rb', line 17
def y=(value)
@children.each {|c| c.y += value - y }
super(value)
end
|