pub struct Switch<A = ()> { /* private fields */ }Expand description
A focusable binary toggle supporting controlled and bound state modes.
Pointer activation occurs on left-button release inside the bounds;
Enter and Space activate on a pressed key event. Switch::checked is
controlled/read-only state: activation only reports !checked through the
callback. Switch::bind first writes the signal, then calls the callback.
With neither binding nor callback, activation is a no-op.
§Examples
use ailloli_ui_widgets::controls::Switch;
let switch: Switch<()> = Switch::new().checked(true);
let _ = switch;Implementations§
Source§impl<A: 'static> Switch<A>
impl<A: 'static> Switch<A>
Sourcepub fn height(self, value: impl Into<Length>) -> Self
pub fn height(self, value: impl Into<Length>) -> Self
Sets preferred height from a logical-pixel or length value.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().height(40.0);
let _ = widget;Sourcepub fn min_width(self, value: impl Into<Length>) -> Self
pub fn min_width(self, value: impl Into<Length>) -> Self
Sets the minimum width bound.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().min_width(40.0);
let _ = widget;Sourcepub fn max_width(self, value: impl Into<Length>) -> Self
pub fn max_width(self, value: impl Into<Length>) -> Self
Sets the maximum width bound.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().max_width(320.0);
let _ = widget;Sourcepub fn min_height(self, value: impl Into<Length>) -> Self
pub fn min_height(self, value: impl Into<Length>) -> Self
Sets the minimum height bound.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().min_height(24.0);
let _ = widget;Sourcepub fn max_height(self, value: impl Into<Length>) -> Self
pub fn max_height(self, value: impl Into<Length>) -> Self
Sets the maximum height bound.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().max_height(240.0);
let _ = widget;Sourcepub fn fill(self) -> Self
pub fn fill(self) -> Self
Sets both preferred axes to parent fill.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill();
let _ = widget;Sourcepub fn fill_width(self) -> Self
pub fn fill_width(self) -> Self
Sets preferred width to parent fill.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill_width();
let _ = widget;Sourcepub fn fill_height(self) -> Self
pub fn fill_height(self) -> Self
Sets preferred height to parent fill.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill_height();
let _ = widget;Sourcepub fn margin(self, value: f32) -> Self
pub fn margin(self, value: f32) -> Self
Sets uniform outer margin in logical pixels.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().margin(8.0);
let _ = widget;Sourcepub fn padding(self, value: f32) -> Self
pub fn padding(self, value: f32) -> Self
Sets uniform inner padding in logical pixels.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().padding(8.0);
let _ = widget;Sourcepub fn flex_grow(self) -> Self
pub fn flex_grow(self) -> Self
Sets flex-grow weight to one.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_grow();
let _ = widget;Sourcepub fn flex_grow_by(self, value: f32) -> Self
pub fn flex_grow_by(self, value: f32) -> Self
Sets a dimensionless flex-grow weight.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_grow_by(2.0);
let _ = widget;Sourcepub fn flex_shrink(self, value: f32) -> Self
pub fn flex_shrink(self, value: f32) -> Self
Sets a dimensionless flex-shrink weight.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_shrink(1.0);
let _ = widget;Sourcepub fn flex_basis(self, value: impl Into<Length>) -> Self
pub fn flex_basis(self, value: impl Into<Length>) -> Self
Sets the preferred main-axis flex basis.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_basis(80.0);
let _ = widget;Sourcepub fn align_self(self, value: AlignItems) -> Self
pub fn align_self(self, value: AlignItems) -> Self
Overrides cross-axis alignment for this flex item.
§Examples
use ailloli_ui_core::style::AlignItems;
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().align_self(AlignItems::Center);
let _ = widget;Source§impl<A: 'static> Switch<A>
impl<A: 'static> Switch<A>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an off, enabled, horizontal switch with no callback.
§Examples
use ailloli_ui_widgets::controls::Switch;
let switch: Switch<()> = Switch::new();
let _ = switch;Sourcepub fn checked(self, checked: impl Into<Binding<bool>>) -> Self
pub fn checked(self, checked: impl Into<Binding<bool>>) -> Self
Sets controlled static or reactive checked state.
This clears any writable signal previously installed by Self::bind.
Activation does not mutate this binding; use Self::on_change to send
the proposed value back to application state.
§Examples
use ailloli_ui_widgets::controls::Switch;
let switch: Switch<()> = Switch::new().checked(true);
let _ = switch;Sourcepub fn bind(self, checked: impl Into<Signal<bool>>) -> Self
pub fn bind(self, checked: impl Into<Signal<bool>>) -> Self
Installs a writable signal for two-way checked state.
Activation writes the negated current value before invoking an optional
change callback. A later Self::checked call returns to controlled mode.
§Examples
use std::{cell::RefCell, rc::Rc};
use ailloli_ui_runtime::component::Signal;
use ailloli_ui_widgets::controls::Switch;
let checked = Signal::new(Rc::new(RefCell::new(false)), Rc::new(|| {}));
let switch: Switch<()> = Switch::new().bind(checked);
let _ = switch;Sourcepub fn disabled(self, disabled: impl Into<Binding<bool>>) -> Self
pub fn disabled(self, disabled: impl Into<Binding<bool>>) -> Self
Sets a static or reactive disabled binding.
Disabled switches ignore activation, leave the bound signal unchanged, are removed from focus traversal, and apply disabled paint.
§Examples
use ailloli_ui_widgets::controls::Switch;
let switch: Switch<()> = Switch::new().disabled(true);
let _ = switch;Sourcepub fn disabled_signal(self, disabled: Memo<bool>) -> Self
pub fn disabled_signal(self, disabled: Memo<bool>) -> Self
Convenience alias for Self::disabled with a reactive memo.
§Examples
use ailloli_ui_runtime::component::Memo;
use ailloli_ui_widgets::controls::Switch;
let switch: Switch<()> = Switch::new().disabled_signal(Memo::new(|| false));
let _ = switch;Sourcepub fn switch_style(self, style: SwitchStyle) -> Self
pub fn switch_style(self, style: SwitchStyle) -> Self
Replaces the complete resolved style without clamping its values.
A later Self::switch_size call discards this custom style.
§Examples
use ailloli_ui_core::Theme;
use ailloli_ui_widgets::controls::{Switch, SwitchSize, SwitchStyle};
let style = SwitchStyle::from_theme(Theme::dark(), SwitchSize::Compact);
let switch: Switch<()> = Switch::new().switch_style(style);
let _ = switch;Sourcepub fn switch_size(self, size: SwitchSize) -> Self
pub fn switch_size(self, size: SwitchSize) -> Self
Replaces the complete style with the default-theme built-in size.
§Examples
use ailloli_ui_widgets::controls::{Switch, SwitchSize};
let switch: Switch<()> = Switch::new().switch_size(SwitchSize::Compact);
let _ = switch;Sourcepub fn orientation(self, orientation: SwitchOrientation) -> Self
pub fn orientation(self, orientation: SwitchOrientation) -> Self
Sets the thumb motion axis.
Vertical orientation swaps the style’s intrinsic width and height. Explicit layout builders may override either dimension.
§Examples
use ailloli_ui_widgets::controls::{Switch, SwitchOrientation};
let switch: Switch<()> = Switch::new().orientation(SwitchOrientation::Vertical);
let _ = switch;Sourcepub fn vertical(self) -> Self
pub fn vertical(self) -> Self
Convenience builder for SwitchOrientation::Vertical.
§Examples
use ailloli_ui_widgets::controls::Switch;
let switch: Switch<()> = Switch::new().vertical();
let _ = switch;Sourcepub fn on_change(self, f: impl Fn(bool) -> A + 'static) -> Self
pub fn on_change(self, f: impl Fn(bool) -> A + 'static) -> Self
Maps each proposed next value to an application action and dispatches it.
The mapper runs after a bound signal is updated. A later change-handler builder replaces it.
§Examples
use ailloli_ui_widgets::controls::Switch;
enum Action { Changed(bool) }
let switch = Switch::new().on_change(Action::Changed);
let _ = switch;Sourcepub fn on_change_ctx(self, f: impl Fn(&mut EventCtx<A>, bool) + 'static) -> Self
pub fn on_change_ctx(self, f: impl Fn(&mut EventCtx<A>, bool) + 'static) -> Self
Installs a context-aware callback for each proposed next value.
The callback may dispatch zero or more actions. A later change-handler builder replaces it.
§Examples
use ailloli_ui_widgets::controls::Switch;
let switch = Switch::<()>::new().on_change_ctx(|ctx, _checked| ctx.request_repaint());
let _ = switch;