Decorators

Trait Decorators 

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

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

This trait is automatically implemented for all IntoView types via a blanket implementation. The decoration behavior depends on the type’s IntoView::Intermediate type:

  • [View] types: Decorated directly (already have a ViewId)
  • Primitives (&str, String, i32, etc.): Wrapped in LazyView which creates a ViewId eagerly but defers view construction
  • Tuples/Vecs: Converted eagerly to their view type

Provided Methods§

Source

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

Alter the style of the view.

The Floem style system provides comprehensive styling capabilities including:

§Layout & Sizing
  • Flexbox & Grid: Full CSS-style layout with flex(), grid(), alignment, and gap controls
  • Dimensions: Width, height, min/max sizes with pixels, percentages, or auto sizing
  • Spacing: Padding, margins with individual side control or shorthand methods
  • Positioning: Absolute positioning with inset controls
§Visual Styling
  • Colors & Brushes: Solid colors, gradients, and custom brushes for backgrounds and text
  • Borders: Individual border styling per side with colors, widths, and radius
  • Shadows: Box shadows with blur, spread, offset, and color customization
  • Typography: Font family, size, weight, style, and line height control
§Interactive States
  • Pseudo-states: Styling for hover, focus, active, disabled, and selected states
  • Dark Mode: Automatic dark mode styling support
  • Responsive Design: Breakpoint-based styling for different screen sizes
§Advanced Features
  • Animations: Smooth transitions between style changes with easing functions
  • Custom Properties: Define and use custom style properties for specialized views
  • Style Classes: Reusable style definitions that can be applied across views
  • Conditional Styling: Apply styles based on conditions using apply_if() and apply_opt()
  • Transform: Scale, translate, and rotate transformations
§Style Application

Styles are reactive and will automatically update when dependencies change. Subsequent calls to style will overwrite previous ones.

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::Intermediate

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::Intermediate

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::Intermediate

The visual style to apply when the view is being dragged

Source

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

Conditionally add a style class to the view

Source

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

Remove a style class from the view

Source

fn keyboard_navigable(self) -> Self::Intermediate

👎Deprecated: Set this property using Style::focusable instead

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::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.

§Reactivity

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

Source

fn draggable(self) -> Self::Intermediate

👎Deprecated: use Style::draggable directly instead

Mark the view as draggable

Source

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

👎Deprecated: use Style::set_disabled directly instead

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::Intermediate

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::Intermediate

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::Intermediate

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

Add an event handler for EventListener::Click.

Source

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

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::Intermediate

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

Attach action executed on button click or Enter or Space Key.

Source

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

Add an event handler for EventListener::DoubleClick

Source

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

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::Intermediate

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::Intermediate

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::Intermediate

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::Intermediate

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::Intermediate

Adds an event handler for resize events for this 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::Intermediate

Adds an event handler for move events for this 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::Intermediate

Adds an event handler for cleanup events for this view.

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

§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::Intermediate

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::Intermediate

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::Intermediate

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::Intermediate

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::Intermediate

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::Intermediate

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
  • wasm32: 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::Intermediate

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::Intermediate

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<T: IntoView> Decorators for T

Blanket implementation for all IntoView types.