Macro zng_wgt_style::style_fn

source ·
macro_rules! style_fn {
    ($fn:path) => { ... };
    ($($tt:tt)+) => { ... };
    () => { ... };
}
Expand description

Declares a style function closure.

The output type is a StyleFn, the input can be a function name path or a closure, with input type &StyleArgs. The closure syntax is clone-move (clmv!).

§Examples

The example below declares a closure that prints every time it is used, the closure captures cloned by clone-move and moved by move. The closure ignores the StyleArgs because it is empty.

let cloned = var(10u32);
let moved = var(20u32);
let style_fn = style_fn!(cloned, |_| {
    println!(
        "style instantiated in {:?}, with captured values, {} and {}",
        WIDGET.try_id(),
        cloned.get(),
        moved.get()
    );

    Style! {
        // ..
    }
});