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.

Both return anyhow::Result<()>

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,

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

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

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

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

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

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

Implementors§