Skip to main content

App

Struct App 

Source
pub struct App<'w, 's> { /* private fields */ }
Expand description

A Bevy SystemParam providing nannou’s application conveniences.

See the module documentation for an overview and example.

Implementations§

Source§

impl<'w, 's> App<'w, 's>

Source

pub fn time(&self) -> f32

The elapsed seconds since startup.

Source

pub fn time_delta(&self) -> f32

The elapsed seconds since the last frame.

Source

pub fn elapsed_frames(&self) -> u64

The number of update frames that have elapsed since the start of the program.

Source

pub fn fps(&self) -> f64

The smoothed frames-per-second as reported by Bevy’s frame-time diagnostics.

Returns 0.0 if the FPS diagnostic is unavailable (e.g. if FrameTimeDiagnosticsPlugin was not registered).

Source

pub fn keys(&self) -> ButtonInput<KeyCode>

The current input state for the keyboard.

Source

pub fn mouse_buttons(&self) -> ButtonInput<MouseButton>

The current input state for the mouse buttons.

Source

pub fn mouse(&self) -> Vec2

The current mouse position in points, relative to the centre of the focused window.

Source

pub fn window_id(&self) -> Entity

The Entity of the “current” window: the focused window, else the primary window, else a window created this call (but not yet spawned), else any open window.

Panics if there are no windows open.

Source

pub fn window_ids(&self) -> Vec<Entity>

The Entity for each currently open window.

Source

pub fn window_count(&self) -> usize

The number of windows currently open (including any created this call but not yet spawned).

Source

pub fn window_rect(&self) -> Rect<f32>

The geom::Rect of the currently focused window, in points.

Panics if there are no windows open.

Source

pub fn available_monitors(&self) -> Vec<(Entity, Monitor)>

The list of all monitors available on the system.

Source

pub fn primary_monitor(&self) -> Option<Entity>

The primary monitor of the system, if one can be detected.

Source

pub fn draw(&self) -> Draw

The Draw API for the window whose view is currently running, or the focused window.

Panics if there are no windows open.

Source

pub fn draw_for_window(&self, window: Entity) -> Draw

The Draw API for the given window.

Panics if the entity has no Draw component (e.g. it is not a nannou window).

Source

pub fn asset_server(&self) -> &AssetServer

A reference to the AssetServer for loading assets.

Source

pub fn image_assets(&self) -> &Assets<Image>

A reference to the Image assets, for reading texture data.

To add a new asset, use asset_server().add(..); for arbitrary asset types or mutable access, take the relevant Assets<T> parameter in your own Bevy system.

Source

pub fn modify_image( &self, handle: &Handle<Image>, f: impl FnOnce(&mut Image) + Send + 'static, )

Queue a mutation of the Image behind handle, applied via the deferred command queue.

A convenience for editing a texture from a classic update/view - e.g. overwriting its pixel data or swapping its sampler - without dropping to a custom Bevy system. Bevy re-uploads the image to its GPU texture on the next extract. The mutation lands after the current update/view returns, and f is skipped if the handle no longer resolves.

// Overwrite a texture's pixels each frame.
app.modify_image(&model.texture, move |image| image.data = Some(pixels));
Source

pub fn text_layout<'b>(&self, s: &'b str) -> Builder<'b>

Build a text layout for measurement or glyph extraction.

App-level equivalent of draw.text_layout().

Source

pub fn command_scope<R>(&self, f: impl FnOnce(Commands<'_, '_>) -> R) -> R

Run a closure with deferred Commands access, returning its result.

A convenience around ParallelCommands::command_scope for spawning entities or queueing world mutations from a shared &App. For example, spawn a camera bound to a window:

app.command_scope(|mut commands| {
    commands.spawn(render::NannouCamera::for_window(window));
});

Do not call another mutating App method (quit, new_window().build(), window(..).set_title(..), …) from inside the closure - they re-enter command_scope, which panics on the already-borrowed thread-local command queue. Use commands directly.

Source

pub fn quit(&self)

