impl_named_style_fn

Macro impl_named_style_fn 

Source
macro_rules! impl_named_style_fn {
    ($name:ident, $NamedStyle:ty) => { ... };
}
Expand description

Implements a NAMED_STYLE_FN_VAR, named_style_fn and NamedStyle! items.

This is a helper for declaring named styles that can be modified contextually, just like the default style.

ยงExamples

The example bellow declares a FooStyle manually, this is a normal definition for a named style. This macro generates a foo_style_fn property and a FOO_STYLE_FN_VAR context var. Note that the manual style implementation must set the named_style_fn, otherwise the style will not inherit from the correct name.

/// Foo style.
#[widget($crate::FooStyle)]
pub struct FooStyle(Style);
impl FooStyle {
    fn widget_intrinsic(&mut self) {
        widget_set! {
            self;
            style_fn_var = FOO_STYLE_FN_VAR;

            // .. style properties here
        }
    }
}
impl_named_style_fn!(foo, FooStyle);