Class: Thaum::Tabs
Overview
Horizontal tab strip. ←/→ cycle the active tab (with wrap). Emits Tabs::ActivatedEvent when the active index changes. The content under each tab is the App’s concern — Tabs only owns the strip.
Constant Summary collapse
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
Attributes included from Sigil
#handler_parent, #rect, #thaum_app
Instance Method Summary collapse
- #current ⇒ Object
-
#initialize(labels:, active: 0) ⇒ Tabs
constructor
A new instance of Tabs.
- #on_key(event) ⇒ Object
- #render(canvas:, theme:) ⇒ Object
Methods included from Sigil
#emit, #focusable?, #focused?, #on_blur, #on_focus, #on_mount, #on_mouse, #on_paste, #on_tick, #on_unmount, #on_update, #request_render
Constructor Details
#initialize(labels:, active: 0) ⇒ Tabs
Returns a new instance of Tabs.
14 15 16 17 18 19 |
# File 'lib/thaum/sigils/tabs.rb', line 14 def initialize(labels:, active: 0) raise ArgumentError, "Tabs needs at least one label" if labels.empty? @labels = labels @active = active.clamp(0, labels.length - 1) end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
12 13 14 |
# File 'lib/thaum/sigils/tabs.rb', line 12 def active @active end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
12 13 14 |
# File 'lib/thaum/sigils/tabs.rb', line 12 def labels @labels end |
Instance Method Details
#current ⇒ Object
21 |
# File 'lib/thaum/sigils/tabs.rb', line 21 def current = @labels[@active] |
#on_key(event) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/thaum/sigils/tabs.rb', line 23 def on_key(event) case event.key when :left then move(-1) when :right then move(1) else emit event end end |
#render(canvas:, theme:) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/thaum/sigils/tabs.rb', line 31 def render(canvas:, theme:) canvas.fill(bg: theme.) x = 0 @labels.each_with_index do |label, idx| x += draw_tab(canvas: canvas, label: label, idx: idx, x: x, theme: theme) end end |