Struct Switch

Source
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>

Source

pub fn width(self, value: impl Into<Length>) -> Self

Sets preferred width from a logical-pixel or length value.

§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().width(120.0);
let _ = widget;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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>

Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;

Trait Implementations§

Source§

impl<A: 'static> Default for Switch<A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A: 'static> IntoView<A> for Switch<A>

Source§

fn into_view(self) -> View<A>

Consumes a builder/value and returns its declarative view tree. Read more
Source§

impl<A: 'static> LayoutExt for Switch<A>

Source§

fn layout_mut(&mut self) -> &mut LayoutStyle

Returns the widget’s mutable declarative size/inset state. Read more

Auto Trait Implementations§

§

impl<A> Freeze for Switch<A>

§

impl<A = ()> !RefUnwindSafe for Switch<A>

§

impl<A = ()> !Send for Switch<A>

§

impl<A = ()> !Sync for Switch<A>

§

impl<A> Unpin for Switch<A>

§

impl<A = ()> !UnwindSafe for Switch<A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, A> FlexItemExt<A> for T
where T: IntoView<A>,

Source§

fn flex_grow(self) -> View<A>

Sets flex-grow weight to one. Read more
Source§

fn flex_grow_by(self, value: f32) -> View<A>

Sets the dimensionless flex-grow weight. Read more
Source§

fn flex_shrink(self, value: f32) -> View<A>

Sets the dimensionless flex-shrink weight. Read more
Source§

fn flex_basis(self, value: impl Into<Length>) -> View<A>

Sets the preferred main-axis flex basis. Read more
Source§

fn align_self(self, value: AlignItems) -> View<A>

Overrides the parent cross-axis alignment for this view. Read more
Source§

fn fill_width(self) -> View<A>

Marks width as parent-fill in the view size hint. Read more
Source§

fn fill_height(self) -> View<A>

Marks height as parent-fill in the view size hint. Read more
Source§

fn fill(self) -> View<A>

Marks both axes as parent-fill in the view size hint. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, A> IntoViewKeyExt<A> for T
where T: IntoView<A>,

§

fn key(self, key: impl Into<String>) -> View<A>

Converts self, assigns the owned key, and returns the view. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,