Decorators

Trait Decorators 

Source
pub trait Decorators: IntoView<V = Self::DV> + Sized {
    type DV: View;

Show 36 methods // Provided methods fn style(self, style: impl Fn(Style) -> Style + 'static) -> Self::DV { ... } fn debug_name(self, name: impl Into<String>) -> Self::DV { ... } fn debug_name_if<S: Into<String>>( self, apply: impl Fn() -> bool + 'static, name: impl Fn() -> S + 'static, ) -> Self::DV { ... } fn dragging_style( self, style: impl Fn(Style) -> Style + 'static, ) -> Self::DV { ... } fn class<C: StyleClass>(self, _class: C) -> Self::DV { ... } fn class_if<C: StyleClass>( self, apply: impl Fn() -> bool + 'static, _class: C, ) -> Self::DV { ... } fn remove_class<C: StyleClass>(self, _class: C) -> Self::DV { ... } fn keyboard_navigable(self) -> Self::DV { ... } fn disable_default_event( self, disable: impl Fn() -> (EventListener, bool) + 'static, ) -> Self::DV { ... } fn draggable(self) -> Self::DV { ... } fn disabled(self, disabled_fn: impl Fn() -> bool + 'static) -> Self::DV { ... } fn on_event( self, listener: EventListener, action: impl FnMut(&Event) -> EventPropagation + 'static, ) -> Self::DV { ... } fn on_key_down( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl Fn(&Event) + 'static, ) -> Self::DV { ... } fn on_key_up( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl Fn(&Event) + 'static, ) -> Self::DV { ... } fn on_event_cont( self, listener: EventListener, action: impl Fn(&Event) + 'static, ) -> Self::DV { ... } fn on_event_stop( self, listener: EventListener, action: impl Fn(&Event) + 'static, ) -> Self::DV { ... } fn on_click( self, action: impl FnMut(&Event) -> EventPropagation + 'static, ) -> Self::DV { ... } fn on_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::DV { ... } fn on_click_stop(self, action: impl FnMut(&Event) + 'static) -> Self::DV { ... } fn on_double_click( self, action: impl Fn(&Event) -> EventPropagation + 'static, ) -> Self::DV { ... } fn on_double_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::DV { ... } fn on_double_click_stop(self, action: impl Fn(&Event) + 'static) -> Self::DV { ... } fn on_secondary_click( self, action: impl Fn(&Event) -> EventPropagation + 'static, ) -> Self::DV { ... } fn on_secondary_click_cont( self, action: impl Fn(&Event) + 'static, ) -> Self::DV { ... } fn on_secondary_click_stop( self, action: impl Fn(&Event) + 'static, ) -> Self::DV { ... } fn on_resize(self, action: impl Fn(Rect) + 'static) -> Self::DV { ... } fn on_move(self, action: impl Fn(Point) + 'static) -> Self::DV { ... } fn on_cleanup(self, action: impl Fn() + 'static) -> Self::DV { ... } fn animation( self, animation: impl Fn(Animation) -> Animation + 'static, ) -> Self::DV { ... } fn clear_focus(self, when: impl Fn() + 'static) -> Self::DV { ... } fn request_focus(self, when: impl Fn() + 'static) -> Self::DV { ... } fn window_scale(self, scale_fn: impl Fn() -> f64 + 'static) -> Self { ... } fn window_title(self, title_fn: impl Fn() -> String + 'static) -> Self { ... } fn window_menu(self, menu_fn: impl Fn() -> Menu + 'static) -> Self { ... } fn context_menu(self, menu: impl Fn() -> Menu + 'static) -> Self::DV { ... } fn popout_menu(self, menu: impl Fn() -> Menu + 'static) -> Self::DV { ... }
}
Expand description

A trait that extends the appearance and functionality of Views through styling and event handling.

Required Associated Types§

Source

type DV: View

The type of the decorated view.

Using this type allows for chaining of decorators as well as maintaining the original type of the view which allows you to call methods that were a part of the original view even after calling a decorators method.

Provided Methods§

Source

