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>
impl<'w, 's> App<'w, 's>
Sourcepub fn time_delta(&self) -> f32
pub fn time_delta(&self) -> f32
The elapsed seconds since the last frame.
Sourcepub fn elapsed_frames(&self) -> u64
pub fn elapsed_frames(&self) -> u64
The number of update frames that have elapsed since the start of the program.
Sourcepub fn fps(&self) -> f64
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).
Sourcepub fn keys(&self) -> ButtonInput<KeyCode>
pub fn keys(&self) -> ButtonInput<KeyCode>
The current input state for the keyboard.
The current input state for the mouse buttons.
Sourcepub fn mouse(&self) -> Vec2
pub fn mouse(&self) -> Vec2
The current mouse position in points, relative to the centre of the focused window.
Sourcepub fn window_id(&self) -> Entity
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.
Sourcepub fn window_ids(&self) -> Vec<Entity>
pub fn window_ids(&self) -> Vec<Entity>
The Entity for each currently open window.
Sourcepub fn window_count(&self) -> usize
pub fn window_count(&self) -> usize
The number of windows currently open (including any created this call but not yet spawned).
Sourcepub fn window_rect(&self) -> Rect<f32>
pub fn window_rect(&self) -> Rect<f32>
The geom::Rect of the currently focused window, in points.
Panics if there are no windows open.
Sourcepub fn available_monitors(&self) -> Vec<(Entity, Monitor)>
pub fn available_monitors(&self) -> Vec<(Entity, Monitor)>
The list of all monitors available on the system.
Sourcepub fn primary_monitor(&self) -> Option<Entity>
pub fn primary_monitor(&self) -> Option<Entity>
The primary monitor of the system, if one can be detected.
Sourcepub fn draw(&self) -> Draw
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.
Sourcepub fn draw_for_window(&self, window: Entity) -> Draw
pub fn draw_for_window(&self, window: Entity) -> Draw
Sourcepub fn asset_server(&self) -> &AssetServer
pub fn asset_server(&self) -> &AssetServer
A reference to the AssetServer for loading assets.
Sourcepub fn image_assets(&self) -> &Assets<Image>
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.
Sourcepub fn modify_image(
&self,
handle: &Handle<Image>,
f: impl FnOnce(&mut Image) + Send + 'static,
)
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));Sourcepub fn text_layout<'b>(&self, s: &'b str) -> Builder<'b>
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().
Sourcepub fn command_scope<R>(&self, f: impl FnOnce(Commands<'_, '_>) -> R) -> R
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.
Sourcepub fn set_update_mode(&self, mode: UpdateMode)
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.
Sourcepub fn set_unfocused_update_mode(&self, mode: UpdateMode)
pub fn set_unfocused_update_mode(&self, mode: UpdateMode)
Set the update mode used while the window is unfocused.
Sourcepub fn set_focused_update_mode(&self, mode: UpdateMode)
pub fn set_focused_update_mode(&self, mode: UpdateMode)
Set the update mode used while the window is focused.
Sourcepub fn set_update_rate(&self, hz: f64)
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.
Sourcepub fn exe_name(&self) -> Result<String>
pub fn exe_name(&self) -> Result<String>
The name of the nannou executable that is currently running.
Sourcepub fn project_path(&self) -> Result<PathBuf, Error>
pub fn project_path(&self) -> Result<PathBuf, Error>
The path to the current project directory (the directory containing Cargo.toml).
Sourcepub fn assets_path(&self) -> PathBuf
pub fn assets_path(&self) -> PathBuf
The path to the assets directory.
Sourcepub fn new_window<M: 'static>(&self) -> Builder<'_, 'w, 's, M>
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.
Sourcepub fn new_camera(&self) -> CameraBuilder<'_, 'w, 's>
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.
Sourcepub fn new_light(&self) -> LightBuilder<'_, 'w, 's>
pub fn new_light(&self) -> LightBuilder<'_, 'w, 's>
Sourcepub fn window(&self, entity: Entity) -> Window<'_, 'w, 's>
pub fn window(&self, entity: Entity) -> Window<'_, 'w, 's>
A handle for reading and updating the window with the given Entity.
Sourcepub fn main_window(&self) -> Window<'_, 'w, 's>
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§
impl<'w, 's> ReadOnlySystemParam for App<'w, 's>where
ParallelCommands<'w, 's>: ReadOnlySystemParam,
Res<'w, Time>: ReadOnlySystemParam,
Res<'w, FrameCount>: ReadOnlySystemParam,
Option<Res<'w, DiagnosticsStore>>: ReadOnlySystemParam,
Res<'w, ButtonInput<KeyCode>>: ReadOnlySystemParam,
Res<'w, ButtonInput<MouseButton>>: ReadOnlySystemParam,
Query<'w, 's, (Entity, &'static Window)>: ReadOnlySystemParam,
Query<'w, 's, Entity, With<PrimaryWindow>>: ReadOnlySystemParam,
Query<'w, 's, &'static Draw>: ReadOnlySystemParam,
Query<'w, 's, (Entity, &'static Monitor)>: ReadOnlySystemParam,
Query<'w, 's, Entity, With<PrimaryMonitor>>: ReadOnlySystemParam,
Query<'w, 's, (&'static RenderTarget, &'static Msaa), With<NannouCamera>>: ReadOnlySystemParam,
Res<'w, AssetServer>: ReadOnlySystemParam,
Res<'w, Assets<Image>>: ReadOnlySystemParam,
Res<'w, SharedTextCx>: ReadOnlySystemParam,
Option<Res<'w, RenderDevice>>: ReadOnlySystemParam,
Option<Res<'w, RenderQueue>>: ReadOnlySystemParam,
Local<'s, Cell<Option<Entity>>>: ReadOnlySystemParam,
Local<'s, RefCell<Vec<(Entity, bool, Window)>>>: ReadOnlySystemParam,
Source§impl SystemParam for App<'_, '_>
impl SystemParam for App<'_, '_>
Source§type Item<'w, 's> = App<'w, 's>
type Item<'w, 's> = App<'w, 's>
Self, instantiated with new lifetimes. Read moreSource§fn init_access(
state: &Self::State,
system_meta: &mut SystemMeta,
component_access_set: &mut FilteredAccessSet,
world: &mut World,
)
fn init_access( state: &Self::State, system_meta: &mut SystemMeta, component_access_set: &mut FilteredAccessSet, world: &mut World, )
Source§fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
SystemParam’s state.
This is used to apply Commands during ApplyDeferred.Source§fn queue(
state: &mut Self::State,
system_meta: &SystemMeta,
world: DeferredWorld<'_>,
)
fn queue( state: &mut Self::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )
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>
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>
SystemParamFunction. Read moreAuto 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, 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ConditionalSend for Twhere
T: Send,
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>, which can then be
downcast into Box<dyn 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>, which 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.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.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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