Class: Rubygoo::TabGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygoo/tab_group.rb

Overview

this class represents a collection of widgets that can be tabbed through

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTabGroup

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_indexObject

Returns the value of attribute selected_index.



5
6
7
# File 'lib/rubygoo/tab_group.rb', line 5

def selected_index
  @selected_index
end

#widgetsObject

Returns the value of attribute widgets.



5
6
7
# File 'lib/rubygoo/tab_group.rb', line 5

def widgets
  @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(*widgets)

  widgets.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.widgets.size > 0
          add *w.widgets
         end
         if w.respond_to? :queued_widgets and w.queued_widgets.size > 0
          add *w.queued_widgets
         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

#nextObject



40
41
42
# File 'lib/rubygoo/tab_group.rb', line 40

def next()
  rotate 1
end

#previousObject



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(*widgets)
  widgets.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