[][src]Struct nannou::app::App

pub struct App {
    pub audio: Audio,
    pub mouse: Mouse,
    pub keys: Keys,
    pub duration: Time,
    pub time: DrawScalar,
    // some fields omitted
}

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

The App provides access to most "IO" related APIs. In other words, if you need access to windowing, audio devices, laser fixtures, 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 audio event loop from which you can receive or send audio via streams.

Fields

audio: Audio

The App's audio-related API.

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: DrawScalar

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.

Methods

impl App[src]

pub const ASSETS_DIRECTORY_NAME: &'static str[src]

pub const DEFAULT_EXIT_ON_ESCAPE: bool[src]

pub const DEFAULT_FULLSCREEN_ON_SHORTCUT: bool[src]

pub fn vk_instance(&self) -> &Arc<Instance>[src]

A reference to the vulkan instance associated with the App.

If you would like to construct the app with a custom vulkan instance, see the app::Builder::vk_instance method.

Important traits for PhysicalDevicesIter<'a>
pub fn vk_physical_devices(&self) -> PhysicalDevicesIter[src]

Returns an iterator yielding each of the physical devices on the system that are vulkan compatible.

If a physical device is not specified for a window surface's swapchain, the first device yielded by this iterator is used as the default.

pub fn default_vk_physical_device(&self) -> Option<PhysicalDevice>[src]

Retrieve the default vulkan physical device.

This is simply the first device yielded by the vk_physical_devices method.

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

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

pub fn new_window(&self) -> Builder[src]

Begin building a new OpenGL window.

pub fn window_count(&self) -> usize[src]

The number of windows currently in the application.

pub fn window(&self, id: Id) -> Option<Ref<Window>>[src]

A reference to the window with the given Id.

pub fn window_id(&self) -> Id[src]

Return the Id of the currently focused window.

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

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

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

pub fn window_rect(&self) -> Rect<DrawScalar>[src]

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.

pub fn main_window(&self) -> Ref<Window>[src]

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?).

pub fn exit_on_escape(&self) -> bool[src]

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

pub fn set_exit_on_escape(&self, b: bool)[src]

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

By default this is true.

pub fn fullscreen_on_shortcut(&self) -> bool[src]

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.

pub fn set_fullscreen_on_shortcut(&self, b: bool)[src]

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.

pub fn loop_mode(&self) -> LoopMode[src]

Returns the App's current LoopMode.

The default loop mode is Rate at 60 frames per second (an update_interval of ~16ms).

pub fn set_loop_mode(&self, mode: LoopMode)[src]

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.

pub fn create_proxy(&self) -> Proxy[src]

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

This can be used to "wake up" the App's inner event loop.

pub fn new_ui(&self) -> Builder[src]

A builder for creating a new Ui.

Each Ui is associated with one specific window. By default, this is the window returned by App::window_id (the currently focused window).

pub fn draw_for_window(&self, window_id: Id) -> Option<Draw>[src]

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

Note: There may only be a single app::Draw instance at any point in time. If this method is called while there is a pre-existing instance of app::Draw this method will panic.

Returns None if there is no window for the given window::Id.

pub fn draw(&self) -> Draw[src]

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

This is a simplified wrapper around the App::draw_for_window method that draws to the window currently in focus.

Panics if there are no windows open.

Note: There may only be a single app::Draw instance at any point in time. If this method is called while there is a pre-existing instance of app::Draw this method will panic.

pub fn elapsed_frames(&self) -> u64[src]

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

Auto Trait Implementations

impl !Send for App

impl !Sync for App

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Content for T[src]

impl<T> SafeBorrow<T> for T[src]

impl<S> FromSample<S> for S[src]

impl<T, U> ToSample<U> for T where
    U: FromSample<T>, 
[src]

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

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.