pub struct ToggleButton { /* private fields */ }Expand description
A toggle button.
Implementations§
Source§impl ToggleButton
impl ToggleButton
Sourcepub fn new(state: impl Fn() -> bool + 'static) -> Self
pub fn new(state: impl Fn() -> bool + 'static) -> Self
Create new ToggleButton.
When the button is toggled by clicking or dragging the widget, an update will be
sent to the ToggleButton::on_toggle handler.
By default this toggle button has a style class of ToggleButtonClass applied
with a default style provided.
§Examples
// An example using read-write signal
let state = RwSignal::new(true);
let toggle = toggle_button(move || state.get())
.on_toggle(move |new_state| state.set(new_state));§Reactivity
This function is reactive and will reactively respond to changes.
Sourcepub fn new_rw(
state: impl SignalGet<bool> + SignalUpdate<bool> + Copy + 'static,
) -> Self
pub fn new_rw( state: impl SignalGet<bool> + SignalUpdate<bool> + Copy + 'static, ) -> Self
Create new ToggleButton with read-write signal.
§Examples
// Create read-write signal that will hold toggle button state
let state = RwSignal::new(false);
let simple = ToggleButton::new_rw(state);§Reactivity
This function will update provided signal on toggle or will be updated if signal changes due to external signal update.
Sourcepub fn on_toggle(self, ontoggle: impl Fn(bool) + 'static) -> Self
👎Deprecated: use .on_event_stop(ToggleChanged::listener(), |_, _|) directly instead
pub fn on_toggle(self, ontoggle: impl Fn(bool) + 'static) -> Self
Add an event handler to be run when the button is toggled.
This does not run if the state is changed because of an outside signal.
Sourcepub fn toggle_style(
self,
style: impl Fn(ToggleButtonCustomStyle) -> ToggleButtonCustomStyle + 'static,
) -> Self
pub fn toggle_style( self, style: impl Fn(ToggleButtonCustomStyle) -> ToggleButtonCustomStyle + 'static, ) -> Self
Set styles related to ToggleButton:
- handle color
- accent color
- handle inset
- circle radius
Trait Implementations§
Source§impl View for ToggleButton
impl View for ToggleButton
fn id(&self) -> ViewId
fn debug_name(&self) -> Cow<'static, str>
fn view_style(&self) -> Option<Style>
Source§fn update(&mut self, _cx: &mut UpdateCx<'_>, state: Box<dyn Any>)
fn update(&mut self, _cx: &mut UpdateCx<'_>, state: Box<dyn Any>)
Use this method to react to changes in view-related state.
You will usually send state to this hook manually using the
View’s Id handle Read morefn event(&mut self, cx: &mut EventCx<'_>) -> EventPropagation
Source§fn style_pass(&mut self, cx: &mut StyleCx<'_>)
fn style_pass(&mut self, cx: &mut StyleCx<'_>)
Use this method to style the view’s children. Read more
Source§fn paint(&mut self, cx: &mut PaintCx<'_>)
fn paint(&mut self, cx: &mut PaintCx<'_>)
View-specific implementation. Called during paint traversal for this view.
Children are painted automatically by Floem.
Views should only paint their own content (backgrounds, borders, custom drawing).fn view_class(&self) -> Option<StyleClassRef>
fn post_paint(&mut self, cx: &mut PaintCx<'_>)
Auto Trait Implementations§
impl Freeze for ToggleButton
impl !RefUnwindSafe for ToggleButton
impl !Send for ToggleButton
impl !Sync for ToggleButton
impl Unpin for ToggleButton
impl UnsafeUnpin for ToggleButton
impl !UnwindSafe for ToggleButton
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> ContainerExt for Twhere
T: IntoView + 'static,
impl<T> ContainerExt for Twhere
T: IntoView + 'static,
Source§impl<T> Decorators for Twhere
T: IntoView,
impl<T> Decorators for Twhere
T: IntoView,
Source§fn style(self, style: impl Fn(Style) -> Style + 'static) -> Self::Intermediate
fn style(self, style: impl Fn(Style) -> Style + 'static) -> Self::Intermediate
Alter the style of the view. Read more
Source§fn debug_name(self, name: impl Into<String>) -> Self::Intermediate
fn debug_name(self, name: impl Into<String>) -> Self::Intermediate
Add a debug name to the view that will be shown in the inspector. Read more
Source§fn debug_name_if<S: Into<String>>(
self,
apply: impl Fn() -> bool + 'static,
name: impl Fn() -> S + 'static,
) -> Self::Intermediate
fn debug_name_if<S: Into<String>>( self, apply: impl Fn() -> bool + 'static, name: impl Fn() -> S + 'static, ) -> Self::Intermediate
Conditionally add a debug name to the view that will be shown in the inspector. Read more
Source§fn dragging_style(
self,
style: impl Fn(Style) -> Style + 'static,
) -> Self::Intermediate
fn dragging_style( self, style: impl Fn(Style) -> Style + 'static, ) -> Self::Intermediate
The visual style to apply when the view is being dragged
Source§fn class<C: StyleClass>(self, _class: C) -> Self::Intermediate
fn class<C: StyleClass>(self, _class: C) -> Self::Intermediate
Add a style class to the view
Source§fn class_if<C: StyleClass>(
self,
apply: impl Fn() -> bool + 'static,
_class: C,
) -> Self::Intermediate
fn class_if<C: StyleClass>( self, apply: impl Fn() -> bool + 'static, _class: C, ) -> Self::Intermediate
Conditionally add a style class to the view
Source§fn remove_class<C: StyleClass>(self, _class: C) -> Self::Intermediate
fn remove_class<C: StyleClass>(self, _class: C) -> Self::Intermediate
Remove a style class from the view
👎Deprecated: Set this property using
Style::keyboard_navigable insteadAllows the element to be navigated to with the keyboard. Similar to setting tabindex=“0” in html.
Source§fn disable_default_event<L: EventListenerTrait>(
self,
disable: impl Fn() -> (L, bool) + 'static,
) -> Self::Intermediate
fn disable_default_event<L: EventListenerTrait>( self, disable: impl Fn() -> (L, bool) + 'static, ) -> Self::Intermediate
Dynamically controls whether the default view behavior for an event should be disabled.
When disable is true, children will still see the event, but the view event function will not be called nor
the event listeners on the view. Read more
Source§fn draggable(
self,
) -> <<Self as IntoView>::Intermediate as IntoView>::Intermediate
fn draggable( self, ) -> <<Self as IntoView>::Intermediate as IntoView>::Intermediate
Mark the current view as draggable with default configuration. Read more
Source§fn draggable_with_config(
self,
config: impl Fn() -> DragConfig + 'static,
) -> <<Self as IntoView>::Intermediate as IntoView>::Intermediate
fn draggable_with_config( self, config: impl Fn() -> DragConfig + 'static, ) -> <<Self as IntoView>::Intermediate as IntoView>::Intermediate
Mark the current view as draggable with custom configuration. Read more
Source§fn disabled(
self,
disabled_fn: impl Fn() -> bool + 'static,
) -> Self::Intermediate
fn disabled( self, disabled_fn: impl Fn() -> bool + 'static, ) -> Self::Intermediate
👎Deprecated: use
Style::set_disabled directly insteadMark the view as disabled Read more
Source§fn on_event_with_config<L: EventListenerTrait>(
self,
listener: L,
config: EventCallbackConfig,
action: impl FnMut(&mut EventCx<'_>, &L::EventData) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_event_with_config<L: EventListenerTrait>( self, listener: L, config: EventCallbackConfig, action: impl FnMut(&mut EventCx<'_>, &L::EventData) -> EventPropagation + 'static, ) -> Self::Intermediate
Add an event handler for the given
EventListener with custom phase configuration.Source§fn on_event_cont_with_config<L: EventListenerTrait>(
self,
listener: L,
config: EventCallbackConfig,
action: impl FnMut(&mut EventCx<'_>, &L::EventData) + 'static,
) -> Self::Intermediate
fn on_event_cont_with_config<L: EventListenerTrait>( self, listener: L, config: EventCallbackConfig, action: impl FnMut(&mut EventCx<'_>, &L::EventData) + 'static, ) -> Self::Intermediate
Add an event handler for the given
EventListener. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_event_stop_with_config<L: EventListenerTrait>(
self,
listener: L,
config: EventCallbackConfig,
action: impl FnMut(&mut EventCx<'_>, &L::EventData) + 'static,
) -> Self::Intermediate
fn on_event_stop_with_config<L: EventListenerTrait>( self, listener: L, config: EventCallbackConfig, action: impl FnMut(&mut EventCx<'_>, &L::EventData) + 'static, ) -> Self::Intermediate
Add an event handler for the given
EventListener. This event will be handled with
the given handler and the event will stop propagating.Source§fn on_event<L: EventListenerTrait>(
self,
listener: L,
action: impl FnMut(&mut EventCx<'_>, &L::EventData) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_event<L: EventListenerTrait>( self, listener: L, action: impl FnMut(&mut EventCx<'_>, &L::EventData) -> EventPropagation + 'static, ) -> Self::Intermediate
Add an event handler for the given
EventListener.Source§fn on_event_cont<L: EventListenerTrait>(
self,
listener: L,
action: impl FnMut(&mut EventCx<'_>, &L::EventData) + 'static,
) -> Self::Intermediate
fn on_event_cont<L: EventListenerTrait>( self, listener: L, action: impl FnMut(&mut EventCx<'_>, &L::EventData) + 'static, ) -> Self::Intermediate
Add an event handler for the given
EventListener. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_event_stop<L: EventListenerTrait>(
self,
listener: L,
action: impl FnMut(&mut EventCx<'_>, &L::EventData) + 'static,
) -> Self::Intermediate
fn on_event_stop<L: EventListenerTrait>( self, listener: L, action: impl FnMut(&mut EventCx<'_>, &L::EventData) + 'static, ) -> Self::Intermediate
Add an event handler for the given
EventListener. This event will be handled with
the given handler and the event will stop propagating.Source§fn on_key_down(
self,
key: Key,
cmp: impl Fn(Modifiers) -> bool + 'static,
action: impl FnMut(&mut EventCx<'_>, &KeyboardEvent) + 'static,
) -> Self::Intermediate
fn on_key_down( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl FnMut(&mut EventCx<'_>, &KeyboardEvent) + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event(listener::KeyDown, ...) instead.Add a handler for pressing down a specific key.
Source§fn on_key_up(
self,
key: Key,
cmp: impl Fn(Modifiers) -> bool + 'static,
action: impl FnMut(&mut EventCx<'_>, &KeyboardEvent) + 'static,
) -> Self::Intermediate
fn on_key_up( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl FnMut(&mut EventCx<'_>, &KeyboardEvent) + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event(listener::KeyUp, ...) instead.Add a handler for a specific key being released.
Source§fn on_click(
self,
action: impl FnMut(&mut EventCx<'_>) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_click( self, action: impl FnMut(&mut EventCx<'_>) -> EventPropagation + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event(Click, |cx, _event| { ... }) instead. The new API provides direct access to typed event data.Add an event handler for
EventListener::Click.Source§fn on_click_cont(
self,
action: impl FnMut(&mut EventCx<'_>) + 'static,
) -> Self::Intermediate
fn on_click_cont( self, action: impl FnMut(&mut EventCx<'_>) + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event_cont(Click, |cx, _event| { ... }) instead. The new API provides direct access to typed event data.Add an event handler for
EventListener::Click. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_click_stop(
self,
action: impl FnMut(&mut EventCx<'_>) + 'static,
) -> Self::Intermediate
fn on_click_stop( self, action: impl FnMut(&mut EventCx<'_>) + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event_stop(Click, |cx, _event| { ... }) instead. The new API provides direct access to typed event data.Add an event handler for
EventListener::Click. This event will be handled with
the given handler and the event will stop propagating.Source§fn action(self, action: impl FnMut() + 'static) -> Self::Intermediate
fn action(self, action: impl FnMut() + 'static) -> Self::Intermediate
Attach action executed on button click or Enter or Space Key.
Source§fn on_double_click(
self,
action: impl FnMut(&mut EventCx<'_>) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_double_click( self, action: impl FnMut(&mut EventCx<'_>) -> EventPropagation + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event(DoubleClick, |cx, _event| { ... }) instead. The new API provides direct access to typed event data.Add an event handler for
EventListener::DoubleClickSource§fn on_double_click_cont(
self,
action: impl FnMut(&mut EventCx<'_>) + 'static,
) -> Self::Intermediate
fn on_double_click_cont( self, action: impl FnMut(&mut EventCx<'_>) + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event_cont(DoubleClick, |cx, _event| { ... }) instead. The new API provides direct access to typed event data.Add an event handler for
EventListener::DoubleClick. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_double_click_stop(
self,
action: impl FnMut(&mut EventCx<'_>) + 'static,
) -> Self::Intermediate
fn on_double_click_stop( self, action: impl FnMut(&mut EventCx<'_>) + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event_stop(DoubleClick, |cx, _event| { ... }) instead. The new API provides direct access to typed event data.Add an event handler for
EventListener::DoubleClick. This event will be handled with
the given handler and the event will stop propagating.Source§fn on_secondary_click(
self,
action: impl FnMut(&mut EventCx<'_>) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_secondary_click( self, action: impl FnMut(&mut EventCx<'_>) -> EventPropagation + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event(SecondaryClick, |cx, _event| { ... }) instead. The new API provides direct access to typed event data.Add an event handler for
EventListener::SecondaryClick. This is most often the “Right” click.Source§fn on_secondary_click_cont(
self,
action: impl FnMut(&mut EventCx<'_>) + 'static,
) -> Self::Intermediate
fn on_secondary_click_cont( self, action: impl FnMut(&mut EventCx<'_>) + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event_cont(SecondaryClick, |cx, _event| { ... }) instead. The new API provides direct access to typed event data.Add an event handler for
EventListener::SecondaryClick. This is most often the “Right” click.
This event will be handled with the given handler and the event will continue propagating.Source§fn on_secondary_click_stop(
self,
action: impl FnMut(&mut EventCx<'_>) + 'static,
) -> Self::Intermediate
fn on_secondary_click_stop( self, action: impl FnMut(&mut EventCx<'_>) + 'static, ) -> Self::Intermediate
👎Deprecated: Use
on_event_stop(SecondaryClick, |cx, _event| { ... }) instead. The new API provides direct access to typed event data.Add an event handler for
EventListener::SecondaryClick. This is most often the “Right” click.
This event will be handled with the given handler and the event will stop propagating.Source§fn on_cleanup(self, action: impl Fn() + 'static) -> Self::Intermediate
fn on_cleanup(self, action: impl Fn() + 'static) -> Self::Intermediate
Adds an event handler for cleanup events for this view. Read more
Source§fn animation(
self,
animation: impl Fn(Animation) -> Animation + 'static,
) -> Self::Intermediate
fn animation( self, animation: impl Fn(Animation) -> Animation + 'static, ) -> Self::Intermediate
Add an animation to the view. Read more
Source§fn clear_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
fn clear_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
Clear the focus from the window. Read more
Source§fn request_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
fn request_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
Request that this view gets the focus for the window. Read more
Source§fn window_scale(
self,
scale_fn: impl Fn() -> f64 + 'static,
) -> Self::Intermediate
fn window_scale( self, scale_fn: impl Fn() -> f64 + 'static, ) -> Self::Intermediate
Set the window scale factor. Read more
Source§fn window_title(
self,
title_fn: impl Fn() -> String + 'static,
) -> Self::Intermediate
fn window_title( self, title_fn: impl Fn() -> String + 'static, ) -> Self::Intermediate
Set the window title. Read more
Set the system window menu Read more
Adds a secondary-click context menu to the view, which opens at the mouse position. Read more
Adds a primary-click context menu, which opens below the view. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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