pub struct Segmented<'a, V> { /* private fields */ }Expand description
A segmented control: a row of exclusive options, one selected (a view’s
modes, a panel’s tabs), as Mantine’s SegmentedControl, Ant’s
Segmented or libadwaita’s AdwToggleGroup have it.
- For assistive technology it is a radio group named by
Segmented::name, each option a radio button, checked when selected. - The keyboard: it is one Tab stop; Left and Right select the option before or after (round from one end to the other), Home and End the first and the last; disabled options are passed over.
- Too narrow a row goes by
SegmentOverflow: by default the last options fold into a “More choices” menu, the selected one staying in the row; or the row wraps, or scrolls. - Looks come from the kit: each option is the
toggle-chipcomponent (selectedfor the option chosen), its padding egui’s button padding, its iconsize.icon.inlineand the gap before its labelspace.xs.
It replaces a row of selectable_value buttons:
use egui_pop_core::widgets::{SegmentOption, Segmented};
#[derive(Clone, Copy, PartialEq)]
enum Scope { Folders, Albums, Keywords }
fn scopes(ui: &mut egui::Ui, scope: &mut Scope) {
let changed = ui
.add(
Segmented::new("library.scope", scope, [
SegmentOption::new(Scope::Folders, "Folders").icon("phosphor:folder"),
SegmentOption::new(Scope::Albums, "Albums"),
SegmentOption::new(Scope::Keywords, "Keywords"),
])
.name("Browse by"),
)
.changed();
let _ = changed;
}Need (input): one mode among a few, as a segmented control or a tab strip.
Implementations§
Source§impl<'a, V: PartialEq + Clone> Segmented<'a, V>
impl<'a, V: PartialEq + Clone> Segmented<'a, V>
Sourcepub fn new(
id_salt: impl AsIdSalt,
value: &'a mut V,
options: impl IntoIterator<Item = SegmentOption<V>>,
) -> Self
pub fn new( id_salt: impl AsIdSalt, value: &'a mut V, options: impl IntoIterator<Item = SegmentOption<V>>, ) -> Self
A control under id_salt (unique in its parent), selecting one of
options into value.
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Its name for assistive technology (“View”, “Browse by”): the radio group’s, and its “More choices” button’s.
Sourcepub fn overflow(self, overflow: SegmentOverflow) -> Self
pub fn overflow(self, overflow: SegmentOverflow) -> Self
What it does with the options that do not fit.
Trait Implementations§
Auto Trait Implementations§
impl<'a, V> Freeze for Segmented<'a, V>
impl<'a, V> RefUnwindSafe for Segmented<'a, V>where
V: RefUnwindSafe,
impl<'a, V> Send for Segmented<'a, V>where
V: Send,
impl<'a, V> Sync for Segmented<'a, V>where
V: Sync,
impl<'a, V> Unpin for Segmented<'a, V>where
V: Unpin,
impl<'a, V> UnsafeUnpin for Segmented<'a, V>
impl<'a, V> !UnwindSafe for Segmented<'a, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more