Macro zng_app::widget::widget_impl

source ·
macro_rules! widget_impl {
    (
        $(
            $(#[$attr:meta])*
            $vis:vis $($property:ident)::+ ($($arg:ident : $arg_ty:ty)*);
        )+
    ) => { ... };
}
Expand description

Implement a property on the widget to strongly associate it with the widget.

Widget implemented properties can be used on the widget without needing to be imported, they also show in the widget documentation page. As a general rule only properties that are captured by the widget, or only work with the widget, or have an special meaning in the widget are implemented like this, standalone properties that can be used in any widget are not implemented.

Note that you can also implement a property for a widget in the property declaration using the impl(Widget) directive in the property macro.

§Syntax

The macro syntax is one or more impl declarations, each declaration can have docs followed by the implementation visibility, usually pub, followed by the path to the property function, followed by a parenthesized list of the function input arguments, terminated by semicolon.

pub path::to::property(input: impl IntoVar<bool>);

§Examples

The example below declares a widget and uses this macro to implements the align property for the widget.

#[widget($crate::MyWgt)]
pub struct MyWgt(WidgetBase);

impl MyWgt {
    widget_impl! {
        /// Docs for the property in the widget.
        pub zng::widget::align(align: impl IntoVar<Align>);
    }
}