Struct ambient_ui::prelude::Element
source · pub struct Element { /* private fields */ }
Expand description
A rendered ElementComponent instance.
Implementations§
source§impl Element
impl Element
sourcepub fn from_element_component(part: Box<dyn ElementComponent>) -> Element
pub fn from_element_component(part: Box<dyn ElementComponent>) -> Element
Creates a new Element from the given component.
sourcepub fn vec_of(self) -> Vec<Element>
pub fn vec_of(self) -> Vec<Element>
Convenience method to construct a Vec<Element>
from a single Element.
sourcepub fn with<T>(self, component: Component<T>, value: T) -> Element
pub fn with<T>(self, component: Component<T>, value: T) -> Element
Adds the given component
with value
to the element.
sourcepub fn init<T>(self, component: Component<T>, value: T) -> Element
pub fn init<T>(self, component: Component<T>, value: T) -> Element
Sets the given component
to value
on the element during initialization only.
sourcepub fn init_default<T>(self, component: Component<T>) -> Element
pub fn init_default<T>(self, component: Component<T>) -> Element
Calls Self::init with the default value for the component’s type.
sourcepub fn remove<T>(self, component: Component<T>) -> Elementwhere
T: SupportedValue + Clone,
pub fn remove<T>(self, component: Component<T>) -> Elementwhere
T: SupportedValue + Clone,
Removes the given component
from the element.
Warning: this only removes components on the current element.
sourcepub fn on_spawned<F>(self, handler: F) -> Element
pub fn on_spawned<F>(self, handler: F) -> Element
Set the callback to call when the element is spawned. The third argument is the instance ID.
sourcepub fn on_despawn<F>(self, handler: F) -> Element
pub fn on_despawn<F>(self, handler: F) -> Element
Set the callback to call when the element is despawned. The third argument is the instance ID.
sourcepub fn key<T>(self, key: T) -> Element
pub fn key<T>(self, key: T) -> Element
Set the unique key used to identify this element.
This is used to disambiguate elements with the same type. This should be used when rendering lists of elements.
sourcepub fn memoize_subtree(self, memo_key: impl Into<String>) -> Element
pub fn memoize_subtree(self, memo_key: impl Into<String>) -> Element
Avoid rendering the subtree, except when the memo_key is changed.
sourcepub fn has_component(&self, component: impl Into<ComponentDesc>) -> bool
pub fn has_component(&self, component: impl Into<ComponentDesc>) -> bool
Returns true if the element has the given component
.
sourcepub fn spawn_tree(self) -> ElementTree
pub fn spawn_tree(self) -> ElementTree
This spawns the elemet tree and returns it. The tree won’t be automatically updated, but can manually be updated
by calling the update
method.
sourcepub fn spawn_interactive(self)
pub fn spawn_interactive(self)
This spawns the element tree and sets up listeners to automatically update it.
This is equivalent to calling Self::spawn_tree and then calling ElementTree::update on the tree each frame.
You may want to update the tree manually if you want to replace the root Element:
let mut tree = Element::new().spawn_tree();
Frame::subscribe(move |_| {
if some_condition {
tree.migrate_root(&mut World, App::el(new_properties));
}
tree.update(&mut World);
});