Add a declarative <Checkbox> widget with a controlled boolean binding and optional change handler. Supports inline text (children) or a text="..." attribute, plus common UX knobs like enabled, wrap, and tooltip.
- Covers a core form/setting control with an idiomatic, template-first API.
- Aligns with EFx’s controlled-input model (value comes from state; emits
onChange).
- Reduces imperative glue for simple preference panes and dialogs.
Scope
- Tag:
<Checkbox>
- Required:
checked={bool_expr}
- Optional attributes:
text="...", enabled=bool, wrap=bool, tooltip="...", id="..." (for stable identity)
- Events:
onChange={|checked: bool| ...} (fires once when the value toggles)
- Content: either
text="..." or inline text children (mutually exclusive; diagnostics on conflict)
Non-goals (here): tri-state/indeterminate mode, custom icons, per-state colors.
Proposed API (sketch)
Template
// With children text
efx!(ui, r#"
<Checkbox checked={prefs.notifications} onChange={|v| prefs.notifications = v} wrap="true">
Enable notifications
</Checkbox>
"#);
// With text attribute
efx!(ui, r#"
<Checkbox checked={prefs.autosave} text="Autosave files" tooltip="Saves every 5 minutes"/>
"#);
Conceptual mapping to egui
let mut val = /* bound bool */;
let mut widget = egui::Checkbox::new(&mut val, text_str); // text_str from children or text=""
widget = widget.wrap(wrap);
let resp = if enabled {
ui.add(widget)
} else {
ui.add_enabled(false, widget)
};
if let Some(tip) = tooltip { resp.on_hover_text(tip); }
if resp.changed() {
// emit onChange(val)
}
Tasks
Add a declarative
<Checkbox>widget with a controlled boolean binding and optional change handler. Supports inline text (children) or atext="..."attribute, plus common UX knobs likeenabled,wrap, andtooltip.onChange).Scope
<Checkbox>checked={bool_expr}text="...",enabled=bool,wrap=bool,tooltip="...",id="..."(for stable identity)onChange={|checked: bool| ...}(fires once when the value toggles)text="..."or inline text children (mutually exclusive; diagnostics on conflict)Non-goals (here): tri-state/indeterminate mode, custom icons, per-state colors.
Proposed API (sketch)
Template
Conceptual mapping to egui
Tasks
AST & parsing
<Checkbox>node withchecked(bool) and optionaltext,enabled,wrap,tooltip,id.text=...; error on both.Codegen
checked={expr}by value-copy to a local, pass&muttoegui::Checkbox, then write back if changed.onChange(bool)whenResponse::changed()is true.enabled=falseviaui.add_enabled(false, ...).wrapflag andtooltiponResponse.idusingegui::Idif provided (stable identity).Diagnostics
checkedor non-boolean type → clear compile error with expected type.text=present → actionable error (choose one).<Checkbox>.Examples & docs
text=).wrap.docs/cookbook.mdanddocs/tags.md.Tests
checked; wrong type; dual text sources; unknown attrs.onChangeexactly once.wasm32-unknown-unknown(no runtime launch).