Class: Ektoplayer::Views::TabBar
Instance Attribute Summary
Attributes inherited from UI::Pad
#win
Attributes inherited from UI::Widget
#pos, #size
Instance Method Summary
collapse
Methods inherited from UI::Pad
#bottom, #down, #layout, #mouse_click, #noutrefresh, #pad_mincol=, #pad_minrow=, #pad_size=, #page_down, #page_up, #refresh, #top, #up, #with_mouse_section_event
Methods inherited from UI::Widget
#display, #events, #invisible!, #invisible?, #key_press, #keys, #layout, #lock, #mouse, #mouse_click, #mouse_event_transform, #mouse_section, #on_key_press, #on_widget_raise, #raise_widget, #refresh, #sub, #unlock, #visible!, #visible=, #visible?, #want_layout, #want_redraw, #want_refresh, #with_lock
Constructor Details
#initialize(**opts) ⇒ TabBar
7
8
9
10
11
|
# File 'lib/ektoplayer/views/tabbar.rb', line 7
def initialize(**opts)
super(**opts)
events.register(:tab_clicked)
@selected, @tabs = 0, []
end
|
Instance Method Details
#add(title) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/ektoplayer/views/tabbar.rb', line 13
def add(title)
with_lock do
@tabs << title
want_redraw
end
end
|
#draw ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/ektoplayer/views/tabbar.rb', line 30
def draw
self.pad_size=(@size.update(height: 1))
mouse_section.clear
@win.erase
@win.move(0,0)
@tabs.each_with_index do |title, i|
mevent = with_mouse_section_event do
if i == @selected
@win.attrset(Theme[:'tabbar.selected'])
else
@win.attrset(Theme[:'tabbar.unselected'])
end
@win << title.to_s
@win.addch(32)
end
mevent.on(ICurses::BUTTON1_CLICKED) do
trigger(@events, :tab_clicked, i)
end
end
end
|
#selected=(index) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/ektoplayer/views/tabbar.rb', line 20
def selected=(index)
index = index.clamp(0, @tabs.size - 1)
return if index == @selected
with_lock do
@selected = index
want_redraw
end
end
|