Skip to content

Checkbox

Checkbox represents a controlled on/off choice that can be selected independently of neighboring checkboxes.

Checkbox("Include diagnostics", include_diagnostics)
.OnChanged([include_diagnostics](bool checked) {
include_diagnostics = checked;
})

Construct it with a bool or State<bool>, with or without a StringVariant label. The state overload reads the current value; OnChanged emits the requested next value and does not mutate the state automatically.

The shared activation path supports pointer input, Enter, and Space. Enabled(false) disables activation and applies disabled styling.

CheckboxStyle controls box size, interactive and state-layer size, checked fill, checkmark, unchecked border, disabled colors, border width, and radius. Checkbox role, checked state, label, focus, and activate action are exposed automatically to accessibility services.

  • Constructors: Checkbox(bool|State<bool>) and Checkbox(StringVariant, bool|State<bool>).
  • Event: .OnChanged(function) with bool.
  • Theme style: CheckboxStyle.

Use RadioButton for one choice in a mutually exclusive group and Switch for an immediately applied setting.

The four overloads in <huxerui/view.h> accept (bool), (const State<bool>&), (StringVariant, bool), and (StringVariant, const State<bool>&). They all declare the same controlled boolean. There is no indeterminate/three-state overload. A group-level “partially selected” indicator needs a separately designed control rather than a third boolean interpretation.

OnChanged accepts void(bool) and proposes the inverse of the current checked value. Keyboard and accessibility activation follow the same path. For the unlabeled form, provide an accessible name with Semantics{.label = "…"}; nearby text is not automatically a semantic label.

CheckboxStyle field Effect
size Visible box dimensions.
minimum_interactive_size, state_layer_size Hit-target and feedback dimensions, independently of the box.
checked_background, checkmark Selected fill and mark.
unchecked_border Unselected outline, including its stroke.
disabled_checked_background, disabled_checkmark, disabled_unchecked_border Disabled counterparts.
corner_radii Box corners.

Material enlarges the interactive/state-layer area around its box; Flat uses a compact baseline. Keep boolean state even while disabled; Enabled(false) changes availability, not the application’s saved choice.