Class: UI::GenericContainer

Inherits:
Widget
  • Object
show all
Defined in:
lib/ektoplayer/ui/widgets/container.rb

Instance Attribute Summary collapse

Attributes inherited from Widget

#pos, #size

Instance Method Summary collapse

Methods inherited from Widget

#display, #events, #invisible!, #invisible?, #key_press, #keys, #lock, #mouse, #mouse_event_transform, #mouse_section, #on_widget_raise, #raise_widget, #sub, #unlock, #visible!, #visible=, #visible?, #want_layout, #want_redraw, #want_refresh, #with_lock

Constructor Details

#initialize(widgets: [], **opts) ⇒ GenericContainer

Returns a new instance of GenericContainer.



7
8
9
10
11
# File 'lib/ektoplayer/ui/widgets/container.rb', line 7

def initialize(widgets: [], **opts)
   super(**opts)
   events.register(:changed)
   @selected, @selected_index, @widgets = nil, nil, widgets
end

Instance Attribute Details

#selectedObject

Returns the value of attribute selected.



5
6
7
# File 'lib/ektoplayer/ui/widgets/container.rb', line 5

def selected
  @selected
end

#selected_indexObject

Returns the value of attribute selected_index.



5
6
7
# File 'lib/ektoplayer/ui/widgets/container.rb', line 5

def selected_index
  @selected_index
end

#widgetsObject (readonly)

Returns the value of attribute widgets.



5
6
7
# File 'lib/ektoplayer/ui/widgets/container.rb', line 5

def widgets
  @widgets
end

Instance Method Details

#add(widget) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/ektoplayer/ui/widgets/container.rb', line 53

def add(widget)
   with_lock do
      @widgets << widget
      self.selected=(widget) unless @selected
      want_layout # important: layout, not redraw
   end
end

#drawObject



74
# File 'lib/ektoplayer/ui/widgets/container.rb', line 74

def draw;     visible_widgets.each(&:draw)     end

#layoutObject



76
# File 'lib/ektoplayer/ui/widgets/container.rb', line 76

def layout;   @widgets.each(&:layout)          end

#mouse_click(mevent) ⇒ Object



69
70
71
72
# File 'lib/ektoplayer/ui/widgets/container.rb', line 69

def mouse_click(mevent)
   visible_widgets.each { |w| w.mouse_click(mevent) }
   super(mevent)
end

#on_key_press(key) ⇒ Object



78
79
80
81
# File 'lib/ektoplayer/ui/widgets/container.rb', line 78

def on_key_press(key)
   @selected.key_press(key) if @selected
   super(key)
end

#refreshObject



75
# File 'lib/ektoplayer/ui/widgets/container.rb', line 75

def refresh;  visible_widgets.each(&:refresh)  end

#remove(widget) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/ektoplayer/ui/widgets/container.rb', line 61

def remove(widget)
   with_lock do
      self.selected=(nil) if @selected.equal?(widget)
      @widgets.delete widget
      want_layout # important: layout, not redraw
   end
end

#select_nextObject



83
84
85
86
# File 'lib/ektoplayer/ui/widgets/container.rb', line 83

def select_next
   return unless @selected
   self.selected_index=((@selected_index + 1) % @widgets.size)
end

#select_prevObject



88
89
90
91
92
# File 'lib/ektoplayer/ui/widgets/container.rb', line 88

def select_prev
   return unless @selected
   return self.selected_index=(@widgets.size - 1) if @selected_index == 0
   self.selected_index=(@selected_index - 1)
end

#visible_widgetsObject



13
14
15
# File 'lib/ektoplayer/ui/widgets/container.rb', line 13

def visible_widgets
   @widgets.select(&:visible?)
end

#winObject



49
50
51
# File 'lib/ektoplayer/ui/widgets/container.rb', line 49

def win
   (@selected or UI::Canvas).win
end