checkbox (cellium v0.1.0)

View Source

Checkbox widget module for togglable boolean options.

This module provides an interactive checkbox widget that displays a label with a checkable box. When focused, colors are inverted.

Usage

Basic checkbox:

checkbox:new(my_checkbox, "Enable feature")

Checkbox with initial checked state:

Widget = checkbox:new(my_checkbox, "Enable feature"),
CheckedWidget = Widget#{checked => true}

Properties

  • label (string): Text label displayed next to the checkbox
  • checked (boolean): Whether the checkbox is checked. Default: false
  • focusable (boolean): Set to true by default

Display

  • Unchecked: [ ] Label
  • Checked: [X] Label
  • When focused, foreground and background colors are swapped

Event Handling

Toggle the checkbox state in your update function when handling space or enter key events on this widget.

Summary

Functions

Handles keyboard events for the checkbox. Toggles checked state on Space or Enter.

Creates a new checkbox with default label 'Checkbox'.

Creates a new checkbox with the specified label.

Renders the checkbox in unfocused state.

Renders the checkbox in focused state with inverted colors.

Functions

handle_event/2

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

Handles keyboard events for the checkbox. Toggles checked state on Space or Enter.

new(Id)

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

Creates a new checkbox with default label 'Checkbox'.

new(Id, Label)

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

Creates a new checkbox with the specified label.

render(Widget, Buffer)

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

Renders the checkbox in unfocused state.

render_focused(Widget, Buffer)

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

Renders the checkbox in focused state with inverted colors.