Class: Rubygoo::Container
Direct Known Subclasses
Constant Summary
Constants inherited from Widget
Instance Attribute Summary collapse
-
#bg_color ⇒ Object
Returns the value of attribute bg_color.
-
#queued_widgets ⇒ Object
Returns the value of attribute queued_widgets.
-
#rect ⇒ Object
Returns the value of attribute rect.
-
#widgets ⇒ Object
Returns the value of attribute widgets.
Attributes inherited from Widget
#app, #container, #enabled, #focus_priority, #focussed, #goo_id, #h, #mouse_over, #opts, #padding_left, #padding_top, #parent, #relative, #visible, #w, #x, #y
Instance Method Summary collapse
-
#_draw(adapter) ⇒ Object
draw ourself and our children.
-
#_key_pressed(event) ⇒ Object
pass on the key press to our widgets.
-
#_key_released(event) ⇒ Object
pass on the key release to our widgets.
-
#_mouse_down(event) ⇒ Object
called when there is a mouse click.
-
#_mouse_drag(event) ⇒ Object
called when there is a mouse release after dragging.
-
#_mouse_dragging(event) ⇒ Object
called when there is motion w/ the mouse button down.
-
#_mouse_motion(event) ⇒ Object
called when there is a mouse motion.
-
#_mouse_up(event) ⇒ Object
called when there is a mouse release.
-
#_update(time) ⇒ Object
called each update cycle with the amount of time that has passed.
-
#add(*widgets) ⇒ Object
Add widget(s) to the container.
-
#added ⇒ Object
called when we are added to another container.
-
#clear ⇒ Object
Remove all our children from the container.
-
#get(id) ⇒ Object
returns the child widget with the id passed in.
-
#initialize(opts = {}) ⇒ Container
constructor
A new instance of Container.
-
#remove(*widgets) ⇒ Object
Remove widget(s) to the container.
-
#resize(w) ⇒ Object
called when we need to update our size.
-
#tab_to? ⇒ Boolean
does this widget want tabbed focus? Containers don’t usually.
Methods inherited from Widget
#_focus, #_unfocus, #contains?, #disable, #draw, #enable, #enabled?, #focus, #focussed?, #get_color, goo_prop, #hide, inherited, #key_pressed, #key_released, #modal?, #mouse_down, #mouse_drag, #mouse_dragging, #mouse_enter, #mouse_exit, #mouse_motion, #mouse_over?, #mouse_up, #removed, #show, #theme_property, #unfocus, #update, #update_rect, #visible?
Methods included from Inflector
#camelize, #classify, #constantize, #dasherize, #demodulize, #foreign_key, #humanize, #inflections, #ordinalize, #pluralize, #singularize, #tableize, #titleize, #underscore
Constructor Details
#initialize(opts = {}) ⇒ Container
Returns a new instance of Container.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rubygoo/container.rb', line 5 def initialize(opts={}) @auto_resize = opts[:auto_resize] # cannot get this if we don't have an app yet @bg_color = theme_property :bg_color if self.app @queued_widgets = [] @widgets = [] @modal_widgets = [] super opts end |
Instance Attribute Details
#bg_color ⇒ Object
Returns the value of attribute bg_color.
3 4 5 |
# File 'lib/rubygoo/container.rb', line 3 def bg_color @bg_color end |
#queued_widgets ⇒ Object
Returns the value of attribute queued_widgets.
3 4 5 |
# File 'lib/rubygoo/container.rb', line 3 def @queued_widgets end |
#rect ⇒ Object
Returns the value of attribute rect.
3 4 5 |
# File 'lib/rubygoo/container.rb', line 3 def rect @rect end |
#widgets ⇒ Object
Returns the value of attribute widgets.
3 4 5 |
# File 'lib/rubygoo/container.rb', line 3 def @widgets end |
Instance Method Details
#_draw(adapter) ⇒ Object
draw ourself and our children
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rubygoo/container.rb', line 80 def _draw(adapter) # any container specific code here (border_colors?) if @bg_color if app == self adapter.fill_screen @bg_color else x1 = @rect[0] y1 = @rect[1] x2 = @rect[2] + x1 y2 = @rect[3] + y1 adapter.fill x1, y1, x2, y2, @bg_color end end draw adapter unless app == self # draw kiddies @widgets.select{|w|w.visible?}.each do |w| w._draw adapter end end |
#_key_pressed(event) ⇒ Object
pass on the key press to our widgets
142 143 144 145 146 147 |
# File 'lib/rubygoo/container.rb', line 142 def _key_pressed(event) key_pressed event @widgets.select{|w| w.enabled? and w.focussed?}.each do |w| w._key_pressed event end end |
#_key_released(event) ⇒ Object
pass on the key release to our widgets
150 151 152 153 154 155 |
# File 'lib/rubygoo/container.rb', line 150 def _key_released(event) key_released event @widgets.select{|w| w.enabled? and w.focussed?}.each do |w| w._key_released event end end |
#_mouse_down(event) ⇒ Object
called when there is a mouse click
110 111 112 113 114 115 |
# File 'lib/rubygoo/container.rb', line 110 def _mouse_down(event) mouse_down event @widgets.select{|w|w.enabled? and w.contains? event.data[:x],event.data[:y] }.each do |w| w._mouse_down event end end |
#_mouse_drag(event) ⇒ Object
called when there is a mouse release after dragging
126 127 128 129 130 131 |
# File 'lib/rubygoo/container.rb', line 126 def _mouse_drag(event) mouse_drag event @widgets.select{|w| w.contains? event.data[:x],event.data[:y] and w.enabled?}.each do |w| w._mouse_drag event end end |
#_mouse_dragging(event) ⇒ Object
called when there is motion w/ the mouse button down
134 135 136 137 138 139 |
# File 'lib/rubygoo/container.rb', line 134 def _mouse_dragging(event) mouse_dragging event @widgets.select{|w| w.contains? event.data[:x],event.data[:y] and w.enabled?}.each do |w| w._mouse_dragging event end end |
#_mouse_motion(event) ⇒ Object
called when there is a mouse motion
102 103 104 105 106 107 |
# File 'lib/rubygoo/container.rb', line 102 def _mouse_motion(event) mouse_motion event @widgets.select{|w|w.enabled?}.each do |w| w._mouse_motion event end end |
#_mouse_up(event) ⇒ Object
called when there is a mouse release
118 119 120 121 122 123 |
# File 'lib/rubygoo/container.rb', line 118 def _mouse_up(event) mouse_up event @widgets.select{|w| w.contains? event.data[:x],event.data[:y] and w.enabled?}.each do |w| w._mouse_up event end end |
#_update(time) ⇒ Object
called each update cycle with the amount of time that has passed. useful for animations, etc
159 160 161 162 163 164 |
# File 'lib/rubygoo/container.rb', line 159 def _update(time) update time unless app == self @widgets.select{|w|w.enabled?}.each do |w| w._update time end end |
#add(*widgets) ⇒ Object
Add widget(s) to the container.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubygoo/container.rb', line 24 def add(*) .uniq.each do |w| unless @widgets.include? w if self.app if w.relative w.x += @x w.y += @y w.update_rect end w.container = self w.parent = self w.app = self.app if !modal? and w.tab_to? and !w.modal? w.app. w end w.added if @auto_resize w.when :resized do || resize end end @widgets << w else @queued_widgets << w end end end end |
#added ⇒ Object
called when we are added to another container
17 18 19 20 21 |
# File 'lib/rubygoo/container.rb', line 17 def added() @bg_color = theme_property :bg_color add *@queued_widgets @queued_widgets = [] end |
#clear ⇒ Object
Remove all our children from the container.
69 70 71 72 73 74 75 76 77 |
# File 'lib/rubygoo/container.rb', line 69 def clear() = @widgets + @queued_widgets + @modal_widgets @widgets = [] @queued_widgets = [] @modal_widgets = [] .each do |w| w.removed end end |
#get(id) ⇒ Object
returns the child widget with the id passed in
192 193 194 195 196 197 |
# File 'lib/rubygoo/container.rb', line 192 def get(id) @widgets.each do |w| found_w = w.get(id) return found_w if found_w end end |
#remove(*widgets) ⇒ Object
Remove widget(s) to the container.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rubygoo/container.rb', line 57 def remove(*) .uniq.each do |w| = @widgets.delete(w) = @queued_widgets.delete(w) = @modal_widgets.delete(w) if or or w.removed end end end |
#resize(w) ⇒ Object
called when we need to update our size
172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/rubygoo/container.rb', line 172 def resize(w) # check the rects of all our children? max_w = 1 max_h = 1 @widgets.each do |w| w_width = w.x + w.w w_height = w.y + w.h max_w = w_width if w_width > max_w max_h = w_height if w_height > max_h end @w = max_w - @x + 2*@padding_left @h = max_h - @y + 2*@padding_top update_rect end |
#tab_to? ⇒ Boolean
does this widget want tabbed focus? Containers don’t usually
167 168 169 |
# File 'lib/rubygoo/container.rb', line 167 def tab_to? false end |