Class: Thaum::Button
- Inherits:
-
Object
- Object
- Thaum::Button
- Includes:
- Sigil
- Defined in:
- lib/thaum/sigils/button.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Attributes included from Sigil
#handler_parent, #rect, #thaum_app
Instance Method Summary collapse
- #disabled? ⇒ Boolean
- #focusable? ⇒ Boolean
-
#initialize(label:, disabled: false) ⇒ Button
constructor
A new instance of Button.
- #on_key(event) ⇒ Object
- #render(canvas:, theme:) ⇒ Object
Methods included from Sigil
#emit, #focused?, #on_blur, #on_focus, #on_mount, #on_mouse, #on_paste, #on_tick, #on_unmount, #on_update, #request_render
Constructor Details
#initialize(label:, disabled: false) ⇒ Button
Returns a new instance of Button.
11 12 13 14 |
# File 'lib/thaum/sigils/button.rb', line 11 def initialize(label:, disabled: false) @label = label @disabled = disabled end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
9 10 11 |
# File 'lib/thaum/sigils/button.rb', line 9 def label @label end |
Instance Method Details
#disabled? ⇒ Boolean
16 |
# File 'lib/thaum/sigils/button.rb', line 16 def disabled? = @disabled |
#focusable? ⇒ Boolean
17 |
# File 'lib/thaum/sigils/button.rb', line 17 def focusable? = !@disabled |
#on_key(event) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/thaum/sigils/button.rb', line 19 def on_key(event) case event.key when :enter, " " then activate else emit event end end |
#render(canvas:, theme:) ⇒ Object
26 27 28 29 30 |
# File 'lib/thaum/sigils/button.rb', line 26 def render(canvas:, theme:) fg, bg = colors(theme) canvas.fill(bg: bg) if bg canvas.text(content: @label, fg: fg, bg: bg, align: :center) end |