App

Trait App 

Source
pub trait App {
    type Args: Sized + Parser;

    // Required method
    fn new(window: &mut Window, args: &Self::Args) -> Result<Self>
       where Self: Sized;

    // Provided methods
    fn handle_window_event(
        &mut self,
        window: &mut Window,
        event: WindowEvent,
    ) -> Result<AppState> { ... }
    fn handle_device_event(
        &mut self,
        window: &mut Window,
        event: DeviceEvent,
    ) -> Result<AppState> { ... }
    fn update(&mut self, window: &mut Window) -> Result<AppState> { ... }
}
Expand description

Implementations of this trait can be run with app_main to manage a Winit window.

Required Associated Types§

Required Methods§

Source

fn new(window: &mut Window, args: &Self::Args) -> Result<Self>
where Self: Sized,

Creates a new instance of the application. The application is allowed to modify the window based on its own requirements. This includes modifying the polling state, fullscreen status, size, etc…

Note: the window is not visible when initially created, the app must choose when to make it visible for the first time.

Provided Methods§

Source

fn handle_window_event( &mut self, window: &mut Window, event: WindowEvent, ) -> Result<AppState>

Handles a single WindowEvent.

Source

fn handle_device_event( &mut self, window: &mut Window, event: DeviceEvent, ) -> Result<AppState>

Handles a single DeviceEvent.

Source

fn update(&mut self, window: &mut Window) -> Result<AppState>

Called in a loop when no other events are pending or when the OS requests a new frame for the window.

This is a good place for rendering logic. This method blocks event processing, so it should be kept as responsive as possible.

Implementors§