pub struct Switch;Expand description
An on/off toggle switch component.
This component provides a boolean on/off input that can be toggled via
keyboard when focused. The switch emits SwitchOutput::Toggled,
SwitchOutput::On, or SwitchOutput::Off messages when toggled.
§Keyboard Activation
When focused, Enter or Space toggles the switch state.
§Visual States
- Off:
( ) OFF - On:
(*) ONwith success/green coloring - Focused: Yellow/focused text
- Disabled: Dark gray text, doesn’t respond to toggle
- With label:
Label (*) ON
§Example
use envision::component::{Switch, SwitchMessage, SwitchOutput, SwitchState, Component};
let mut state = SwitchState::new();
// Toggle the switch on
let output = Switch::update(&mut state, SwitchMessage::Toggle);
assert_eq!(output, Some(SwitchOutput::On));
assert!(state.is_on());Trait Implementations§
Source§impl Component for Switch
impl Component for Switch
Source§type State = SwitchState
type State = SwitchState
The component’s internal state type. Read more
Source§type Message = SwitchMessage
type Message = SwitchMessage
Messages this component can receive. Read more
Source§type Output = SwitchOutput
type Output = SwitchOutput
Messages this component can emit to its parent. Read more
Source§fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
Update component state based on a message. Read more
Source§fn handle_event(
_state: &Self::State,
event: &Event,
ctx: &EventContext,
) -> Option<Self::Message>
fn handle_event( _state: &Self::State, event: &Event, ctx: &EventContext, ) -> Option<Self::Message>
Maps an input event to a component message. Read more
Source§fn view(state: &Self::State, ctx: &mut RenderContext<'_, '_>)
fn view(state: &Self::State, ctx: &mut RenderContext<'_, '_>)
Render the component to the given area. Read more
Source§fn traced_view(state: &Self::State, ctx: &mut RenderContext<'_, '_>)
fn traced_view(state: &Self::State, ctx: &mut RenderContext<'_, '_>)
Renders the component with optional tracing instrumentation. Read more
Source§fn dispatch_event(
state: &mut Self::State,
event: &Event,
ctx: &EventContext,
) -> Option<Self::Output>
fn dispatch_event( state: &mut Self::State, event: &Event, ctx: &EventContext, ) -> Option<Self::Output>
Dispatches an event by mapping it to a message and updating state. Read more
Source§impl Toggleable for Switch
impl Toggleable for Switch
Source§fn is_visible(state: &Self::State) -> bool
fn is_visible(state: &Self::State) -> bool
Returns true if this component is currently visible.
Source§fn set_visible(state: &mut Self::State, visible: bool)
fn set_visible(state: &mut Self::State, visible: bool)
Sets the visibility of this component.
Auto Trait Implementations§
impl Freeze for Switch
impl RefUnwindSafe for Switch
impl Send for Switch
impl Sync for Switch
impl Unpin for Switch
impl UnsafeUnpin for Switch
impl UnwindSafe for Switch
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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