Skip to main content

Segmented

Struct Segmented 

Source
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-chip component (selected for the option chosen), its padding egui’s button padding, its icon size.icon.inline and the gap before its label space.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>

Source

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.

Source

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.

Source

pub fn overflow(self, overflow: SegmentOverflow) -> Self

What it does with the options that do not fit.

Trait Implementations§

Source§

impl<V> Debug for Segmented<'_, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V: PartialEq + Clone> Widget for Segmented<'_, V>

Source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a [Response]. Read more
§

fn boxed<'a>(self) -> Box<dyn FnOnce(&mut Ui) -> Response + 'a>
where Self: Sized + 'a,

Box this widget for dynamic dispatch.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,