Module zng::widget::info

source ·
Expand description

Widget info tree and info builder.

§Examples

The example declares a new info state for widgets and a property that sets the new state. The new state is then used in a widget.

mod custom {
    use zng::prelude_wgt::*;

    static_id! {
        static ref STATE_ID: StateId<bool>;
    }

    #[property(CONTEXT)]
    pub fn flag_state(child: impl UiNode, state: impl IntoVar<bool>) -> impl UiNode {
        let state = state.into_var();
        match_node(child, move |_, op| match op {
            UiNodeOp::Init => {
                WIDGET.sub_var_info(&state);
            }
            UiNodeOp::Info { info } => {
                info.set_meta(*STATE_ID, state.get());
            }
            _ => {}
        })
    }

    pub trait StateExt {
        fn state(&self) -> Option<bool>;
    }
    impl StateExt for WidgetInfo {
        fn state(&self) -> Option<bool> {
            self.meta().get_clone(*STATE_ID)
        }
    }
}

Wgt! {
    custom::flag_state = true;
    widget::on_info_init = hn!(|_| {
        use custom::StateExt as _;
        let info = WIDGET.info();
        println!("state: {:?}", info.state());
    });
}

Modules§

  • Accessibility metadata types.
  • Helper types for inspecting an UI tree.
  • Widget info tree iterators.

Structs§

Enums§

Statics§