Class: Thaum::Spinner

Inherits:
Object
  • Object
show all
Includes:
Sigil
Defined in:
lib/thaum/sigils/spinner.rb

Overview

Animated activity indicator. Advances one frame per ‘interval` seconds, driven by tick deltas (not wall clock — works with whatever tick rate the app runs at). Non-focusable.

Constant Summary collapse

DEFAULT_FRAMES =
%w[         ].freeze

Instance Attribute Summary collapse

Attributes included from Sigil

#handler_parent, #rect, #thaum_app

Instance Method Summary collapse

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(frames: DEFAULT_FRAMES, interval: 0.1) ⇒ Spinner

Returns a new instance of Spinner.



14
15
16
17
18
19
# File 'lib/thaum/sigils/spinner.rb', line 14

def initialize(frames: DEFAULT_FRAMES, interval: 0.1)
  @frames    = frames
  @interval  = interval
  @frame     = 0
  @elapsed   = 0.0
end

Instance Attribute Details

#frameObject (readonly)

Returns the value of attribute frame.



12
13
14
# File 'lib/thaum/sigils/spinner.rb', line 12

def frame
  @frame
end

#framesObject (readonly)

Returns the value of attribute frames.



12
13
14
# File 'lib/thaum/sigils/spinner.rb', line 12

def frames
  @frames
end

#intervalObject (readonly)

Returns the value of attribute interval.



12
13
14
# File 'lib/thaum/sigils/spinner.rb', line 12

def interval
  @interval
end

Instance Method Details

#focusable?Boolean

Returns:

  • (Boolean)


21
# File 'lib/thaum/sigils/spinner.rb', line 21

def focusable? = false

#on_tick(event) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/thaum/sigils/spinner.rb', line 23

def on_tick(event)
  @elapsed += event.delta
  advanced = false
  while @elapsed >= @interval
    @elapsed -= @interval
    @frame = (@frame + 1) % @frames.length
    advanced = true
  end
  request_render if advanced
end

#render(canvas:, theme:) ⇒ Object



34
35
36
37
# File 'lib/thaum/sigils/spinner.rb', line 34

def render(canvas:, theme:)
  canvas.fill(bg: theme.bg)
  canvas.text(content: @frames[@frame], fg: theme.accent, bg: theme.bg)
end