CustomStylable

Trait CustomStylable 

Source
pub trait CustomStylable<S: CustomStyle + 'static>: IntoView<V = Self::DV> + Sized {
    type DV: View;

    // Provided method
    fn custom_style(self, style: impl Fn(S) -> S + 'static) -> Self::DV { ... }
}
Expand description

A trait that enables views to accept custom styling beyond the standard Style properties.

This trait allows specific view types to provide their own specialized styling methods that are tailored to their functionality. For example, a label might have custom selection styling, or a button might have custom press animations.

§Type Parameters

  • S - The custom style type associated with this view (e.g., LabelCustomStyle)

§Example

use floem::prelude::*;
use floem::style::CustomStylable;
use palette::css;

// Using custom styling on a view that implements CustomStylable
text("Hello World")
    .custom_style(|s: LabelCustomStyle| {
        s.selection_color(css::BLUE)
         .selectable(false)
    });

Required Associated Types§

Source

type DV: View

The view type that this custom stylable converts to.

Provided Methods§

Source

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

Applies custom styling to the view with access to specialized custom style methods.

This method allows you to use custom styling methods that are specific to this view type, going beyond the standard styling properties available on all views.

§Parameters
  • style - A closure that takes the custom style type and returns the modified style
§Implementation Note

For trait implementors: Don’t implement this method yourself, just use the trait’s default implementation. The default implementation properly handles style registration and updates.

§Example
use floem::prelude::*;
use floem::style::CustomStylable;

// Custom styling with theme integration
text("Status")
    .custom_style(|s: LabelCustomStyle| {
        s.selection_color(Color::from_rgb8(100, 150, 255))
         .selectable(true)
    });

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§