button (cellium v0.1.0)

View Source

Button widget module for interactive clickable buttons.

Buttons are focusable widgets that can be activated with Enter or Space. When focused, they display with inverted colors or a border to indicate selection.

Usage

button:new(submit_btn, "Submit")

Properties

  • label (string): The text displayed on the button
  • focusable (boolean): Always true for buttons
  • focused (boolean): Set by focus manager when button has focus
  • height (integer): If >= 3, renders with a box border

Rendering

  • Height < 3: Simple text with brackets when focused: [Submit]
  • Height >= 3: Bordered box with centered label (double border when focused)
  • Focused state inverts foreground/background colors

Summary

Functions

Handles keyboard events for the button. Emits button_clicked event on Enter or Space.

Creates a new button widget with default label 'Button'.

Creates a new button widget with the specified label.

Renders the button widget to the buffer.

Functions

handle_event/2

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

Handles keyboard events for the button. Emits button_clicked event on Enter or Space.

new(Id)

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

Creates a new button widget with default label 'Button'.

new(Id, Label)

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

Creates a new button widget with the specified label.

render(Widget, Buffer)

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

Renders the button widget to the buffer.

render_focused(Widget, Buffer)

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