Class: Rubygoo::TabGroup
- Inherits:
-
Object
- Object
- Rubygoo::TabGroup
- Defined in:
- lib/rubygoo/tab_group.rb
Overview
this class represents a collection of widgets that can be tabbed through
Instance Attribute Summary collapse
-
#selected_index ⇒ Object
Returns the value of attribute selected_index.
-
#widgets ⇒ Object
Returns the value of attribute widgets.
Instance Method Summary collapse
- #add(*widgets) ⇒ Object
- #focus(w) ⇒ Object
-
#initialize ⇒ TabGroup
constructor
A new instance of TabGroup.
- #next ⇒ Object
- #previous ⇒ Object
- #remove(*widgets) ⇒ Object
- #rotate(dir) ⇒ Object
Constructor Details
#initialize ⇒ TabGroup
Returns a new instance of TabGroup.
7 8 9 10 |
# File 'lib/rubygoo/tab_group.rb', line 7 def initialize() @widgets = [] @selected_index = 1 end |
Instance Attribute Details
#selected_index ⇒ Object
Returns the value of attribute selected_index.
5 6 7 |
# File 'lib/rubygoo/tab_group.rb', line 5 def selected_index @selected_index end |
#widgets ⇒ Object
Returns the value of attribute widgets.
5 6 7 |
# File 'lib/rubygoo/tab_group.rb', line 5 def @widgets end |
Instance Method Details
#add(*widgets) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubygoo/tab_group.rb', line 12 def add(*) .uniq.each do |w| unless @widgets.include? w if w.tab_to? @widgets << w w.focus_priority = @widgets.size unless w.focus_priority else if w.respond_to? :widgets and w..size > 0 add *w. end if w.respond_to? :queued_widgets and w..size > 0 add *w. end end end end @widgets.sort_by {|w| w.focus_priority} end |
#focus(w) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/rubygoo/tab_group.rb', line 48 def focus(w) index = @widgets.index w if index @widgets[@selected_index]._unfocus if @widgets[@selected_index] @selected_index = index @widgets[@selected_index]._focus end end |
#next ⇒ Object
40 41 42 |
# File 'lib/rubygoo/tab_group.rb', line 40 def next() rotate 1 end |
#previous ⇒ Object
44 45 46 |
# File 'lib/rubygoo/tab_group.rb', line 44 def previous() rotate -1 end |
#remove(*widgets) ⇒ Object
34 35 36 37 38 |
# File 'lib/rubygoo/tab_group.rb', line 34 def remove(*) .uniq.each do |w| @widgets.delete(w) end end |
#rotate(dir) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/rubygoo/tab_group.rb', line 57 def rotate(dir) if @widgets.size > 0 @widgets[@selected_index]._unfocus if @widgets[@selected_index] @selected_index += dir @selected_index %= @widgets.size @widgets[@selected_index]._focus end end |