pub struct SegmentedControl<'a> { /* private fields */ }Expand description
A row of mutually-exclusive segments sharing a single rounded track.
Bind to a &mut usize index. Click selects; the selected index is
updated in place and the response is marked changed. Use
SegmentedControl::new for plain text segments and
SegmentedControl::from_segments when you need icons, dots, counts,
or per-segment disabled state.
let mut selected = 1usize;
ui.add(SegmentedControl::new(&mut selected, ["Day", "Week", "Month"]));
ui.add(
SegmentedControl::new(&mut selected, ["Compact", "Comfortable", "Spacious"])
.size(SegmentedSize::Small),
);Rich segments with status dots and counts:
let mut selected = 0usize;
ui.add(
SegmentedControl::from_segments(
&mut selected,
[
Segment::text("Open").dot(SegmentDot::Amber).count("12"),
Segment::text("Triaged").dot(SegmentDot::Neutral).count("84"),
Segment::text("Resolved").dot(SegmentDot::Green).count("1,204"),
Segment::text("Rejected").dot(SegmentDot::Red).count("31"),
],
)
.fill(),
);Implementations§
Source§impl<'a> SegmentedControl<'a>
impl<'a> SegmentedControl<'a>
Sourcepub fn new<I, S>(selected: &'a mut usize, items: I) -> Self
pub fn new<I, S>(selected: &'a mut usize, items: I) -> Self
Build a text-only single-select segmented control bound to
selected (a &mut usize index). Click-selects; the index is
always within 0..items.len() after rendering.
Sourcepub fn from_segments(
selected: &'a mut usize,
segments: impl IntoIterator<Item = Segment>,
) -> Self
pub fn from_segments( selected: &'a mut usize, segments: impl IntoIterator<Item = Segment>, ) -> Self
Build a single-select segmented control from explicit Segments.
Use this when you need icons, dots, counts, or disabled states.
Sourcepub fn toggles<I, S>(states: &'a mut [bool], items: I) -> Self
pub fn toggles<I, S>(states: &'a mut [bool], items: I) -> Self
Build a multi-select segmented control: each click toggles the
segment’s bool independently, so any combination of segments
(including all on or all off) is a valid state. Visuals match the
single-select track. states.len() and items should have the
same length; extra labels render as always-off, extra states are
ignored.
let mut targets = [true, false]; // [server_on, client_on]
ui.add(SegmentedControl::toggles(&mut targets, ["Server", "Client"]));Sourcepub fn size(self, size: SegmentedSize) -> Self
pub fn size(self, size: SegmentedSize) -> Self
Pick a size preset. Default: SegmentedSize::Medium.