radio (cellium v0.1.0)

View Source

Radio button widget module for mutually exclusive options.

This module provides an interactive radio button widget that displays a label with a selectable button. Radio buttons are typically used in groups where only one option can be selected at a time.

Usage

Basic radio button:

radio:new(option_a, "Option A")

Radio button with selected state:

Widget = radio:new(option_a, "Option A"),
SelectedWidget = Widget#{selected => true}

Properties

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

Display

  • Unselected: ( ) Label
  • Selected: (*) Label
  • When focused, foreground and background colors are swapped

Event Handling

Set the selected state in your update function when handling space or enter key events. Remember to deselect other radio buttons in the same group.

Summary

Functions

Handles keyboard events for the radio button. Sets selected to true on Space or Enter.

Creates a new radio button with default label 'Radio'.

Creates a new radio button with the specified label.

Renders the radio button in unfocused state.

Renders the radio button in focused state with inverted colors.

Functions

handle_event/2

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

Handles keyboard events for the radio button. Sets selected to true on Space or Enter.

new(Id)

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

Creates a new radio button with default label 'Radio'.

new(Id, Label)

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

Creates a new radio button with the specified label.

render(Widget, Buffer)

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

Renders the radio button in unfocused state.

render_focused(Widget, Buffer)

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

Renders the radio button in focused state with inverted colors.