Struct UiNode

Source
pub struct UiNode(pub Box<dyn Control<Target = Widget>>);
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<Target = Widget>>

Implementations§

Source§

impl UiNode

Source

pub fn new<T>(widget: T) -> UiNode
where 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, Visit, Reflect, Debug, ComponentProvider)]
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(ctx),
        };

        // 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 fyrox_core::type_traits::ComponentProvider::query_component_ref for more info.

Source

pub fn has_component<T>(&self) -> bool
where 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 Clone for UiNode

Source§

fn clone(&self) -> UiNode

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ComponentProvider for UiNode

Source§

fn query_component_ref(&self, type_id: TypeId) -> Option<&(dyn Any + 'static)>

Allows an object to provide access to inner components.
Source§

fn query_component_mut( &mut self, type_id: TypeId, ) -> Option<&mut (dyn Any + 'static)>

Allows an object to provide access to inner components.
Source§

impl ConstructorProvider<UiNode, UserInterface> for AbsmEventProvider

Source§

impl ConstructorProvider<UiNode, UserInterface> for AlphaBar

Source§

impl ConstructorProvider<UiNode, UserInterface> for AnimationBlendingStateMachine

Source§

impl ConstructorProvider<UiNode, UserInterface> for AnimationPlayer

Source§

impl<T> ConstructorProvider<UiNode, UserInterface> for BitField<T>
where T: BitContainer,

Source§

impl ConstructorProvider<UiNode, UserInterface> for Border

Source§

impl ConstructorProvider<UiNode, UserInterface> for Button

Source§

impl ConstructorProvider<UiNode, UserInterface> for Canvas

Source§

impl ConstructorProvider<UiNode, UserInterface> for CheckBox

Source§

impl ConstructorProvider<UiNode, UserInterface> for ColorField

Source§

impl ConstructorProvider<UiNode, UserInterface> for ColorGradientEditor

Source§

impl ConstructorProvider<UiNode, UserInterface> for ColorGradientField

Source§

impl ConstructorProvider<UiNode, UserInterface> for ColorPicker

Source§

impl ConstructorProvider<UiNode, UserInterface> for ColorPoint

Source§

impl ConstructorProvider<UiNode, UserInterface> for ContextMenu

Source§

impl ConstructorProvider<UiNode, UserInterface> for CurveEditor

Source§

impl ConstructorProvider<UiNode, UserInterface> for Decorator

Source§

impl ConstructorProvider<UiNode, UserInterface> for DockingManager

Source§

impl ConstructorProvider<UiNode, UserInterface> for DropdownList

Source§

impl ConstructorProvider<UiNode, UserInterface> for Expander

Source§

impl ConstructorProvider<UiNode, UserInterface> for FileBrowser

Source§

impl ConstructorProvider<UiNode, UserInterface> for FileSelector

Source§

impl ConstructorProvider<UiNode, UserInterface> for FileSelectorField

Source§

impl ConstructorProvider<UiNode, UserInterface> for Grid

Source§

impl ConstructorProvider<UiNode, UserInterface> for HotKeyEditor

Source§

impl ConstructorProvider<UiNode, UserInterface> for HueBar

Source§

impl ConstructorProvider<UiNode, UserInterface> for Image

Source§

impl ConstructorProvider<UiNode, UserInterface> for Inspector

Source§

impl ConstructorProvider<UiNode, UserInterface> for KeyBindingEditor

Source§

impl ConstructorProvider<UiNode, UserInterface> for ListView

Source§

impl ConstructorProvider<UiNode, UserInterface> for ListViewItem

Source§

impl ConstructorProvider<UiNode, UserInterface> for Menu

Source§

impl ConstructorProvider<UiNode, UserInterface> for MenuItem

Source§

impl ConstructorProvider<UiNode, UserInterface> for MessageBox

Source§

impl ConstructorProvider<UiNode, UserInterface> for NinePatch

Source§

impl<T> ConstructorProvider<UiNode, UserInterface> for NumericUpDown<T>
where T: NumericType,

Source§

impl ConstructorProvider<UiNode, UserInterface> for PathEditor

Source§

impl ConstructorProvider<UiNode, UserInterface> for Popup

Source§

impl ConstructorProvider<UiNode, UserInterface> for ProgressBar

Source§

impl<T> ConstructorProvider<UiNode, UserInterface> for RangeEditor<T>
where T: NumericType,

Source§

impl<T> ConstructorProvider<UiNode, UserInterface> for RectEditor<T>
where T: NumericType,

Source§

impl ConstructorProvider<UiNode, UserInterface> for SaturationBrightnessField

Source§

impl ConstructorProvider<UiNode, UserInterface> for Screen

Source§

impl ConstructorProvider<UiNode, UserInterface> for ScrollBar

Source§

impl ConstructorProvider<UiNode, UserInterface> for ScrollPanel

Source§

impl ConstructorProvider<UiNode, UserInterface> for ScrollViewer

Source§

impl ConstructorProvider<UiNode, UserInterface> for Selector

Source§

impl ConstructorProvider<UiNode, UserInterface> for StackPanel

Source§

impl ConstructorProvider<UiNode, UserInterface> for TabControl

Source§

impl ConstructorProvider<UiNode, UserInterface> for Text

Source§

impl ConstructorProvider<UiNode, UserInterface> for TextBox

Source§

impl ConstructorProvider<UiNode, UserInterface> for Thumb

Source§

impl ConstructorProvider<UiNode, UserInterface> for Tile

Source§

impl ConstructorProvider<UiNode, UserInterface> for ToggleButton

Source§

impl ConstructorProvider<UiNode, UserInterface> for Tree

Source§

impl ConstructorProvider<UiNode, UserInterface> for TreeRoot

Source§

impl ConstructorProvider<UiNode, UserInterface> for UuidEditor

Source§

impl<T, const D: usize> ConstructorProvider<UiNode, UserInterface> for VecEditor<T, D>
where T: NumericType,

Source§

impl ConstructorProvider<UiNode, UserInterface> for VectorImage

Source§

impl ConstructorProvider<UiNode, UserInterface> for Window

Source§

impl ConstructorProvider<UiNode, UserInterface> for WrapPanel

Source§

impl Debug for UiNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl DerefMut for UiNode

Source§

fn deref_mut(&mut self) -> &mut <UiNode as Deref>::Target

Mutably dereferences the value.
Source§

impl<T> From<T> for UiNode
where T: Control,

Source§

fn from(value: T) -> UiNode

Converts to this type from the input type.
Source§

impl NameProvider for UiNode

Source§

fn name(&self) -> &str

Returns a reference to the name of the entity.
Source§

impl Reflect for UiNode

Source§

fn source_path() -> &'static str

Source§

fn type_name(&self) -> &'static str

Source§

fn doc(&self) -> &'static str

Source§

fn assembly_name(&self) -> &'static str

Returns a parent assembly name of the type that implements this trait. WARNING: You should use proc-macro (#[derive(Reflect)]) to ensure that this method will return correct assembly name. In other words - there’s no guarantee, that any implementation other than proc-macro will return a correct name of the assembly. Alternatively, you can use env!("CARGO_PKG_NAME") as an implementation.
Source§

fn type_assembly_name() -> &'static str

Returns a parent assembly name of the type that implements this trait. WARNING: You should use proc-macro (#[derive(Reflect)]) to ensure that this method will return correct assembly name. In other words - there’s no guarantee, that any implementation other than proc-macro will return a correct name of the assembly. Alternatively, you can use env!("CARGO_PKG_NAME") as an implementation.
Source§

fn fields_info(&self, func: &mut dyn FnMut(&[FieldInfo<'_, '_>]))

Source§

fn into_any(self: Box<UiNode>) -> Box<dyn Any>

Source§

fn as_any(&self, func: &mut dyn FnMut(&(dyn Any + 'static)))

Source§

fn as_any_mut(&mut self, func: &mut dyn FnMut(&mut (dyn Any + 'static)))

Source§

fn as_reflect(&self, func: &mut dyn FnMut(&(dyn Reflect + 'static)))

Source§

fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut (dyn Reflect + 'static)))

Source§

fn set( &mut self, value: Box<dyn Reflect>, ) -> Result<Box<dyn Reflect>, Box<dyn Reflect>>

Source§

fn set_field( &mut self, field: &str, value: Box<dyn Reflect>, func: &mut dyn FnMut(Result<Box<dyn Reflect>, Box<dyn Reflect>>), )

Calls user method specified with #[reflect(setter = ..)] or falls back to Reflect::field_mut
Source§

fn fields(&self, func: &mut dyn FnMut(&[&(dyn Reflect + 'static)]))

Source§

fn fields_mut( &mut self, func: &mut dyn FnMut(&mut [&mut (dyn Reflect + 'static)]), )

Source§

fn field( &self, name: &str, func: &mut dyn FnMut(Option<&(dyn Reflect + 'static)>), )

Source§

fn field_mut( &mut self, name: &str, func: &mut dyn FnMut(Option<&mut (dyn Reflect + 'static)>), )

Source§

fn as_array(&self, func: &mut dyn FnMut(Option<&(dyn ReflectArray + 'static)>))

Source§

fn as_array_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectArray + 'static)>), )

Source§

fn as_list(&self, func: &mut dyn FnMut(Option<&(dyn ReflectList + 'static)>))

Source§

fn as_list_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectList + 'static)>), )

Source§

fn as_inheritable_variable( &self, func: &mut dyn FnMut(Option<&(dyn ReflectInheritableVariable + 'static)>), )

Source§

fn as_inheritable_variable_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectInheritableVariable + 'static)>), )

Source§

fn as_hash_map( &self, func: &mut dyn FnMut(Option<&(dyn ReflectHashMap + 'static)>), )

Source§

fn as_hash_map_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectHashMap + 'static)>), )

Source§

impl SceneGraphNode for UiNode

Source§

type Base = Widget

Source§

type SceneGraph = UserInterface

Source§

type ResourceData = UserInterface

Source§

fn base(&self) -> &<UiNode as SceneGraphNode>::Base

Source§

fn set_base(&mut self, base: <UiNode as SceneGraphNode>::Base)

Source§

fn is_resource_instance_root(&self) -> bool

Source§

fn original_handle_in_resource(&self) -> Handle<UiNode>

Source§

fn set_original_handle_in_resource(&mut self, handle: Handle<UiNode>)

Source§

fn resource(&self) -> Option<Resource<<UiNode as SceneGraphNode>::ResourceData>>

Source§

fn self_handle(&self) -> Handle<UiNode>

Source§

fn parent(&self) -> Handle<UiNode>

Source§

fn children(&self) -> &[Handle<UiNode>]

Source§

fn children_mut(&mut self) -> &mut [Handle<UiNode>]

Source§

fn swap_child_position( &mut self, child: Handle<Self>, pos: usize, ) -> Option<usize>

Puts the given child handle to the given position pos, by swapping positions.
Source§

fn set_child_position( &mut self, child: Handle<Self>, dest_pos: usize, ) -> Option<usize>

Source§

fn child_position(&self, child: Handle<Self>) -> Option<usize>

Source§

fn has_child(&self, child: Handle<Self>) -> bool

Source§

fn revert_inheritable_property( &mut self, path: &str, ) -> Option<Box<dyn Reflect>>

Source§

fn component_ref<T>(&self) -> Option<&T>
where T: Any,

Tries to borrow a component of given type.
Source§

fn component_mut<T>(&mut self) -> Option<&mut T>
where T: Any,

Tries to borrow a component of given type.
Source§

fn has_component<T>(&self) -> bool
where T: Any,

Checks if the node has a component of given type.
Source§

impl TypeUuidProvider for UiNode

Source§

fn type_uuid() -> Uuid

Return type UUID.
Source§

impl Visit for UiNode

Source§

fn visit(&mut self, name: &str, visitor: &mut Visitor) -> Result<(), VisitError>

Read or write this value, depending on whether Visitor::is_reading() is true or false. Read more
Source§

impl Deref for UiNode

Source§

type Target = dyn Control<Target = Widget>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<UiNode as Deref>::Target

Dereferences the value.

Auto Trait Implementations§

§

impl Freeze for UiNode

§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsyncTaskResult for T
where T: Any + Send + 'static,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

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

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast for T
where T: Any,

Source§

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

Converts self reference as a reference to Any. Could be used to downcast a trait object to a particular type.
Source§

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

Converts self reference as a reference to Any. Could be used to downcast a trait object to a particular type.
Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

impl<T> FieldValue for T
where 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<R> GetField for R
where R: Reflect,

Source§

fn get_field<T>(&self, name: &str, func: &mut dyn FnMut(Option<&T>))
where T: 'static,

Source§

fn get_field_mut<T>(&mut self, name: &str, func: &mut dyn FnMut(Option<&mut T>))
where T: 'static,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ReflectBase for T
where T: Reflect,

Source§

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

Source§

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

Source§

impl<T> ResolvePath for T
where T: Reflect,

Source§

fn resolve_path<'p>( &self, path: &'p str, func: &mut dyn FnMut(Result<&(dyn Reflect + 'static), ReflectPathError<'p>>), )

Source§

fn resolve_path_mut<'p>( &mut self, path: &'p str, func: &mut dyn FnMut(Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>), )

Source§

fn get_resolve_path<'p, T>( &self, path: &'p str, func: &mut dyn FnMut(Result<&T, ReflectPathError<'p>>), )
where T: Reflect,

Source§

fn get_resolve_path_mut<'p, T>( &mut self, path: &'p str, func: &mut dyn FnMut(Result<&mut T, ReflectPathError<'p>>), )
where T: Reflect,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ScriptMessagePayload for T
where T: 'static + Send + Debug,

Source§

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

Returns self as &dyn Any
Source§

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

Returns self as &dyn Any
Source§

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

Source§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> Value for T
where T: Reflect + Clone + Debug + Send,

Source§

fn clone_box(&self) -> Box<dyn Value>

Source§

fn into_box_reflect(self: Box<T>) -> Box<dyn Reflect>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> AbstractSceneNode for T
where T: SceneGraphNode,

Source§

impl<T> InspectableEnum for T
where T: Debug + Reflect + Clone + TypeUuidProvider + Send + 'static,