pub struct SegmentedControl<T: SelectionItem = SegmentOption> { /* private fields */ }Expand description
Segmented control widget for single-selection from horizontal options
Generic over T: SelectionItem. For simple string-based selections,
use the default SegmentedControl<SegmentOption> via the options() builder.
Implementations§
Source§impl SegmentedControl<SegmentOption>
impl SegmentedControl<SegmentOption>
Sourcepub fn new(cx: &mut Context<'_, Self>) -> Self
pub fn new(cx: &mut Context<'_, Self>) -> Self
Create a new segmented control for SegmentOption selections
Use options() to set the available options.
Sourcepub fn options(self, options: Vec<(&str, &str)>) -> Self
pub fn options(self, options: Vec<(&str, &str)>) -> Self
Set options from a slice of (value, label) tuples (builder pattern)
Sourcepub fn with_options(self, options: Vec<SegmentOption>) -> Self
pub fn with_options(self, options: Vec<SegmentOption>) -> Self
Set options from SegmentOption structs (builder pattern)
Sourcepub fn with_selected_value(self, value: &str) -> Self
pub fn with_selected_value(self, value: &str) -> Self
Set selected value by string (builder pattern)
For use with options() API. Matches by value field.
Sourcepub fn set_selected_value(&mut self, value: &str, cx: &mut Context<'_, Self>)
pub fn set_selected_value(&mut self, value: &str, cx: &mut Context<'_, Self>)
Set selected by string value programmatically
For use with options() API. Emits Change event if value changes.
Sourcepub fn selected_value(&self) -> &str
pub fn selected_value(&self) -> &str
Get the selected value as a string
Convenience method for SegmentOption-based controls.
Source§impl<T: SelectionItem> SegmentedControl<T>
impl<T: SelectionItem> SegmentedControl<T>
Sourcepub fn new_with_items(
items: Vec<T>,
selected: T,
cx: &mut Context<'_, Self>,
) -> Self
pub fn new_with_items( items: Vec<T>, selected: T, cx: &mut Context<'_, Self>, ) -> Self
Create a new segmented control with items and initial selection
Sourcepub fn with_items(self, items: Vec<T>) -> Self
pub fn with_items(self, items: Vec<T>) -> Self
Set items (builder pattern)
Sourcepub fn with_selected(self, item: T) -> Self
pub fn with_selected(self, item: T) -> Self
Set selected item (builder pattern)
Sourcepub fn with_selected_index(self, index: usize) -> Self
pub fn with_selected_index(self, index: usize) -> Self
Set selected by index (builder pattern)
Sourcepub fn with_enabled(self, enabled: bool) -> Self
pub fn with_enabled(self, enabled: bool) -> Self
Set enabled state (builder pattern)
Set gap between segment buttons (builder pattern)
Default is 8px.
Sourcepub fn selected_index(&self) -> usize
pub fn selected_index(&self) -> usize
Get the currently selected index
Sourcepub fn set_selected(&mut self, item: T, cx: &mut Context<'_, Self>)
pub fn set_selected(&mut self, item: T, cx: &mut Context<'_, Self>)
Set selected item programmatically
Emits Change event if selection changes.
Sourcepub fn set_selected_index(&mut self, index: usize, cx: &mut Context<'_, Self>)
pub fn set_selected_index(&mut self, index: usize, cx: &mut Context<'_, Self>)
Set selected by index programmatically
Emits Change event if selection changes.
Sourcepub fn focus_handle(&self) -> &FocusHandle
pub fn focus_handle(&self) -> &FocusHandle
Get the focus handle
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if enabled
Sourcepub fn set_enabled(&mut self, enabled: bool, cx: &mut Context<'_, Self>)
pub fn set_enabled(&mut self, enabled: bool, cx: &mut Context<'_, Self>)
Set enabled state programmatically
Trait Implementations§
Source§impl<T: SelectionItem> Focusable for SegmentedControl<T>
impl<T: SelectionItem> Focusable for SegmentedControl<T>
Source§fn focus_handle(&self, _cx: &App) -> FocusHandle
fn focus_handle(&self, _cx: &App) -> FocusHandle
Source§impl<T: SelectionItem> Render for SegmentedControl<T>
impl<T: SelectionItem> Render for SegmentedControl<T>
impl<T: SelectionItem> EventEmitter<SegmentedControlEvent<T>> for SegmentedControl<T>
Auto Trait Implementations§
impl<T> Freeze for SegmentedControl<T>where
T: Freeze,
impl<T = SegmentOption> !RefUnwindSafe for SegmentedControl<T>
impl<T> Send for SegmentedControl<T>where
T: Send,
impl<T> Sync for SegmentedControl<T>where
T: Sync,
impl<T> Unpin for SegmentedControl<T>where
T: Unpin,
impl<T> UnsafeUnpin for SegmentedControl<T>where
T: UnsafeUnpin,
impl<T = SegmentOption> !UnwindSafe for SegmentedControl<T>
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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