toggle
Builds Toggle ToggleGroup


The code that drew it
A still frame holds a repeating animation at its first frame and a one-shot at its last, because a still of a moving thing is not reproducible. Run the gallery to review motion.
fn toggle(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
stack(&theme)
.child(caption(&theme, "A button that stays in"))
.child(
row(&theme)
.child(
Toggle::new("scene.toggle.bold")
.label("Bold")
.pressed(true)
.on_press(|_, _, _| {}),
)
.child(
Toggle::new("scene.toggle.italic")
.label("Italic")
.on_press(|_, _, _| {}),
)
.child(
Toggle::new("scene.toggle.review")
.label("Review mode")
.secondary()
.pressed(true)
.on_press(|_, _, _| {}),
)
.child(
Toggle::new("scene.toggle.locked")
.label("Locked")
.disabled(true),
),
)
.child(caption(&theme, "Any number in at once"))
.child(
ToggleGroup::new("scene.toggle-group.format")
.label("Formatting")
.selection(ToggleSelection::Any)
.items([
ToggleItem::new("bold", "Bold"),
ToggleItem::new("italic", "Italic"),
ToggleItem::new("underline", "Underline").disabled(true),
])
.pressed_ids(&["bold", "italic"])
.on_change(|_, _, _, _| {}),
)
.child(caption(
&theme,
"One or none, which a segmented strip cannot say",
))
.child(
ToggleGroup::new("scene.toggle-group.density")
.label("Density")
.selection(ToggleSelection::AtMostOne)
.items([
ToggleItem::new("compact", "Compact"),
ToggleItem::new("cosy", "Cosy"),
ToggleItem::new("roomy", "Roomy"),
])
.pressed_ids(&["cosy"])
.on_change(|_, _, _, _| {}),
)
.into_any_element()
}