Class: Charming::Components::Audio

Inherits:
Charming::Component show all
Defined in:
lib/charming/presentation/components/audio.rb

Overview

Audio is a one-line playback-status indicator for a Audio::Player. It reads the player’s ‘playing?` state and renders a play/stop glyph with an optional label; pair it with a controller timer (or `on_task` re-render) to keep it live.

Note: this view component (‘Charming::Components::Audio`) is distinct from the playback engine namespace (`Charming::Audio`) — the component only displays state, the engine spawns the sound.

Instance Method Summary collapse

Methods inherited from Charming::Component

#captures_text?

Methods inherited from View

#focused?, #layout_assigns

Constructor Details

#initialize(player:, label: nil, theme: nil) ⇒ Audio

player is the Audio::Player whose state is shown. label is an optional suffix (e.g. the track name) appended after the glyph. theme is the active theme, forwarded to the view layer.



16
17
18
19
20
# File 'lib/charming/presentation/components/audio.rb', line 16

def initialize(player:, label: nil, theme: nil)
  super(theme: theme)
  @player = player
  @label = label
end

Instance Method Details

#renderObject

Renders ‘▶`/`■` for playing/stopped, followed by the label when present.



23
24
25
26
27
28
# File 'lib/charming/presentation/components/audio.rb', line 23

def render
  glyph = @player.playing? ? "" : ""
  return glyph unless @label

  "#{glyph} #{@label}"
end