Toggle

Struct Toggle 

Source
pub struct Toggle(/* private fields */);
Expand description

A control that toggles between on and off states.

Toggle displays a switch with an optional label. It’s commonly used for settings that can be turned on or off.

§Layout Behavior

With a label: Toggle expands horizontally to fill available space, placing the label on the left and switch on the right. Without a label: Toggle is content-sized (just the switch).

§Examples

// Simple toggle with label
toggle("Wi-Fi", &is_enabled)

// Toggle without label
Toggle::new(&dark_mode)

// In a settings list
vstack((
    toggle("Notifications", &notifications),
    toggle("Sound", &sound),
))

Implementations§

Source§

impl Toggle

Source

pub fn new(toggle: &Binding<bool>) -> Self

Creates a new Toggle with the specified binding for the toggle state.

Source

pub fn label(self, view: impl View) -> Self

Sets the label for the toggle.

Trait Implementations§

Source§

impl ConfigurableView for Toggle

Source§

type Config = ToggleConfig

The configuration type associated with this view. Read more
Source§

fn config(self) -> Self::Config

Returns the configuration for this view. Read more
Source§

impl From<ToggleConfig> for Toggle

Source§

fn from(value: ToggleConfig) -> Self

Converts to this type from the input type.
Source§

impl View for Toggle

Source§

fn body(self, env: &Environment) -> impl View

Build this view and return the content. Read more

Auto Trait Implementations§

§

impl Freeze for Toggle

§

impl !RefUnwindSafe for Toggle

§

impl !Send for Toggle

§

impl !Sync for Toggle

§

impl Unpin for Toggle

§

impl !UnwindSafe for Toggle

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> IdentifiableExt for T

Source§

fn use_id<F, Id>(self, f: F) -> UseId<Self, F>
where F: Fn(&Self) -> Id, Id: Ord + Hash,

Wraps the value in a UseId with the provided identification function.
Source§

fn self_id(self) -> SelfId<Self>

Wraps the value in a SelfId, making the value serve as its own identifier.
§

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

§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<V> IntoView for V
where V: View,

Source§

type Output = V

The resulting View type after conversion.
Source§

fn into_view(self, _env: &Environment) -> <V as IntoView>::Output

Converts the implementing type into a View. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.