fn style(self, style: impl Fn(Style) -> Style + 'static) -> Self::DV

Alter the style of the view.

Earlier applications of style have lower priority than later calls.

fn view() -> impl View {
    label(|| "Hello".to_string())
        .style(|s| s.font_size(20.0).color(palette::css::RED))
}

fn other() -> impl View {
    stack((
        view(), // will be red and size 20
        // will be green and default size due to the previous style being overwritten
        view().style(|s| s.color(palette::css::GREEN)),
    ))
}
Source

fn debug_name(self, name: impl Into<String>) -> Self::DV

Add a debug name to the view that will be shown in the inspector.

This can be called multiple times and each name will be shown in the inspector with the most recent name showing first.

Source

fn debug_name_if<S: Into<String>>( self, apply: impl Fn() -> bool + 'static, name: impl Fn() -> S + 'static, ) -> Self::DV

Conditionally add a debug name to the view that will be shown in the inspector.

§Reactivity

Both the apply and name functions are reactive.

Source

fn dragging_style(self, style: impl Fn(Style) -> Style + 'static) -> Self::DV

The visual style to apply when the mouse hovers over the element

Source

fn class<C: StyleClass>(self, _class: C) -> Self::DV

Add a style class to the view

Source

fn class_if<C: StyleClass>( self, apply: impl Fn() -> bool + 'static, _class: C, ) -> Self::DV

Conditionally add a style class to the view

Source

fn remove_class<C: StyleClass>(self, _class: C) -> Self::DV

Remove a style class from the view

Source

fn keyboard_navigable(self) -> Self::DV

Allows the element to be navigated to with the keyboard. Similar to setting tabindex=“0” in html.

Source

fn disable_default_event( self, disable: impl Fn() -> (EventListener, bool) + 'static, ) -> Self::DV

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.

§Reactivity

This function is reactive and will re-run the disable function automatically in response to changes in signals

Source

fn draggable(self) -> Self::DV

Mark the view as draggable

Source

fn disabled(self, disabled_fn: impl Fn() -> bool + 'static) -> Self::DV

Mark the view as disabled

§Reactivity

The disabled_fn is reactive.

Source

fn on_event( self, listener: EventListener, action: impl FnMut(&Event) -> EventPropagation + 'static, ) -> Self::DV

Add an event handler for the given EventListener.

Source

fn on_key_down( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl Fn(&Event) + 'static, ) -> Self::DV

Add an handler for pressing down a specific key.

NOTE: View should have .keyboard_navigable() in order to receive keyboard events

Source

fn on_key_up( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl Fn(&Event) + 'static, ) -> Self::DV

Add an handler for a specific key being released.

NOTE: View should have .keyboard_navigable() in order to receive keyboard events

Source

fn on_event_cont( self, listener: EventListener, action: impl Fn(&Event) + 'static, ) -> Self::DV

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( self, listener: EventListener, action: impl Fn(&Event) + 'static, ) -> Self::DV

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_click( self, action: impl FnMut(&Event) -> EventPropagation + 'static, ) -> Self::DV

Add an event handler for EventListener::Click.

Source

fn on_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::DV

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(&Event) + 'static) -> Self::DV

Add an event handler for EventListener::Click. This event will be handled with the given handler and the event will stop propagating.

Source

fn on_double_click( self, action: impl Fn(&Event) -> EventPropagation + 'static, ) -> Self::DV

Add an event handler for EventListener::DoubleClick

Source

fn on_double_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::DV

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 Fn(&Event) + 'static) -> Self::DV

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 Fn(&Event) -> EventPropagation + 'static, ) -> Self::DV

Add an event handler for EventListener::SecondaryClick. This is most often the “Right” click.

Source

fn on_secondary_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::DV

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 Fn(&Event) + 'static) -> Self::DV

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_resize(self, action: impl Fn(Rect) + 'static) -> Self::DV

Set the event handler for resize events for this view.

There can only be one resize event handler for a view.

§Reactivity

The action will be called whenever the view is resized but will not rerun automatically in response to signal changes

Source

fn on_move(self, action: impl Fn(Point) + 'static) -> Self::DV

Set the event handler for move events for this view.

There can only be one move event handler for a view.

§Reactivity

The action will be called whenever the view is moved but will not rerun automatically in response to signal changes

Source

fn on_cleanup(self, action: impl Fn() + 'static) -> Self::DV

Set the event handler for cleanup events for this view.

The cleanup event is called when the view is removed from the view tree.

There can only be one cleanup event handler for a view.

§Reactivity

The action will be called when the view is removed from the view tree but will not rerun automatically in response to signal changes

Source

fn animation( self, animation: impl Fn(Animation) -> Animation + 'static, ) -> Self::DV

Add an animation to the view.

You can add more than one animation to a view and all of them can be active at the same time.

See the Animation struct for more information on how to create animations.

§Reactivity

The animation function will be updated in response to signal changes in the function. The behavior is the same as the Decorators::style method.

Source

fn clear_focus(self, when: impl Fn() + 'static) -> Self::DV

Clear the focus from the window.

§Reactivity

The when function is reactive and will rereun in response to any signal changes in the function.

Source

fn request_focus(self, when: impl Fn() + 'static) -> Self::DV

Request that this view gets the focus for the window.

§Reactivity

The when function is reactive and will rereun in response to any signal changes in the function.

Source

fn window_scale(self, scale_fn: impl Fn() -> f64 + 'static) -> Self

Set the window scale factor.

This internally calls the crate::action::set_window_scale function.

§Reactivity

The scale function is reactive and will rereun in response to any signal changes in the function.

Source

fn window_title(self, title_fn: impl Fn() -> String + 'static) -> Self

Set the window title.

This internally calls the crate::action::set_window_title function.

§Reactivity

The title function is reactive and will rereun in response to any signal changes in the function.

Source

fn window_menu(self, menu_fn: impl Fn() -> Menu + 'static) -> Self

Set the system window menu

This internally calls the crate::action::set_window_menu function.

Platform support:

  • Windows: No
  • macOS: Yes (not currently implemented)
  • Linux: No
§Reactivity

The menu function is reactive and will rereun in response to any signal changes in the function.

Source

fn context_menu(self, menu: impl Fn() -> Menu + 'static) -> Self::DV

Adds a secondary-click context menu to the view, which opens at the mouse position.

§Reactivity

The menu function is not reactive and will not rerun automatically in response to signal changes while the menu is showing and will only update the menu items each time that it is created

Source

fn popout_menu(self, menu: impl Fn() -> Menu + 'static) -> Self::DV

Adds a primary-click context menu, which opens below the view.

§Reactivity

The menu function is not reactive and will not rerun automatically in response to signal changes while the menu is showing and will only update the menu items each time that it is created

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<VW: View, IV: IntoView<V = VW>> Decorators for IV

Source§

type DV = VW