EventHandler

Trait EventHandler 

Source
pub trait EventHandler {
    // Required methods
    fn update<'life0, 'life1, 'async_trait>(
        &'life0 self,
        game: &'life1 mut Game,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn draw<'life0, 'life1, 'async_trait>(
        &'life0 self,
        game: &'life1 mut Game,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn key_down_event(
        &self,
        _game: &mut Game,
        _timestamp: u64,
        _window_id: u32,
        _keycode: Option<Keycode>,
        _scancode: Option<Scancode>,
        _keymod: Mod,
        _repeat: bool,
        _which: u32,
        _raw: u16,
    ) -> Result<()> { ... }
    fn key_up_event(
        &self,
        _game: &mut Game,
        _timestamp: u64,
        _window_id: u32,
        _keycode: Option<Keycode>,
        _scancode: Option<Scancode>,
        _keymod: Mod,
        _repeat: bool,
        _which: u32,
        _raw: u16,
    ) -> Result<()> { ... }
    fn mouse_motion_event(
        &self,
        _game: &mut Game,
        _timestamp: u64,
        _window_id: u32,
        _which: u32,
        _mousestate: MouseState,
        _x: f32,
        _y: f32,
        _xrel: f32,
        _yrel: f32,
    ) -> Result<()> { ... }
    fn mouse_button_down_event(
        &self,
        _game: &mut Game,
        _timestamp: u64,
        _window_id: u32,
        _which: u32,
        _mouse_btn: MouseButton,
        _clicks: u8,
        _x: f32,
        _y: f32,
    ) -> Result<()> { ... }
    fn mouse_button_up_event(
        &self,
        _game: &mut Game,
        _timestamp: u64,
        _window_id: u32,
        _which: u32,
        _mouse_btn: MouseButton,
        _clicks: u8,
        _x: f32,
        _y: f32,
    ) -> Result<()> { ... }
    fn mouse_wheel_event(
        &self,
        _game: &mut Game,
        _timestamp: u64,
        _window_id: u32,
        _which: u32,
        _x: f32,
        _y: f32,
        _direction: MouseWheelDirection,
        _mouse_x: f32,
        _mouse_y: f32,
    ) -> Result<()> { ... }
}
Expand description

Trait that must be implemented by user’s game state struct

  • update is called to advance game state (physics, AI, input processing).
  • draw is called to render the current state using game.graphics.

Required Methods§

Source

fn update<'life0, 'life1, 'async_trait>( &'life0 self, game: &'life1 mut Game, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Updates the game state.

This method should contain the logic for updating the game state.

§Arguments
  • game - A mutable reference to the game state.
§Returns
  • Result<()> - () if everythings fine, otherwise you should return an error if something failed in your logics
Source

fn draw<'life0, 'life1, 'async_trait>( &'life0 self, game: &'life1 mut Game, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Draws the game

This method should contain the logic for drawing on the game’s canvas

§Arguments
  • game - A mutable reference to the game state.
§Returns
  • Result<()> - () if everythings fine, otherwise you should return an error if something failed in your logics

Provided Methods§

Source

fn key_down_event( &self, _game: &mut Game, _timestamp: u64, _window_id: u32, _keycode: Option<Keycode>, _scancode: Option<Scancode>, _keymod: Mod, _repeat: bool, _which: u32, _raw: u16, ) -> Result<()>

Handles a key‑down event.

§Parameters
  • game – Mutable Game reference.
  • timestamp – Event timestamp.
  • window_id – Window identifier.
  • keycode – Optional keycode of the pressed key.
  • scancode – Optional scancode of the pressed key.
Source

fn key_up_event( &self, _game: &mut Game, _timestamp: u64, _window_id: u32, _keycode: Option<Keycode>, _scancode: Option<Scancode>, _keymod: Mod, _repeat: bool, _which: u32, _raw: u16, ) -> Result<()>

Handles a key‑up event. Parameters mirror key_down_event

Source

fn mouse_motion_event( &self, _game: &mut Game, _timestamp: u64, _window_id: u32, _which: u32, _mousestate: MouseState, _x: f32, _y: f32, _xrel: f32, _yrel: f32, ) -> Result<()>

Handles mouse‑motion events.

§Parameters
  • game – Mutable Game reference.
  • timestamp – Event timestamp.
  • window_id – Window identifier.
  • x, y – Absolute cursor coordinates.
  • xrel, yrel – Relative motion since the previous event.
Source

fn mouse_button_down_event( &self, _game: &mut Game, _timestamp: u64, _window_id: u32, _which: u32, _mouse_btn: MouseButton, _clicks: u8, _x: f32, _y: f32, ) -> Result<()>

Handles a mouse‑button‑down event.

§Parameters
  • game – Mutable Game reference.
  • timestamp – Event timestamp.
  • window_id – Window identifier.
  • mouse_btn – Button that was pressed.
  • clicks – Number of consecutive clicks.
  • x, y – Cursor position at the time of the press.
Source

fn mouse_button_up_event( &self, _game: &mut Game, _timestamp: u64, _window_id: u32, _which: u32, _mouse_btn: MouseButton, _clicks: u8, _x: f32, _y: f32, ) -> Result<()>

Handles a mouse‑button‑up event. Parameters mirror mouse_button_down_event

Source

fn mouse_wheel_event( &self, _game: &mut Game, _timestamp: u64, _window_id: u32, _which: u32, _x: f32, _y: f32, _direction: MouseWheelDirection, _mouse_x: f32, _mouse_y: f32, ) -> Result<()>

Handles a mouse‑wheel (scroll) event.

§Parameters
  • game – Mutable Game reference.
  • timestamp – Event timestamp.
  • window_id – Window identifier.
  • x, y – Scroll amount along each axis.
  • direction – Scroll direction probably i don’t know.
  • mouse_x, mouse_y – Cursor position when the wheel event occurred.

Implementors§