Skip to main content

AppHandler

Trait AppHandler 

Source
pub trait AppHandler: Sized + 'static {
    // Required method
    fn init(engine: &mut Engine, window: &dyn Window) -> Self;

    // Provided methods
    fn on_event(
        &mut self,
        engine: &mut Engine,
        window: &dyn Window,
        event: &(dyn Any + 'static),
    ) -> bool { ... }
    fn update(
        &mut self,
        engine: &mut Engine,
        window: &dyn Window,
        frame: &FrameState,
    ) { ... }
    fn compose_frame<'a>(&'a mut self, composer: FrameComposer<'a>) { ... }
}
Expand description

Trait for defining application behavior.

Implement this trait to create your application. The framework will call these methods at appropriate times during the application lifecycle.

§Lifecycle

  1. init - Called once when the window and renderer are ready
  2. update - Called each frame before rendering
  3. compose_frame - Called to configure the render pipeline

§Input Handling

Use engine.input to query input state in update. This is the standard game development paradigm and works across all backends.

For advanced use cases that require raw platform events (e.g., integrating an external UI framework like egui), use on_event. The concrete event type depends on the backend; with winit it is winit::event::WindowEvent. Downcast via event.downcast_ref::<T>().

Required Methods§

Source

fn init(engine: &mut Engine, window: &dyn Window) -> Self

Initializes the application.

Called once after the window is created and the renderer is initialized. Use this to set up your scene, load assets, and prepare the initial state.

Provided Methods§

Source

fn on_event( &mut self, engine: &mut Engine, window: &dyn Window, event: &(dyn Any + 'static), ) -> bool

Handles raw platform events (advanced use only).

Most applications should use engine.input in update instead.

When using the winit backend, event is winit::event::WindowEvent. Access it via event.downcast_ref::<winit::event::WindowEvent>().

Return true to consume the event (preventing default input processing), or false to allow normal engine input handling.

Source

fn update( &mut self, engine: &mut Engine, window: &dyn Window, frame: &FrameState, )

Updates application state.

Called once per frame before rendering. Use this for game logic, animations, physics updates, etc.

Source

fn compose_frame<'a>(&'a mut self, composer: FrameComposer<'a>)

Configures the render pipeline for this frame.

Override this method to add custom render passes (UI, post-processing, etc.) via the hook-based API. The default implementation only renders the built-in pipeline (BasicForward or HighFidelity depending on RenderPath).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§