Struct nannou::app::App

source ·
pub struct App {
    pub mouse: Mouse,
    pub keys: Keys,
    pub duration: Time,
    pub time: f32,
    /* private fields */
}
Expand description

Each nannou application has a single App instance. This App represents the entire context of the application.

The App provides access to most application, windowing and “IO” related APIs. In other words, if you need access to windowing, the active wgpu devices, etc, the App will provide access to this.

The App owns and manages:

  • The window and input event loop used to drive the application forward.
  • All windows for graphics and user input. Windows can be referenced via their IDs.
  • The sharing of wgpu devices between windows.
  • A default Draw instance for ease of use.
  • A map of channels for submitting user input updates to active Uis.

Fields§

§mouse: Mouse

The current state of the Mouse.

§keys: Keys

State of the keyboard keys.

mods provides state of each of the modifier keys: shift, ctrl, alt, logo.

down is the set of keys that are currently pressed.

NOTE: down this is tracked by the nannou App so issues might occur if e.g. a key is pressed while the app is in focus and then released when out of focus. Eventually we should change this to query the OS somehow, but I don’t think winit provides a way to do this yet.

§duration: Time

Key time measurements tracked by the App.

duration.since_start specifies the duration since the app started running.

duration.since_prev_update specifies the duration since the previous update event.

§time: f32

The time in seconds since the App started running.

Primarily, this field is a convenience that removes the need to call app.duration.since_start.secs(). Normally we would try to avoid using such an ambiguous field name, however due to the sheer amount of use that this value has we feel it is beneficial to provide easier access.

This value is of the same type as the scalar value used for describing space in animations. This makes it very easy to animate graphics and create changes over time without having to cast values or repeatedly calculate it from a Duration type. A small example might be app.time.sin() for simple oscillation behaviour.

Note: This is suitable for use in short sketches, however should be avoided in long running installations. This is because the “resolution” of floating point values reduces as the number becomes higher. Instead, we recommend using app.duration.since_start or app.duration.since_prev_update to access a more precise form of app time.

Implementations§

source§

impl App

source

pub const ASSETS_DIRECTORY_NAME: &'static str = "assets"

source

pub const DEFAULT_EXIT_ON_ESCAPE: bool = true

source

pub const DEFAULT_FULLSCREEN_ON_SHORTCUT: bool = true

source

pub fn available_monitors(&self) -> Vec<MonitorHandle>

Returns the list of all the monitors available on the system.

source

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

Returns the primary monitor of the system. May return None if none can be detected. For example, this can happen when running on Linux with Wayland.

source

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

Find and return the absolute path to the project’s assets directory.

This method looks for the assets directory in the following order:

  1. Checks the same directory as the executable.
  2. Recursively checks exe’s parent directories (to a max depth of 5).
  3. Recursively checks exe’s children directories (to a max depth of 3).
source

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

The path to the current project directory.

The current project directory is considered to be the directory containing the cargo manifest (aka the Cargo.toml file).

Note: Be careful not to rely on this directory for apps or sketches that you wish to distribute! This directory is mostly useful for local sketches, experiments and testing.

source

pub fn new_window(&self) -> Builder<'_>

Begin building a new window.

source

pub fn window_count(&self) -> usize

The number of windows currently in the application.

source

pub fn window(&self, id: Id) -> Option<Ref<'_, Window>>

A reference to the window with the given Id.

source

pub fn window_id(&self) -> Id

Return the Id of the currently focused window.

Panics if there are no windows or if no window is in focus.

source

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

Return a Vec containing a unique window::Id for each currently open window managed by the App.

source

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

Return the Rect for the currently focused window.

The Rect coords are described in “points” (pixels divided by the hidpi factor).

Panics if there are no windows or if no window is in focus.

source

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

A reference to the window currently in focus.

Panics if their are no windows open in the App.

Uses the App::window method internally.

TODO: Currently this produces a reference to the focused window, but this behaviour should be changed to track the “main” window (the first window created?).

source

pub fn backends(&self) -> Backends

Return the wgpu Backends in use.

source

pub fn instance(&self) -> &Instance

Return the main wgpu Instance in use.

This must be passed into the various methods on AdapterMap.

source

pub fn wgpu_adapters(&self) -> &AdapterMap

Access to the App’s inner map of wgpu adapters representing access to physical GPU devices.

By maintaining a map of active adapters and their established devices, nannou allows for devices to be shared based on the desired RequestAdapterOptions and DeviceDescriptors.

For example, when creating new windows with the same set of RequestAdapterOptions and DeviceDescriptors, nannou will automatically share devices between windows where possible. This allows for sharing GPU resources like Textures and Buffers between windows.

All methods on AdapterMap that take a wgpu::Instance must be passed the main instance in use by the app, accessed via App::instance().

source

pub fn exit_on_escape(&self) -> bool

Return whether or not the App is currently set to exit when the Escape key is pressed.

source

pub fn set_exit_on_escape(&self, b: bool)

Specify whether or not the app should close when the Escape key is pressed.

By default this is true.

source

pub fn fullscreen_on_shortcut(&self) -> bool

Returns whether or not the App is currently allows the focused window to enter or exit fullscreen via typical platform-specific shortcuts.

  • Linux uses F11.
  • macOS uses apple key + f.
  • Windows uses windows key + f.
source

pub fn set_fullscreen_on_shortcut(&self, b: bool)

Set whether or not the App should allow the focused window to enter or exit fullscreen via typical platform-specific shortcuts.

  • Linux uses F11.
  • macOS uses apple key + f.
  • Windows uses windows key + f.
source

pub fn loop_mode(&self) -> LoopMode

Returns the App’s current LoopMode.

The default loop mode is LoopMode::RefreshSync.

source

pub fn set_loop_mode(&self, mode: LoopMode)

Sets the loop mode of the App.

Note: Setting the loop mode will not affect anything until the end of the current loop iteration. The behaviour of a single loop iteration is described under each of the LoopMode variants.

source

pub fn create_proxy(&self) -> Proxy

A handle to the App that can be shared across threads.

This can be used to “wake up” the App’s inner event loop.

source

pub fn draw(&self) -> Draw

Produce the App’s Draw API for drawing geometry and text with colors and textures.

Note: You can also create your own Draw instances via Draw::new()! This method makes it a tiny bit easier as the App stores the Draw instance for you and automatically resets the state on each call to app.draw().

source

pub fn elapsed_frames(&self) -> u64

The number of times the focused window’s view function has been called since the start of the program.

source

pub fn fps(&self) -> f32

The number of frames that can currently be displayed a second

source

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

The name of the nannou executable that is currently running.

source

pub fn quit(&self)

Quits the currently running application.

Trait Implementations§

source§

impl<'a> WithDeviceQueuePair for &'a App

source§

fn with_device_queue_pair<F, O>(self, f: F) -> O
where F: FnOnce(&Device, &Queue) -> O,

Auto Trait Implementations§

§

impl !RefUnwindSafe for App

§

impl !Send for App

§

impl !Sync for App

§

impl Unpin for App

§

impl !UnwindSafe for App

Blanket Implementations§

source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Component + Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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> 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, U> ConvertInto<U> for T
where U: ConvertFrom<T>,

source§

fn convert_into(self) -> U

Convert into T with values clamped to the color defined bounds Read more
source§

fn convert_unclamped_into(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
source§

fn try_convert_into(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

impl<T> Upcast<T> for T

§

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

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V