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>
impl<'a> MacSegmentedControl<'a>
Sourcepub const INLINE_SEGMENT_CAPACITY: usize = INLINE_CAP
pub const INLINE_SEGMENT_CAPACITY: usize = INLINE_CAP
Maximum number of segments stored inline on the stack (8) before spilling to heap storage.
Sourcepub fn new(options: &'a [&'a str], selected_idx: usize) -> Self
pub fn new(options: &'a [&'a str], selected_idx: usize) -> Self
Creates a segmented control from borrowed text option labels and currently selected index.
Sourcepub fn with_custom_segments(
segments: impl IntoIterator<Item = SegmentItem<'a>>,
selected_idx: usize,
) -> Self
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.
Sourcepub fn momentary(segments: impl IntoIterator<Item = SegmentItem<'a>>) -> Self
pub fn momentary(segments: impl IntoIterator<Item = SegmentItem<'a>>) -> Self
Creates a momentary segmented action strip (NSSegmentedSwitchTrackingMomentary) with no persistent active pill.
Sourcepub fn with_icons(symbols: &'a [MacSymbol], selected_idx: usize) -> Self
pub fn with_icons(symbols: &'a [MacSymbol], selected_idx: usize) -> Self
Creates a segmented control from a slice of MacSymbol icons.
Sourcepub const fn is_inline_allocated(&self) -> bool
pub const fn is_inline_allocated(&self) -> bool
Returns true when the segment descriptors reside inline on the stack without heap allocation.
Sourcepub fn id_salt(self, salt: impl Hash + Debug) -> Self
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.
Sourcepub fn accessibility_label(self, label: impl Into<Cow<'a, str>>) -> Self
pub fn accessibility_label(self, label: impl Into<Cow<'a, str>>) -> Self
Sets the NSAccessibility / AccessKit group label announced by assistive technologies.
Sourcepub const fn enabled(self, enabled: bool) -> Self
pub const fn enabled(self, enabled: bool) -> Self
Enables or disables the entire segmented control.
Sourcepub const fn height(self, height: f32) -> Self
pub const fn height(self, height: f32) -> Self
Overrides control height in points (defaults to size-tier segmented height token).
Sourcepub const fn control_size(self, size: MacControlSize) -> Self
pub const fn control_size(self, size: MacControlSize) -> Self
Sets the AppKit control size (Regular 22pt, Small 18pt, or Mini 15pt).
Sourcepub const fn small_square(self) -> Self
pub const fn small_square(self) -> Self
Configures AppKit NSSegmentedStyleSmallSquare (2.0pt corner radius and full-height dividers).
Sourcepub const fn fixed_rect(self, rect: Rect) -> Self
pub const fn fixed_rect(self, rect: Rect) -> Self
Pins the segmented control to an exact NIB rectangle.
Sourcepub fn show_multi(self, ui: &mut Ui, active: &mut [bool]) -> Option<usize>
pub fn show_multi(self, ui: &mut Ui, active: &mut [bool]) -> Option<usize>
Renders a multi-select segmented strip (NSSegmentedSwitchTrackingSelectAny).
Sourcepub fn show(self, ui: &mut Ui, on_select: impl FnMut(usize)) -> Response
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.
Sourcepub fn show_with_events(
self,
ui: &mut Ui,
on_event: impl FnMut(SegmentEvent),
) -> Response
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.
Sourcepub fn show_momentary(
self,
ui: &mut Ui,
on_action: impl FnMut(usize),
) -> Response
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.
Sourcepub fn show_momentary_with_events(
self,
ui: &mut Ui,
on_event: impl FnMut(SegmentEvent),
) -> Response
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§
impl<'a> !RefUnwindSafe for MacSegmentedControl<'a>
impl<'a> !Send for MacSegmentedControl<'a>
impl<'a> !Sync for MacSegmentedControl<'a>
impl<'a> !UnwindSafe for MacSegmentedControl<'a>
impl<'a> Forget for MacSegmentedControl<'a>
impl<'a> Freeze for MacSegmentedControl<'a>
impl<'a> Move for MacSegmentedControl<'a>
impl<'a> Unpin for MacSegmentedControl<'a>
impl<'a> UnsafeUnpin for MacSegmentedControl<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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> ⓘ
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