toggle (cellium v0.1.0)

View Source

Toggle widget module for on/off switches.

Toggles are focusable widgets that can be switched with Enter or Space. They display as < ON > or < OFF >.

Usage

toggle:new(feature_toggle)

Properties

  • on (boolean): Whether the toggle is on. Default: false
  • focusable (boolean): Always true for toggles
  • focused (boolean): Set by focus manager when toggle has focus

Rendering

Format: < ON > or < OFF > When focused, colors are inverted to highlight the toggle.

Summary

Functions

Handles keyboard events for the toggle. Toggles ON/OFF state on Space or Enter.

Creates a new toggle widget in the OFF state.

Renders the toggle widget to the buffer.

Renders the toggle in focused state with inverted colors.

Functions

handle_event/2

-spec handle_event(term(), map()) -> map().

Handles keyboard events for the toggle. Toggles ON/OFF state on Space or Enter.

new(Id)

-spec new(term()) -> map().

Creates a new toggle widget in the OFF state.

render(Widget, Buffer)

-spec render(map(), map()) -> map().

Renders the toggle widget to the buffer.

render_focused(Widget, Buffer)

-spec render_focused(map(), map()) -> map().

Renders the toggle in focused state with inverted colors.