pub struct SegmentedControl<T, A = ()> { /* private fields */ }Expand description
An equal-width, typed single-selection control.
Selection can be controlled or two-way bound. Without either a writable signal or callback, interaction is read-only. Arrow keys wrap and skip disabled options; Home/End choose first/last. With no matching selection, Right chooses first, Left chooses last, and Enter/Space chooses first.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let control: SegmentedControl<&str, ()> = SegmentedControl::new()
.option("grid", "Grid")
.option("list", "List")
.selected("grid");
let _ = control;Implementations§
Source§impl<T: Clone + PartialEq + 'static, A: 'static> SegmentedControl<T, A>
impl<T: Clone + PartialEq + 'static, A: 'static> SegmentedControl<T, A>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an enabled empty control with no selection or callback.
Empty controls measure zero width, retain style height, and are not focusable.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let control: SegmentedControl<i32, ()> = SegmentedControl::new();
let _ = control;Sourcepub fn option(self, value: T, label: impl Into<String>) -> Self
pub fn option(self, value: T, label: impl Into<String>) -> Self
Appends an enabled text-only option.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let control: SegmentedControl<i32, ()> = SegmentedControl::new().option(1, "One");
let _ = control;Sourcepub fn segmented_option(self, option: SegmentedOption<T>) -> Self
pub fn segmented_option(self, option: SegmentedOption<T>) -> Self
Appends a fully configured option.
§Examples
use ailloli_ui_widgets::controls::{SegmentedControl, SegmentedOption};
let option = SegmentedOption::new(1, "One").disabled(true);
let control: SegmentedControl<i32, ()> = SegmentedControl::new().segmented_option(option);
let _ = control;Sourcepub fn selected(self, selected: impl Into<Binding<T>>) -> Self
pub fn selected(self, selected: impl Into<Binding<T>>) -> Self
Sets controlled static/reactive selection and clears bound mode.
A value absent from options paints no selection. Change callbacks still emit interaction results, but cannot mutate this source.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let control: SegmentedControl<i32, ()> = SegmentedControl::new().option(1, "One").selected(1);
let _ = control;Sourcepub fn bind(self, selected: impl Into<Signal<T>>) -> Self
pub fn bind(self, selected: impl Into<Signal<T>>) -> Self
Installs a writable signal for two-way selection.
§Examples
use std::{cell::RefCell, rc::Rc};
use ailloli_ui_runtime::component::Signal;
use ailloli_ui_widgets::controls::SegmentedControl;
let selected = Signal::new(Rc::new(RefCell::new(1)), Rc::new(|| {}));
let control: SegmentedControl<i32, ()> = SegmentedControl::new().option(1, "One").bind(selected);
let _ = control;Sourcepub fn disabled(self, disabled: impl Into<Binding<bool>>) -> Self
pub fn disabled(self, disabled: impl Into<Binding<bool>>) -> Self
Sets static or reactive global disabled state.
Disabled controls are not focusable and ignore pointer/keyboard input.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let control: SegmentedControl<i32, ()> = SegmentedControl::new().disabled(true);
let _ = control;Sourcepub fn disabled_signal(self, disabled: Memo<bool>) -> Self
pub fn disabled_signal(self, disabled: Memo<bool>) -> Self
Sets global disabled state from a derived memo.
§Examples
use ailloli_ui_runtime::component::Memo;
use ailloli_ui_widgets::controls::SegmentedControl;
let control: SegmentedControl<i32, ()> = SegmentedControl::new().disabled_signal(Memo::new(|| false));
let _ = control;Sourcepub fn segmented_style(self, style: SegmentedStyle) -> Self
pub fn segmented_style(self, style: SegmentedStyle) -> Self
Replaces complete colors and intrinsic geometry.
§Examples
use ailloli_ui_widgets::controls::{SegmentedControl, SegmentedStyle};
let control: SegmentedControl<i32, ()> = SegmentedControl::new().segmented_style(SegmentedStyle::default());
let _ = control;Sourcepub fn segmented_size(self, size: SegmentedSize) -> Self
pub fn segmented_size(self, size: SegmentedSize) -> Self
Replaces style with a default-theme built-in size.
§Examples
use ailloli_ui_widgets::controls::{SegmentedControl, SegmentedSize};
let control: SegmentedControl<i32, ()> = SegmentedControl::new().segmented_size(SegmentedSize::Compact);
let _ = control;Sourcepub fn on_change(self, f: impl Fn(T) -> A + 'static) -> Self
pub fn on_change(self, f: impl Fn(T) -> A + 'static) -> Self
Maps each distinct enabled option selection to an application action.
The callback does not make a controlled source writable; use Self::bind
for two-way state.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
#[derive(Clone)]
enum Action { Selected(i32) }
let control = SegmentedControl::new().option(1, "One").on_change(Action::Selected);
let _ = control;Sourcepub fn on_change_ctx(self, f: impl Fn(&mut EventCtx<A>, T) + 'static) -> Self
pub fn on_change_ctx(self, f: impl Fn(&mut EventCtx<A>, T) + 'static) -> Self
Installs a context-aware selection handler.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let control = SegmentedControl::<i32, ()>::new()
.option(1, "One")
.on_change_ctx(|_ctx, value| assert_eq!(value, 1));
let _ = control;Sourcepub fn width(self, value: impl Into<Length>) -> Self
pub fn width(self, value: impl Into<Length>) -> Self
Sets preferred width from logical pixels or an explicit Length.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().width(240.0);Sourcepub fn height(self, value: impl Into<Length>) -> Self
pub fn height(self, value: impl Into<Length>) -> Self
Sets preferred height from logical pixels or an explicit Length.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().height(40.0);Sourcepub fn min_width(self, value: impl Into<Length>) -> Self
pub fn min_width(self, value: impl Into<Length>) -> Self
Sets the minimum resolved width.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().min_width(120.0);Sourcepub fn max_width(self, value: impl Into<Length>) -> Self
pub fn max_width(self, value: impl Into<Length>) -> Self
Sets the maximum resolved width.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().max_width(400.0);Sourcepub fn min_height(self, value: impl Into<Length>) -> Self
pub fn min_height(self, value: impl Into<Length>) -> Self
Sets the minimum resolved height.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().min_height(28.0);Sourcepub fn max_height(self, value: impl Into<Length>) -> Self
pub fn max_height(self, value: impl Into<Length>) -> Self
Sets the maximum resolved height.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().max_height(48.0);Sourcepub fn fill(self) -> Self
pub fn fill(self) -> Self
Marks both axes as parent-fill.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().fill();Sourcepub fn fill_width(self) -> Self
pub fn fill_width(self) -> Self
Marks width as parent-fill while preserving height.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().fill_width();Sourcepub fn fill_height(self) -> Self
pub fn fill_height(self) -> Self
Marks height as parent-fill while preserving width.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().fill_height();Sourcepub fn margin(self, value: f32) -> Self
pub fn margin(self, value: f32) -> Self
Sets the same logical-pixel margin on every side.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().margin(8.0);Sourcepub fn padding(self, value: f32) -> Self
pub fn padding(self, value: f32) -> Self
Sets the same logical-pixel layout padding on every side.
This is layout metadata and is separate from per-segment content padding.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().padding(4.0);Sourcepub fn flex_grow(self) -> Self
pub fn flex_grow(self) -> Self
Sets the dimensionless parent flex-grow weight to one.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().flex_grow();Sourcepub fn flex_grow_by(self, value: f32) -> Self
pub fn flex_grow_by(self, value: f32) -> Self
Sets the dimensionless parent flex-grow weight.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().flex_grow_by(2.0);Sourcepub fn flex_shrink(self, value: f32) -> Self
pub fn flex_shrink(self, value: f32) -> Self
Sets the dimensionless parent flex-shrink weight.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().flex_shrink(0.5);Sourcepub fn flex_basis(self, value: impl Into<Length>) -> Self
pub fn flex_basis(self, value: impl Into<Length>) -> Self
Sets the preferred parent main-axis flex basis.
§Examples
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().flex_basis(160.0);Sourcepub fn align_self(self, value: AlignItems) -> Self
pub fn align_self(self, value: AlignItems) -> Self
Overrides this item’s parent cross-axis alignment.
§Examples
use ailloli_ui_core::style::AlignItems;
use ailloli_ui_widgets::controls::SegmentedControl;
let _ = SegmentedControl::<i32, ()>::new().align_self(AlignItems::End);