Struct ambient_element::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>) -> Self
pub fn from_element_component(part: Box<dyn ElementComponent>) -> Self
Creates a new Element from the given component.
sourcepub fn vec_of(self) -> Vec<Self>
pub fn vec_of(self) -> Vec<Self>
Convenience method to construct a Vec<Element>
from a single Element.
sourcepub fn with<T: ComponentValue + Sync + Send + Clone + 'static>(
self,
component: Component<T>,
value: T
) -> Self
pub fn with<T: ComponentValue + Sync + Send + Clone + 'static>( self, component: Component<T>, value: T ) -> Self
Adds the given component
with value
to the element.
sourcepub fn init<T: ComponentValue + Sync + Send + Clone + 'static>(
self,
component: Component<T>,
value: T
) -> Self
pub fn init<T: ComponentValue + Sync + Send + Clone + 'static>( self, component: Component<T>, value: T ) -> Self
Sets the given component
to value
on the element during initialization only.
sourcepub fn init_default<T: ComponentValue + Sync + Send + Clone + Default + 'static>(
self,
component: Component<T>
) -> Self
pub fn init_default<T: ComponentValue + Sync + Send + Clone + Default + 'static>( self, component: Component<T> ) -> Self
Calls Self::init with the default value for the component’s type.
sourcepub fn remove<T: ComponentValue + Clone>(self, component: Component<T>) -> Self
pub fn remove<T: ComponentValue + Clone>(self, component: Component<T>) -> Self
Removes the given component
from the element.
Warning: this only removes components on the current element.
sourcepub fn spawner<F: Fn(&mut World, Entity) -> EntityId + Sync + Send + 'static>(
self,
handler: F
) -> Self
pub fn spawner<F: Fn(&mut World, Entity) -> EntityId + Sync + Send + 'static>( self, handler: F ) -> Self
Set the function used to spawn the element.
sourcepub fn despawner<F: Fn(&mut World, EntityId) + Sync + Send + 'static>(
self,
handler: F
) -> Self
pub fn despawner<F: Fn(&mut World, EntityId) + Sync + Send + 'static>( self, handler: F ) -> Self
Set the function used to despawn the element.
sourcepub fn on_spawned<F: Fn(&mut World, EntityId, &str) + Sync + Send + 'static>(
self,
handler: F
) -> Self
pub fn on_spawned<F: Fn(&mut World, EntityId, &str) + Sync + Send + 'static>( self, handler: F ) -> Self
Set the callback to call when the element is spawned. The third argument is the instance ID.
sourcepub fn on_despawn<F: Fn(&mut World, EntityId, &str) + Sync + Send + 'static>(
self,
handler: F
) -> Self
pub fn on_despawn<F: Fn(&mut World, EntityId, &str) + Sync + Send + 'static>( self, handler: F ) -> Self
Set the callback to call when the element is despawned. The third argument is the instance ID.
sourcepub fn key<T: Into<String>>(self, key: T) -> Self
pub fn key<T: Into<String>>(self, key: T) -> Self
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>) -> Self
pub fn memoize_subtree(self, memo_key: impl Into<String>) -> Self
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);
});