Components / Selection & input
Toggle group
Markdown crates/ui/src/widgets/controls.rs docs.rs
use ui::widgets::Controls;
theme.toggle_group().children(
["Day", "Week", "Month"].into_iter().enumerate().map(|(index, label)| {
theme.toggle_group_item(label, self.segment == index)
}),
)Reach for this over a select when there are few enough choices that a menu would be overkill.
API
pub trait Controls: ThemeExt {
/// The track. Sets `self_start`, or flexbox's default `stretch` blows it
/// out to a column's full width.
fn toggle_group(&self) -> Div;
/// Exactly one reads as pressed; the rest stay bare.
fn toggle_group_item(&self, label: impl Into<SharedString>, selected: bool) -> Div;
// ...
}Segment corners derive from the track's radius and its inset — both numbers are read at both ends, so a segment cannot stop being concentric with its track.