pub struct Cx<'p, 'w> { /* private fields */ }Expand description
A context parameter that is passed to views and callbacks. It contains the reactive tracking scope, which is used to manage reactive dependencies, as well as a reference to the Bevy world.
Implementations§
Source§impl<'p, 'w> Cx<'p, 'w>
impl<'p, 'w> Cx<'p, 'w>
Sourcepub fn new(
world: &'w mut World,
owner: Entity,
tracking: &'p mut TrackingScope,
) -> Cx<'p, 'w>
pub fn new( world: &'w mut World, owner: Entity, tracking: &'p mut TrackingScope, ) -> Cx<'p, 'w>
Construct a new reactive context.
Sourcepub fn create_entity(&mut self) -> Entity
pub fn create_entity(&mut self) -> Entity
Spawn an empty Entity. The entity will be despawned when the tracking scope is dropped.
Sourcepub fn create_mutable<T>(&mut self, init: T) -> Mutable<T>
pub fn create_mutable<T>(&mut self, init: T) -> Mutable<T>
Create a new Mutable in this context.
Sourcepub fn create_effect<S, D>(&mut self, effect_fn: S, deps: D)
pub fn create_effect<S, D>(&mut self, effect_fn: S, deps: D)
Create an effect which runs each time the reactive context is executed, and the given dependencies change.
Arguments:
effect_fn: The effect function to run.deps: The dependencies which trigger the effect.
Sourcepub fn create_effect_ext<S, D>(
&mut self,
effect_fn: S,
deps: D,
options: EffectOptions,
)
pub fn create_effect_ext<S, D>( &mut self, effect_fn: S, deps: D, options: EffectOptions, )
Create an effect which runs each time the reactive context is executed, and the given dependencies change. This version takes additional options.
Arguments:
effect_fn: The effect function to run.deps: The dependencies which trigger the effect.options: Additional options for running the effect.
Sourcepub fn create_memo<R, S, D>(&mut self, factory_fn: S, deps: D) -> R
pub fn create_memo<R, S, D>(&mut self, factory_fn: S, deps: D) -> R
Create a memoized value which is only recomputed when dependencies change.
Arguments:
factory_fn: The factory function which computes the memoized value.deps: The dependencies which trigger the effect.
Sourcepub fn create_memo_cmp<R, S, C, D>(
&mut self,
factory_fn: S,
cmp: C,
deps: D,
) -> R
pub fn create_memo_cmp<R, S, C, D>( &mut self, factory_fn: S, cmp: C, deps: D, ) -> R
Create a memoized value which is only recomputed when dependencies change. This version uses a user-supplied comparison function to determine if the dependencies have changed.
Arguments:
factory_fn: The factory function which computes the memoized value.deps: The dependencies which trigger the effect.
Sourcepub fn create_callback<P, M, S>(&mut self, callback: S) -> Callback<P>
pub fn create_callback<P, M, S>(&mut self, callback: S) -> Callback<P>
Create a new callback in this context. This registers a one-shot system with the world. The callback will be unregistered when the tracking scope is dropped.
Note: This function takes no deps argument, the callback is only registered once the first time it is called. Subsequent calls will return the original callback.
Sourcepub fn create_capture<T>(&mut self, init: T) -> Mutable<T>
pub fn create_capture<T>(&mut self, init: T) -> Mutable<T>
Temporary hook used to create a new Mutable which is automatically updated
each time this hook is called. This is used for now until we get replaceable one-shot systems.
You cannot create multiple captures of the same type within a single tracking scope.
Sourcepub fn insert(&mut self, component: impl Component)
pub fn insert(&mut self, component: impl Component)
Insert a component on the owner entity of the current context. This component can
be accessed by this context any any child contexts via [use_inherited_component].
Sourcepub fn use_resource<T>(&self) -> &Twhere
T: Resource,
pub fn use_resource<T>(&self) -> &Twhere
T: Resource,
Return a reference to the resource of the given type. Calling this function adds the resource as a dependency of the current presenter invocation.
Sourcepub fn use_resource_untracked<T>(&self) -> &Twhere
T: Resource,
pub fn use_resource_untracked<T>(&self) -> &Twhere
T: Resource,
Return a reference to the resource of the given type. Calling this function does not add the resource as a dependency of the current presenter invocation.
Sourcepub fn use_component<C>(&self, entity: Entity) -> Option<&C>where
C: Component,
pub fn use_component<C>(&self, entity: Entity) -> Option<&C>where
C: Component,
Return a reference to the Component C on the given entity.
Sourcepub fn use_component_untracked<C>(&self, entity: Entity) -> Option<&C>where
C: Component,
pub fn use_component_untracked<C>(&self, entity: Entity) -> Option<&C>where
C: Component,
Return a reference to the Component C on the given entity. This version does not
add the component to the tracking scope, and is intended for components that update
frequently.
Sourcepub fn use_inherited_component<C>(&self) -> Option<&C>where
C: Component,
pub fn use_inherited_component<C>(&self) -> Option<&C>where
C: Component,
Return a reference to the Component C on the owner entity of the current
context, or one of it’s ancestors. This searches up the entity tree until it finds
a component of the given type. If found, the component is added to the current tracking
scope.
Sourcepub fn on_cleanup(
&mut self,
cleanup: impl FnOnce(&mut DeferredWorld<'_>) + Send + Sync + 'static,
)
pub fn on_cleanup( &mut self, cleanup: impl FnOnce(&mut DeferredWorld<'_>) + Send + Sync + 'static, )
Add a cleanup function which is run once before the next reaction, or when the owner entity for this context is despawned.
Trait Implementations§
Source§impl<'p, 'w> ReadMutable for Cx<'p, 'w>
impl<'p, 'w> ReadMutable for Cx<'p, 'w>
Source§fn read_mutable<T>(&self, mutable: &Mutable<T>) -> T
fn read_mutable<T>(&self, mutable: &Mutable<T>) -> T
Source§fn read_mutable_clone<T>(&self, mutable: &Mutable<T>) -> T
fn read_mutable_clone<T>(&self, mutable: &Mutable<T>) -> T
Source§fn read_mutable_as_ref<T>(&self, mutable: &Mutable<T>) -> &T
fn read_mutable_as_ref<T>(&self, mutable: &Mutable<T>) -> &T
Source§impl<'p, 'w> RunCallback for Cx<'p, 'w>
impl<'p, 'w> RunCallback for Cx<'p, 'w>
fn run_callback<P>(&mut self, callback: Callback<P>, props: P)where
P: 'static,
Source§impl<'p, 'w> WriteMutable for Cx<'p, 'w>
impl<'p, 'w> WriteMutable for Cx<'p, 'w>
Source§fn write_mutable<T>(&mut self, mutable: Entity, value: T)
fn write_mutable<T>(&mut self, mutable: Entity, value: T)
Source§fn write_mutable_clone<T>(&mut self, mutable: Entity, value: T)
fn write_mutable_clone<T>(&mut self, mutable: Entity, value: T)
Auto Trait Implementations§
impl<'p, 'w> !Freeze for Cx<'p, 'w>
impl<'p, 'w> !RefUnwindSafe for Cx<'p, 'w>
impl<'p, 'w> Send for Cx<'p, 'w>
impl<'p, 'w> !Sync for Cx<'p, 'w>
impl<'p, 'w> Unpin for Cx<'p, 'w>
impl<'p, 'w> !UnwindSafe for Cx<'p, 'w>
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.