pub struct ToggleGroupState { /* private fields */ }Expand description
Retained selection and focus for one group in one window.
Tab enters the last focused enabled option, initially the first enabled item.
Arrow keys move focus without changing pressed values. By default any number
of items can be pressed. Self::single_selection limits this to one; pressing
another option releases the previous one, and pressing it again clears the group.
Implementations§
Source§impl ToggleGroupState
impl ToggleGroupState
pub fn new( items: impl IntoIterator<Item = ToggleItem>, cx: &mut Context<'_, Self>, ) -> Self
Sourcepub fn single_selection(self) -> Self
pub fn single_selection(self) -> Self
Limits the group to zero or one pressed item, before it is first rendered.
Focus movement still leaves selection unchanged. Activating a pressed option releases it.
§Panics
Panics if previously supplied defaults contain more than one distinct value.
Sourcepub fn default_values<V: AsRef<str>>(
self,
values: impl IntoIterator<Item = V>,
) -> Self
pub fn default_values<V: AsRef<str>>( self, values: impl IntoIterator<Item = V>, ) -> Self
Sets initially pressed values without emitting an event.
§Panics
Every value must identify an enabled item in the fixed collection. In single-selection mode, at most one distinct value may be supplied.
pub fn items(&self) -> &[ToggleItem]
pub fn is_pressed(&self, index: usize) -> bool
pub fn selected_values(&self) -> Vec<SharedString>
Sourcepub fn set_selected_values<V: AsRef<str>>(
&mut self,
values: impl IntoIterator<Item = V>,
window: &mut Window,
cx: &mut Context<'_, Self>,
) -> bool
pub fn set_selected_values<V: AsRef<str>>( &mut self, values: impl IntoIterator<Item = V>, window: &mut Window, cx: &mut Context<'_, Self>, ) -> bool
Sets pressed values without emitting Change or moving focus or its cursor.
Unknown or disabled options, and more than one distinct value in single mode, are rejected without changing the selection. Empty values clear the group. Returns whether all values were accepted, including unchanged values. Application updates remain available while the group itself is disabled.
pub fn option_focus_handle(&self, index: usize) -> &FocusHandle
pub fn is_disabled(&self) -> bool
Sourcepub fn set_disabled(
&mut self,
disabled: bool,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_disabled( &mut self, disabled: bool, window: &mut Window, cx: &mut Context<'_, Self>, )
Disables user changes and normal Tab entry while retaining pressed values. An already-focused option keeps Button’s focus binding so Tab can leave.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ToggleGroupState
impl !Send for ToggleGroupState
impl !Sync for ToggleGroupState
impl !UnwindSafe for ToggleGroupState
impl Forget for ToggleGroupState
impl Freeze for ToggleGroupState
impl Move for ToggleGroupState
impl Unpin for ToggleGroupState
impl UnsafeUnpin for ToggleGroupState
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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