Skip to main content

CheckBox

widget.CheckBox is a focusable boolean toggle rendered as [ ] label (unchecked) or [x] label (checked).

Basic usage

cb := widget.NewCheckBox("Enable notifications")

Builder options

MethodDescription
WithStyle(s latte.Style)Override the display style
WithID(id string)Set a stable identifier for Canvas.GetValue(id)
WithOnToggle(fn func(bool))Callback fired when the checked state changes

Toggle callback

cb := widget.NewCheckBox("Dark mode").
WithOnToggle(func(checked bool) {
if checked {
// apply dark mode
}
})

Reading and setting state

cb.SetChecked(true)
isOn := cb.IsChecked()

CheckBox also implements oat.ValueGetter: Canvas.GetValue(id) returns the current checked state as a bool.

Key bindings

KeyAction
Space or EnterToggle checked state
Tab / Shift+TabMove focus