Quit the currently running application.

Source

pub fn set_update_mode(&self, mode: UpdateMode)

Set the update mode used while the window is both focused and unfocused.

See UpdateModeExt for convenient wait/freeze modes.

Source

pub fn set_unfocused_update_mode(&self, mode: UpdateMode)

Set the update mode used while the window is unfocused.

Source

pub fn set_focused_update_mode(&self, mode: UpdateMode)

Set the update mode used while the window is focused.

Source

pub fn set_update_rate(&self, hz: f64)

Drive updates at a fixed rate of hz ticks per second, while both focused and unfocused. Analogous to Processing’s frameRate(fps).

Convenience for set_update_mode(UpdateMode::rate(hz)). See UpdateModeExt::rate for the exact semantics.

Source

pub fn exe_name(&self) -> Result<String>

The name of the nannou executable that is currently running.

Source

pub fn project_path(&self) -> Result<PathBuf, Error>

The path to the current project directory (the directory containing Cargo.toml).

Source

pub fn assets_path(&self) -> PathBuf

The path to the assets directory.

Source

pub fn new_window<M: 'static>(&self) -> Builder<'_, 'w, 's, M>

Begin building a new window.

The returned window::Builder spawns the window along with a NannouCamera targeting it (so its Draw is rendered), and returns the window Entity from build.

Source

pub fn new_camera(&self) -> CameraBuilder<'_, 'w, 's>

Begin building a new NannouCamera.

Configure it with the SetCamera methods, then call build to spawn it and obtain its Entity.

Source

pub fn new_light(&self) -> LightBuilder<'_, 'w, 's>

Begin building a new directional light.

Configure it with the SetLight methods, then call build to spawn it and obtain its Entity.

Source

pub fn window(&self, entity: Entity) -> Window<'_, 'w, 's>

A handle for reading and updating the window with the given Entity.

Source

pub fn main_window(&self) -> Window<'_, 'w, 's>

A handle for reading and updating the app’s main window.

This is the window explicitly marked primary (see Builder::primary) if there is one, including a primary window created this call but not yet spawned. Otherwise it falls back to the current window (see window_id), so a single window is treated as the main window without needing to be marked primary.

Panics if there are no windows open.

Trait Implementations§

Source§

impl<'w, 's> ReadOnlySystemParam for App<'w, 's>

Source§

impl SystemParam for App<'_, '_>

Source§

type State = FetchState

Used to store data which persists across invocations of a system.
Source§

type Item<'w, 's> = App<'w, 's>

The item type returned when constructing this system param. The value of this associated type should be Self, instantiated with new lifetimes. Read more
Source§

fn init_state(world: &mut World) -> Self::State

Creates a new instance of this param’s State.
Source§

fn init_access( state: &Self::State, system_meta: &mut SystemMeta, component_access_set: &mut FilteredAccessSet, world: &mut World, )

Registers any World access used by this SystemParam. Read more
Source§

fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)

Applies any deferred mutations stored in this SystemParam’s state. This is used to apply Commands during ApplyDeferred.
Source§

fn queue( state: &mut Self::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )

Queues any deferred mutations to be applied at the next ApplyDeferred.
Source§

unsafe fn get_param<'w, 's>( state: &'s mut Self::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> Result<Self::Item<'w, 's>, SystemParamValidationError>

Creates a parameter to be passed into a SystemParamFunction. Read more

Auto Trait Implementations§

§

impl<'w, 's> !RefUnwindSafe for App<'w, 's>

§

impl<'w, 's> !Sync for App<'w, 's>

§

impl<'w, 's> !UnwindSafe for App<'w, 's>

§

impl<'w, 's> Freeze for App<'w, 's>

§

impl<'w, 's> Send for App<'w, 's>

§

impl<'w, 's> Unpin for App<'w, 's>

§

impl<'w, 's> UnsafeUnpin for App<'w, 's>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

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

Source§

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

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

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

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

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

Converts &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)

Converts &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 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<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. 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<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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