Struct fyrox_ui::UiNode

source ·
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

source

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)
    }
}
source

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.

source

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.

source

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.

source

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§

source§

impl Deref for UiNode

§

type Target = dyn Control<Target = Widget>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for UiNode

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> FieldValue for Twhere T: 'static,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts self to a &dyn Any
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V