Module zng::widget::builder

source ·
Expand description

Widget and property builder types.

§Examples

The example declares a new widget type, ShowProperties!, that inherits from Text! and display what properties are set on itself by accessing the WidgetBuilder at two points. First call is directly in the widget_intrinsic that is called after inherited intrinsics, but before the instance properties are set. Second call is in a build action that is called when the widget starts building, after the instance properties are set.

mod widgets {
    use std::fmt::Write as _;
    use zng::prelude_wgt::*;

    #[widget($crate::widgets::ShowProperties)]
    pub struct ShowProperties(zng::text::Text);

    impl ShowProperties {
        fn widget_intrinsic(&mut self) {
            let txt = var(Txt::from(""));
            widget_set! {
                self;
                txt = txt.clone();
            }

            let builder = self.widget_builder();

            let mut t = Txt::from("Properties set by default:\n");
            for p in builder.properties() {
                writeln!(&mut t, "• {}", p.args.property().name).unwrap();
            }

            builder.push_build_action(move |builder| {
                writeln!(&mut t, "\nAll properties set:").unwrap();
                for p in builder.properties() {
                    writeln!(&mut t, "• {}", p.args.property().name).unwrap();
                }
                txt.set(t.clone());            
            });
        }
    }
}

widgets::ShowProperties! {
    font_size = 20;
}

§Full API

See zng_app::widget::builder for the full API.

Macros§

Structs§

Enums§

Traits§

Type Aliases§