pub trait CustomStyle:
Default
+ Clone
+ Into<Style>
+ From<Style> {
type StyleClass: StyleClass;
// Provided methods
fn style(self, style: impl FnOnce(Style) -> Style) -> Self { ... }
fn hover(self, style: impl FnOnce(Self) -> Self) -> Self { ... }
fn focus(self, style: impl FnOnce(Self) -> Self) -> Self { ... }
fn focus_visible(self, style: impl FnOnce(Self) -> Self) -> Self { ... }
fn selected(self, style: impl FnOnce(Self) -> Self) -> Self { ... }
fn disabled(self, style: impl FnOnce(Self) -> Self) -> Self { ... }
fn dark_mode(self, style: impl FnOnce(Self) -> Self) -> Self { ... }
fn active(self, style: impl FnOnce(Self) -> Self) -> Self { ... }
fn responsive(
self,
size: ScreenSize,
style: impl FnOnce(Self) -> Self,
) -> Self { ... }
fn apply_if(self, cond: bool, style: impl FnOnce(Self) -> Self) -> Self { ... }
fn apply_opt<T>(
self,
opt: Option<T>,
f: impl FnOnce(Self, T) -> Self,
) -> Self { ... }
fn transition<P: StyleProp>(self, _prop: P, transition: Transition) -> Self { ... }
}Expand description
A trait for custom styling of specific view types.
This trait allows views to have specialized styling methods beyond the basic Style properties. Each implementing type provides custom styling capabilities for a particular view type.
§Example
use floem::prelude::*;
use floem::style::CustomStylable;
use palette::css;
// Using custom styling on a text view
text("Hello").custom_style(|s: LabelCustomStyle| {
s.selection_color(css::BLUE)
});Required Associated Types§
Sourcetype StyleClass: StyleClass
type StyleClass: StyleClass
The CSS class associated with this custom style type.
Provided Methods§
Sourcefn style(self, style: impl FnOnce(Style) -> Style) -> Self
fn style(self, style: impl FnOnce(Style) -> Style) -> Self
Applies standard styling methods to this custom style.
This method allows you to use any of the standard Style methods while working within a custom style context.
§Example
label_custom_style.style(|s| s.padding(10.0).background(css::RED))Sourcefn hover(self, style: impl FnOnce(Self) -> Self) -> Self
fn hover(self, style: impl FnOnce(Self) -> Self) -> Self
Applies custom styling when the element is hovered.
This method allows you to define how the custom style should change when the mouse hovers over the element.
§Example
label_custom_style.hover(|s| s.selection_color(css::BLUE))Sourcefn focus(self, style: impl FnOnce(Self) -> Self) -> Self
fn focus(self, style: impl FnOnce(Self) -> Self) -> Self
Applies custom styling when the element has keyboard focus.
This method allows you to define how the custom style should change when the element gains keyboard focus.
§Example
label_custom_style.focus(|s| s.selection_color(css::GREEN))Sourcefn focus_visible(self, style: impl FnOnce(Self) -> Self) -> Self
fn focus_visible(self, style: impl FnOnce(Self) -> Self) -> Self
Similar to the :focus-visible css selector, this style only activates when tab navigation is used.
Sourcefn selected(self, style: impl FnOnce(Self) -> Self) -> Self
fn selected(self, style: impl FnOnce(Self) -> Self) -> Self
Applies custom styling when the element is in a selected state.
This method allows you to define how the custom style should change when the element is selected.
§Example
label_custom_style.selected(|s| s.selection_color(css::ORANGE))Sourcefn disabled(self, style: impl FnOnce(Self) -> Self) -> Self
fn disabled(self, style: impl FnOnce(Self) -> Self) -> Self
Applies custom styling when the element is disabled.
This method allows you to define how the custom style should change when the element is in a disabled state.
§Example
label_custom_style.disabled(|s| s.selection_color(css::GRAY))Sourcefn dark_mode(self, style: impl FnOnce(Self) -> Self) -> Self
fn dark_mode(self, style: impl FnOnce(Self) -> Self) -> Self
Applies custom styling when the application is in dark mode.
This method allows you to define how the custom style should change when the application switches to dark mode.
§Example
label_custom_style.dark_mode(|s| s.selection_color(css::WHITE))Sourcefn active(self, style: impl FnOnce(Self) -> Self) -> Self
fn active(self, style: impl FnOnce(Self) -> Self) -> Self
Applies custom styling when the element is being actively pressed.
This method allows you to define how the custom style should change when the element is being actively pressed (e.g., mouse button down).
§Example
label_custom_style.active(|s| s.selection_color(css::RED))Sourcefn responsive(self, size: ScreenSize, style: impl FnOnce(Self) -> Self) -> Self
fn responsive(self, size: ScreenSize, style: impl FnOnce(Self) -> Self) -> Self
Applies custom styling that activates at specific screen sizes (responsive design).
This method allows you to define how the custom style should change based on the screen size, enabling responsive custom styling.
§Example
label_custom_style.responsive(ScreenSize::SM, |s| s.selection_color(css::PURPLE))Sourcefn apply_if(self, cond: bool, style: impl FnOnce(Self) -> Self) -> Self
fn apply_if(self, cond: bool, style: impl FnOnce(Self) -> Self) -> Self
Conditionally applies custom styling based on a boolean condition.
This method allows you to apply custom styling only when a condition is true, providing a convenient way to chain conditional styling operations.
§Example
label_custom_style.apply_if(is_highlighted, |s| s.selection_color(css::YELLOW))Sourcefn apply_opt<T>(self, opt: Option<T>, f: impl FnOnce(Self, T) -> Self) -> Self
fn apply_opt<T>(self, opt: Option<T>, f: impl FnOnce(Self, T) -> Self) -> Self
Conditionally applies custom styling based on an optional value.
This method allows you to apply custom styling only when an optional value is Some, passing the unwrapped value to the styling function.
§Example
label_custom_style.apply_opt(maybe_color, |s, color| s.selection_color(color))Sourcefn transition<P: StyleProp>(self, _prop: P, transition: Transition) -> Self
fn transition<P: StyleProp>(self, _prop: P, transition: Transition) -> Self
Sets a transition animation for a specific custom style property.
This method allows you to animate changes to custom style properties, creating smooth transitions when the property values change.
§Example
// Note: Actual property types vary by custom style implementationDyn 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.