Class: Thaum::StatusBar
- Inherits:
-
Object
- Object
- Thaum::StatusBar
- Includes:
- Sigil
- Defined in:
- lib/thaum/sigils/status_bar.rb
Overview
Horizontal bar of labeled segments separated by a configurable delimiter. Segments are either plain Strings (decorative) or Hashes ‘{ label:, on_click: }` whose click handler fires when the user left-presses inside the segment’s column range. Non-focusable —status bars sit at the bottom of the focus order. Mouse events the bar does not act on are eaten (not propagated) so the bar acts as the floor of the click target.
Constant Summary collapse
- DEFAULT_SEPARATOR =
" │ "
Instance Attribute Summary collapse
-
#segments ⇒ Object
Returns the value of attribute segments.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Attributes included from Sigil
#handler_parent, #rect, #thaum_app
Instance Method Summary collapse
- #focusable? ⇒ Boolean
-
#initialize(segments:, separator: DEFAULT_SEPARATOR) ⇒ StatusBar
constructor
A new instance of StatusBar.
- #on_mouse(event) ⇒ Object
- #render(canvas:, theme:) ⇒ Object
Methods included from Sigil
#emit, #focused?, #on_blur, #on_focus, #on_key, #on_mount, #on_paste, #on_tick, #on_unmount, #on_update, #request_render
Constructor Details
#initialize(segments:, separator: DEFAULT_SEPARATOR) ⇒ StatusBar
Returns a new instance of StatusBar.
18 19 20 21 22 |
# File 'lib/thaum/sigils/status_bar.rb', line 18 def initialize(segments:, separator: DEFAULT_SEPARATOR) @segments = segments @separator = separator @ranges = [] # parallel array: [start_col, end_col_exclusive] per segment end |
Instance Attribute Details
#segments ⇒ Object
Returns the value of attribute segments.
16 17 18 |
# File 'lib/thaum/sigils/status_bar.rb', line 16 def segments @segments end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
16 17 18 |
# File 'lib/thaum/sigils/status_bar.rb', line 16 def separator @separator end |
Instance Method Details
#focusable? ⇒ Boolean
24 |
# File 'lib/thaum/sigils/status_bar.rb', line 24 def focusable? = false |
#on_mouse(event) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/thaum/sigils/status_bar.rb', line 31 def on_mouse(event) return unless event.action == :press && event. == :left seg = segment_at(event.x) or return handler = on_click(seg) or return if handler.arity.zero? handler.call else handler.call(event) end end |
#render(canvas:, theme:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/thaum/sigils/status_bar.rb', line 43 def render(canvas:, theme:) canvas.fill(bg: theme.) @ranges = [] x = 0 width = canvas.width @segments.each_with_index do |seg, idx| x += draw_separator(canvas: canvas, theme: theme, x: x, width: width) if idx.positive? break if x >= width label = label(seg) label_w = label.display_width start = x canvas.text(content: label, x: x, fg: theme.fg, bg: theme.) x += label_w finish = [x, width].min @ranges << [start, finish] end end |