Skip to main content

MacSegmentedControl

Struct MacSegmentedControl 

Source
pub struct MacSegmentedControl<'a> { /* private fields */ }
Expand description

Authentic macOS segmented pill selector (NSSegmentedControl equivalent).

Supports CASpring sliding pill physics, per-segment widths, template-tinted vector icons, per-segment enablement, isHighlighted pressed feedback, Sonoma active-pill divider suppression, AccessKit (egui::Role::RadioGroup / egui::Role::Toolbar) semantics, stack-inline storage, and AppKit menu triggers (PressAndHold, PullDown, SecondaryClick, Keyboard).

§Example

use egui_macview::{MacSegmentedControl, MacTheme};
let theme = MacTheme::default();
let mut selected = 1;
MacSegmentedControl::new(&["Day", "Week", "Month", "Year"], selected)
    .accessibility_label("Calendar Scale")
    .theme(&theme)
    .show(ui, |i| selected = i);

Implementations§

Source§

impl<'a> MacSegmentedControl<'a>

Source

pub const INLINE_SEGMENT_CAPACITY: usize = INLINE_CAP

Maximum number of segments stored inline on the stack (8) before spilling to heap storage.

Source

pub fn new(options: &'a [&'a str], selected_idx: usize) -> Self

Creates a segmented control from borrowed text option labels and currently selected index.

Source

pub fn with_custom_segments( segments: impl IntoIterator<Item = SegmentItem<'a>>, selected_idx: usize, ) -> Self

Creates a segmented control from any array or iterator of SegmentItem descriptors.

Source

pub fn momentary(segments: impl IntoIterator<Item = SegmentItem<'a>>) -> Self

Creates a momentary segmented action strip (NSSegmentedSwitchTrackingMomentary) with no persistent active pill.

Source

pub fn with_icons(symbols: &'a [MacSymbol], selected_idx: usize) -> Self

Creates a segmented control from a slice of MacSymbol icons.

Source

pub const fn is_inline_allocated(&self) -> bool

Returns true when the segment descriptors reside inline on the stack without heap allocation.

Source

pub fn id_salt(self, salt: impl Hash + Debug) -> Self

Explicitly binds an ID salt so spring physics and gesture state stay invariant across conditional peer layouts.

Source

pub fn accessibility_label(self, label: impl Into<Cow<'a, str>>) -> Self

Sets the NSAccessibility / AccessKit group label announced by assistive technologies.

Source

pub const fn enabled(self, enabled: bool) -> Self

Enables or disables the entire segmented control.

Source

pub const fn theme(self, theme: &'a MacTheme) -> Self

Injects an explicit MacTheme reference.

Source

pub const fn height(self, height: f32) -> Self

Overrides control height in points (defaults to size-tier segmented height token).

Source

pub const fn control_size(self, size: MacControlSize) -> Self

Sets the AppKit control size (Regular 22pt, Small 18pt, or Mini 15pt).

Source

pub const fn small_square(self) -> Self

Configures AppKit NSSegmentedStyleSmallSquare (2.0pt corner radius and full-height dividers).

Source

pub const fn fixed_rect(self, rect: Rect) -> Self

Pins the segmented control to an exact NIB rectangle.

Source

pub fn show_multi(self, ui: &mut Ui, active: &mut [bool]) -> Option<usize>

Renders a multi-select segmented strip (NSSegmentedSwitchTrackingSelectAny).

Source

pub fn show(self, ui: &mut Ui, on_select: impl FnMut(usize)) -> Response

Renders the segmented control and invokes on_select when a primary selection occurs.

Source

pub fn show_with_events( self, ui: &mut Ui, on_event: impl FnMut(SegmentEvent), ) -> Response

Renders the segmented control and dispatches SegmentEvent values for both selection and menu triggers.

Source

pub fn show_momentary( self, ui: &mut Ui, on_action: impl FnMut(usize), ) -> Response

Renders a momentary segmented strip (NSSegmentedSwitchTrackingMomentary) and invokes on_action on click/activation.

Source

pub fn show_momentary_with_events( self, ui: &mut Ui, on_event: impl FnMut(SegmentEvent), ) -> Response

Renders a momentary segmented strip (NSSegmentedSwitchTrackingMomentary) and dispatches both click and menu SegmentEvents.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

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

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.