Struct Cx

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

Source

pub fn new( world: &'w mut World, owner: Entity, tracking: &'p mut TrackingScope, ) -> Cx<'p, 'w>

Construct a new reactive context.

Source

pub fn world(&self) -> &World

Access to world from reactive context.

Source

pub fn world_mut(&mut self) -> &mut World

Access to mutable world from reactive context.

Source

pub fn owner(&self) -> Entity

Returns the id of the entity that owns the tracking scope.

Source

pub fn create_entity(&mut self) -> Entity

Spawn an empty Entity. The entity will be despawned when the tracking scope is dropped.

Source

pub fn create_mutable<T>(&mut self, init: T) -> Mutable<T>
where T: Send + Sync + 'static,

Create a new Mutable in this context.

Source

pub fn create_effect<S, D>(&mut self, effect_fn: S, deps: D)
where S: Fn(&mut World, D) + Send + Sync, D: PartialEq + Clone + Send + Sync + 'static,

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

pub fn create_effect_ext<S, D>( &mut self, effect_fn: S, deps: D, options: EffectOptions, )
where S: Fn(&mut World, D) + Send + Sync, D: PartialEq + Clone + Send + Sync + 'static,

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

pub fn create_memo<R, S, D>(&mut self, factory_fn: S, deps: D) -> R
where R: Clone + Send + Sync + 'static, S: Fn(&mut World, D) -> R + Send + Sync, D: PartialEq + Clone + Send + Sync + 'static,

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

pub fn create_memo_cmp<R, S, C, D>( &mut self, factory_fn: S, cmp: C, deps: D, ) -> R
where R: Clone + Send + Sync + 'static, S: Fn(&mut Cx<'_, '_>, D) -> R + Send + Sync, C: Fn(&D, &D) -> bool, D: Clone + Send + Sync + 'static,

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

pub fn create_callback<P, M, S>(&mut self, callback: S) -> Callback<P>
where P: Send + Sync + 'static, S: IntoSystem<P, (), M> + 'static,

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.

Source

pub fn create_capture<T>(&mut self, init: T) -> Mutable<T>
where T: Clone + PartialEq + Send + Sync + 'static,

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.

Source

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].

Source

pub fn use_resource<T>(&self) -> &T
where 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.

Source

pub fn use_resource_untracked<T>(&self) -> &T
where 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.

Source

pub fn use_component<C>(&self, entity: Entity) -> Option<&C>
where C: Component,

Return a reference to the Component C on the given entity.

Source

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.

Source

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.

Source

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>

Source§

fn read_mutable<T>(&self, mutable: &Mutable<T>) -> T
where T: Send + Sync + Copy + 'static,

Read the value of a mutable variable using Copy semantics. Calling this function adds the mutable to the current tracking scope.
Source§

fn read_mutable_clone<T>(&self, mutable: &Mutable<T>) -> T
where T: Send + Sync + Clone + 'static,

Read the value of a mutable variable using Clone semantics. Calling this function adds the mutable to the current tracking scope.
Source§

fn read_mutable_as_ref<T>(&self, mutable: &Mutable<T>) -> &T
where T: Send + Sync + 'static,

Return an immutable reference to the mutable variable.
Source§

fn read_mutable_map<T, U, F>(&self, mutable: &Mutable<T>, f: F) -> U
where F: Fn(&T) -> U, T: Send + Sync + 'static,

Read the value of a mutable variable using a mapping function.
Source§

impl<'p, 'w> RunCallback for Cx<'p, 'w>

Source§

fn run_callback<P>(&mut self, callback: Callback<P>, props: P)
where P: 'static,

Source§

impl<'p, 'w> WriteMutable for Cx<'p, 'w>

Source§

fn write_mutable<T>(&mut self, mutable: Entity, value: T)
where T: Send + Sync + Copy + PartialEq + 'static,

Write the value of a mutable variable using Copy semantics. Does nothing if the value being set matches the existing value.
Source§

fn write_mutable_clone<T>(&mut self, mutable: Entity, value: T)
where T: Send + Sync + Clone + PartialEq + 'static,

Write the value of a mutable variable using Clone semantics. Does nothing if the value being set matches the existing value.
Source§

fn update_mutable<T, F>(&mut self, mutable: Entity, updater: F)
where F: FnOnce(Mut<'_, T>), T: Send + Sync + 'static,

Update a mutable value in place using a callback. The callback is passed a Mut<T> which can be used to modify the value.

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

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> ConditionalSend for T
where T: Send,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> WasmNotSend for T
where T: Send,