pub trait WidgetInfoInspectorExt {
// Required methods
fn inspector_info(&self) -> Option<Arc<InspectorInfo>>;
fn can_inspect(&self) -> bool;
fn inspect_child<P: InspectWidgetPattern>(
&self,
pattern: P,
) -> Option<WidgetInfo>;
fn inspect_descendant<P: InspectWidgetPattern>(
&self,
pattern: P,
) -> Option<WidgetInfo>;
fn inspect_ancestor<P: InspectWidgetPattern>(
&self,
pattern: P,
) -> Option<WidgetInfo>;
fn inspect_property<P: InspectPropertyPattern>(
&self,
pattern: P,
) -> Option<&dyn PropertyArgs>;
fn parent_property(&self) -> Option<(PropertyId, usize)>;
}
Expand description
Extensions methods for WidgetInfo
.
Required Methods§
sourcefn inspector_info(&self) -> Option<Arc<InspectorInfo>>
fn inspector_info(&self) -> Option<Arc<InspectorInfo>>
Reference the builder that was used to generate the widget, the builder generated items and the widget info context.
Returns None
if not build with the "inspector"
feature, or if the widget instance was not created using
the standard builder.
sourcefn can_inspect(&self) -> bool
fn can_inspect(&self) -> bool
If a inspector_info
is defined for the widget.
sourcefn inspect_child<P: InspectWidgetPattern>(
&self,
pattern: P,
) -> Option<WidgetInfo>
fn inspect_child<P: InspectWidgetPattern>( &self, pattern: P, ) -> Option<WidgetInfo>
Returns the first child that matches.
sourcefn inspect_descendant<P: InspectWidgetPattern>(
&self,
pattern: P,
) -> Option<WidgetInfo>
fn inspect_descendant<P: InspectWidgetPattern>( &self, pattern: P, ) -> Option<WidgetInfo>
Returns the first descendant that matches.
§Examples
Example searches for a “button” descendant, using a string search that matches the end of the WidgetType::path
and
an exact widget mod that matches the WidgetType::type_id
.
mod widgets {
use zng_app::widget::*;
#[widget($crate::widgets::Button)]
pub struct Button(base::WidgetBase);
}
let fuzzy = info.inspect_descendant("button");
let exact = info.inspect_descendant(std::any::TypeId::of::<crate::widgets::Button>());
sourcefn inspect_ancestor<P: InspectWidgetPattern>(
&self,
pattern: P,
) -> Option<WidgetInfo>
fn inspect_ancestor<P: InspectWidgetPattern>( &self, pattern: P, ) -> Option<WidgetInfo>
Returns the first ancestor that matches.
sourcefn inspect_property<P: InspectPropertyPattern>(
&self,
pattern: P,
) -> Option<&dyn PropertyArgs>
fn inspect_property<P: InspectPropertyPattern>( &self, pattern: P, ) -> Option<&dyn PropertyArgs>
Search for a property set on the widget.
§Examples
Search for a property by name, and then downcast its value.
fn inspect_foo(info: WidgetInfo) -> Option<bool> {
info.inspect_property("foo")?.value(0).as_any().downcast_ref().copied()
}
sourcefn parent_property(&self) -> Option<(PropertyId, usize)>
fn parent_property(&self) -> Option<(PropertyId, usize)>
Gets the parent property that has this widget as an input.
Returns Some((PropertyId, member_index))
.