Trait EventHandler
pub trait EventHandler {
Show 16 methods
// Required methods
fn update(&mut self);
fn draw(&mut self);
// Provided methods
fn resize_event(&mut self, _width: f32, _height: f32) { ... }
fn mouse_motion_event(&mut self, _x: f32, _y: f32) { ... }
fn mouse_wheel_event(&mut self, _x: f32, _y: f32) { ... }
fn mouse_button_down_event(
&mut self,
_button: MouseButton,
_x: f32,
_y: f32,
) { ... }
fn mouse_button_up_event(&mut self, _button: MouseButton, _x: f32, _y: f32) { ... }
fn char_event(&mut self, _character: char, _keymods: KeyMods, _repeat: bool) { ... }
fn key_down_event(
&mut self,
_keycode: KeyCode,
_keymods: KeyMods,
_repeat: bool,
) { ... }
fn key_up_event(&mut self, _keycode: KeyCode, _keymods: KeyMods) { ... }
fn touch_event(&mut self, phase: TouchPhase, _id: u64, x: f32, y: f32) { ... }
fn raw_mouse_motion(&mut self, _dx: f32, _dy: f32) { ... }
fn window_minimized_event(&mut self) { ... }
fn window_restored_event(&mut self) { ... }
fn quit_requested_event(&mut self) { ... }
fn files_dropped_event(&mut self) { ... }
}
dep_miniquad
only.Expand description
A trait defining event callbacks.
Required Methods§
fn update(&mut self)
fn update(&mut self)
On most platforms update() and draw() are called each frame, sequentially, draw right after update. But on Android (and maybe some other platforms in the future) update might be called without draw. When the app is in background, Android destroys the rendering surface, while app is still alive and can do some usefull calculations. Note that in this case drawing from update may lead to crashes.
fn draw(&mut self)
Provided Methods§
fn resize_event(&mut self, _width: f32, _height: f32)
fn mouse_motion_event(&mut self, _x: f32, _y: f32)
fn mouse_wheel_event(&mut self, _x: f32, _y: f32)
fn char_event(&mut self, _character: char, _keymods: KeyMods, _repeat: bool)
fn key_down_event( &mut self, _keycode: KeyCode, _keymods: KeyMods, _repeat: bool, )
fn key_up_event(&mut self, _keycode: KeyCode, _keymods: KeyMods)
fn touch_event(&mut self, phase: TouchPhase, _id: u64, x: f32, y: f32)
fn touch_event(&mut self, phase: TouchPhase, _id: u64, x: f32, y: f32)
Default implementation emulates mouse clicks
fn raw_mouse_motion(&mut self, _dx: f32, _dy: f32)
fn raw_mouse_motion(&mut self, _dx: f32, _dy: f32)
Represents raw hardware mouse motion event Note that these events are delivered regardless of input focus and not in pixels, but in hardware units instead. And those units may be different from pixels depending on the target platform
fn window_minimized_event(&mut self)
fn window_minimized_event(&mut self)
Window has been minimized Right now is only implemented on Android, X11 and wasm, On Andoid window_minimized_event is called on a Pause ndk callback On X11 and wasm it will be called on focus change events.
fn window_restored_event(&mut self)
fn window_restored_event(&mut self)
Window has been restored Right now is only implemented on Android, X11 and wasm, On Andoid window_minimized_event is called on a Pause ndk callback On X11 and wasm it will be called on focus change events.
fn quit_requested_event(&mut self)
fn quit_requested_event(&mut self)
This event is sent when the userclicks the window’s close button or application code calls the ctx.request_quit() function. The event handler callback code can handle this event by calling ctx.cancel_quit() to cancel the quit. If the event is ignored, the application will quit as usual.
fn files_dropped_event(&mut self)
fn files_dropped_event(&mut self)
A file has been dropped over the application.
Applications can request the number of dropped files with
ctx.dropped_file_count()
, path of an individual file with
ctx.dropped_file_path()
, and for wasm targets the file bytes
can be requested with ctx.dropped_file_bytes()
.