pub struct UiNode(pub Box<dyn Control>);Expand description
UI node is a type-agnostic wrapper for any widget type. Internally, it is just a trait object
that provides common widget interface. Its main use is to reduce code bloat (no need to type
Box<dyn Control> everywhere, just UiNode) and to provide some useful methods such as type
casting, component querying, etc. You could also be interested in Control docs, since it
contains all the interesting stuff and detailed description for each method.
Tuple Fields§
§0: Box<dyn Control>Implementations§
source§impl UiNode
impl UiNode
sourcepub fn new<T>(widget: T) -> Selfwhere
T: Control,
pub fn new<T>(widget: T) -> Selfwhere T: Control,
Creates a new UI node from any object that implements Control trait. Its main use
is to finish widget creation like so:
#[derive(Clone)]
struct MyWidget {
widget: Widget,
}
struct MyWidgetBuilder {
widget_builder: WidgetBuilder,
}
impl MyWidgetBuilder {
pub fn build(self, ctx: &mut BuildContext) -> Handle<UiNode> {
let my_widget = MyWidget {
widget: self.widget_builder.build(),
};
// Wrap your widget in the type-agnostic wrapper so it can be placed in the UI.
let node = UiNode::new(my_widget);
ctx.add_node(node)
}
}sourcepub fn cast<T>(&self) -> Option<&T>where
T: Control,
pub fn cast<T>(&self) -> Option<&T>where T: Control,
Tries to perform direct downcasting to a particular widget type. It is just a simple wrapper
for Any::downcast_ref.
sourcepub fn cast_mut<T>(&mut self) -> Option<&mut T>where
T: Control,
pub fn cast_mut<T>(&mut self) -> Option<&mut T>where T: Control,
Tries to perform direct downcasting to a particular widget type. It is just a simple wrapper
for Any::downcast_mut.
sourcepub fn query_component<T>(&self) -> Option<&T>where
T: 'static,
pub fn query_component<T>(&self) -> Option<&T>where T: 'static,
Tries to fetch a component of the given type T. At very basis it mimics Self::cast behaviour, but
also allows you to fetch components of other types as well. For example, your widget may be built on
top of existing one (via composition) and you have it as a field inside your widget. In this case, you
can fetch it by using this method with the appropriate type. See docs for Control::query_component
for more info.
sourcepub fn has_component<T>(&self) -> boolwhere
T: 'static,
pub fn has_component<T>(&self) -> boolwhere T: 'static,
This method checks if the widget has a component of the given type T. Internally, it queries the component
of the given type and checks if it exists.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for UiNode
impl !Send for UiNode
impl !Sync for UiNode
impl Unpin for UiNode
impl !UnwindSafe for UiNode
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere T: 'static,
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.