Class: Thaum::ProgressBar
- Inherits:
-
Object
- Object
- Thaum::ProgressBar
- Includes:
- Sigil
- Defined in:
- lib/thaum/sigils/progress_bar.rb
Overview
Horizontal progress bar. Two modes:
-
determinate (default): ‘value` is 0.0..1.0, fills proportionally.
-
indeterminate: a fixed-width block walks across the bar on each tick.
Non-focusable.
Constant Summary collapse
- INDETERMINATE_BLOCK_WIDTH =
6- INDETERMINATE_INTERVAL =
0.1
Instance Attribute Summary collapse
-
#indeterminate ⇒ Object
readonly
Returns the value of attribute indeterminate.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes included from Sigil
#handler_parent, #rect, #thaum_app
Instance Method Summary collapse
- #focusable? ⇒ Boolean
- #indeterminate? ⇒ Boolean
-
#initialize(value: 0.0, indeterminate: false) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #on_tick(event) ⇒ Object
- #render(canvas:, theme:) ⇒ Object
Methods included from Sigil
#emit, #focused?, #on_blur, #on_focus, #on_key, #on_mount, #on_mouse, #on_paste, #on_unmount, #on_update, #request_render
Constructor Details
#initialize(value: 0.0, indeterminate: false) ⇒ ProgressBar
Returns a new instance of ProgressBar.
17 18 19 20 21 22 |
# File 'lib/thaum/sigils/progress_bar.rb', line 17 def initialize(value: 0.0, indeterminate: false) @value = value @indeterminate = indeterminate @offset = 0 @elapsed = 0.0 end |
Instance Attribute Details
#indeterminate ⇒ Object (readonly)
Returns the value of attribute indeterminate.
15 16 17 |
# File 'lib/thaum/sigils/progress_bar.rb', line 15 def indeterminate @indeterminate end |
#value ⇒ Object
Returns the value of attribute value.
14 15 16 |
# File 'lib/thaum/sigils/progress_bar.rb', line 14 def value @value end |
Instance Method Details
#focusable? ⇒ Boolean
24 |
# File 'lib/thaum/sigils/progress_bar.rb', line 24 def focusable? = false |
#indeterminate? ⇒ Boolean
25 |
# File 'lib/thaum/sigils/progress_bar.rb', line 25 def indeterminate? = @indeterminate |
#on_tick(event) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/thaum/sigils/progress_bar.rb', line 27 def on_tick(event) return unless indeterminate? @elapsed += event.delta advanced = false while @elapsed >= INDETERMINATE_INTERVAL @elapsed -= INDETERMINATE_INTERVAL @offset += 1 advanced = true end request_render if advanced end |
#render(canvas:, theme:) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/thaum/sigils/progress_bar.rb', line 40 def render(canvas:, theme:) canvas.fill(bg: theme.bg) if indeterminate? render_indeterminate(canvas: canvas, theme: theme) else render_determinate(canvas: canvas, theme: theme) end end |