Expand description
Prelude for declaring new properties and widgets.
This prelude can be imported over prelude.
§Examples
use zng::{prelude::*, prelude_wgt::*};
/// A button with only text child.
#[widget($crate::TextButton)]
pub struct TextButton(Button);
/// Button text.
#[property(CHILD, widget_impl(TextButton))]
pub fn txt(wgt: &mut WidgetBuilding, txt: impl IntoVar<Txt>) {
let _ = txt;
wgt.expect_property_capture();
}
impl TextButton {
fn widget_intrinsic(&mut self) {
self.widget_builder().push_build_action(|b| {
let txt = b
.capture_var::<Txt>(property_id!(Self::txt))
.unwrap_or_else(|| const_var(Txt::from("")));
b.set_child(Text!(txt));
});
}
}Re-exports§
pub use crate::__prelude_wgt::*;