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
updateis called to advance game state (physics, AI, input processing).drawis called to render the current state usinggame.graphics.
Required Methods§
Sourcefn 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 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,
Provided Methods§
Sourcefn 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_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– MutableGamereference.timestamp– Event timestamp.window_id– Window identifier.keycode– Optional keycode of the pressed key.scancode– Optional scancode of the pressed key.
Sourcefn 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 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
Sourcefn 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_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– MutableGamereference.timestamp– Event timestamp.window_id– Window identifier.x,y– Absolute cursor coordinates.xrel,yrel– Relative motion since the previous event.
Handles a mouse‑button‑down event.
§Parameters
game– MutableGamereference.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.
Handles a mouse‑button‑up event. Parameters mirror
mouse_button_down_event
Sourcefn 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<()>
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– MutableGamereference.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.