pub trait App: 'static + Sized {
Show 15 methods
fn new(_ctx: &mut Context<Self>) -> Self;
fn on_update(&mut self, _ctx: &mut Context<Self>, _delta: f32) { ... }
fn on_close_requested(&mut self, _ctx: &mut Context<Self>) { ... }
fn on_received_character(
&mut self,
_ctx: &mut Context<Self>,
_character: char
) { ... }
fn on_key_pressed(
&mut self,
_ctx: &mut Context<Self>,
_key: KeyboardButton,
_is_repeat: bool
) { ... }
fn on_key_released(&mut self, _ctx: &mut Context<Self>, _key: KeyboardButton) { ... }
fn on_cursor_pressed(
&mut self,
_ctx: &mut Context<Self>,
_button: CursorButton,
_physical_pos: Vector2<f32>,
_normalized_pos: Vector2<f32>
) { ... }
fn on_cursor_released(
&mut self,
_ctx: &mut Context<Self>,
_button: CursorButton,
_physical_pos: Vector2<f32>,
_normalized_pos: Vector2<f32>
) { ... }
fn on_cursor_scroll(
&mut self,
_ctx: &mut Context<Self>,
_direction: ScrollDirection
) { ... }
fn on_cursor_moved(
&mut self,
_ctx: &mut Context<Self>,
_physical_pos: Vector2<f32>,
_normalized_pos: Vector2<f32>
) { ... }
fn on_cursor_delta(
&mut self,
_ctx: &mut Context<Self>,
_delta: Vector2<f32>,
_focused: bool
) { ... }
fn on_cursor_left(&mut self, _ctx: &mut Context<Self>) { ... }
fn on_cursor_entered(&mut self, _ctx: &mut Context<Self>) { ... }
fn on_window_resized(
&mut self,
_ctx: &mut Context<Self>,
_physical_size: Vector2<f32>,
_logical_size: Vector2<f32>,
_scale_factor: f32
) { ... }
fn on_window_focused(&mut self, _ctx: &mut Context<Self>, _focused: bool) { ... }
}
Expand description
Type that holds all of your application state and handles events.
Required Methods
Provided Methods
This event is useful as a place to put your code that should be run after all state-changing events have been handled and you want to do stuff (updating state, performing calculations, etc) that happens as the “main body” of your event loop.
Arguments
ctx
- The engine context. This can be used to call various API functions.delta
- The time passed since the last update in seconds.
fn on_close_requested(&mut self, _ctx: &mut Context<Self>)
fn on_close_requested(&mut self, _ctx: &mut Context<Self>)
The window has requested it close.
fn on_received_character(&mut self, _ctx: &mut Context<Self>, _character: char)
fn on_received_character(&mut self, _ctx: &mut Context<Self>, _character: char)
Received a character. This includes control characters.
Arguments
ctx
- The engine context. This can be used to call various API functions.character
- The character typed.
fn on_key_pressed(
&mut self,
_ctx: &mut Context<Self>,
_key: KeyboardButton,
_is_repeat: bool
)
fn on_key_pressed(
&mut self,
_ctx: &mut Context<Self>,
_key: KeyboardButton,
_is_repeat: bool
)
Keyboard press event. Includes a flag for if this is a repeat event.
Arguments
ctx
- The engine context. This can be used to call various API functions.key
- The button pressed.is_repeat
- Flag for if this key was already pressed. Some environments may fire repeat key pressed events when the key is held.
fn on_key_released(&mut self, _ctx: &mut Context<Self>, _key: KeyboardButton)
fn on_key_released(&mut self, _ctx: &mut Context<Self>, _key: KeyboardButton)
Keyboard release event.
Arguments
ctx
- The engine context. This can be used to call various API functions.key
- The button released.
fn on_cursor_pressed(
&mut self,
_ctx: &mut Context<Self>,
_button: CursorButton,
_physical_pos: Vector2<f32>,
_normalized_pos: Vector2<f32>
)
fn on_cursor_pressed(
&mut self,
_ctx: &mut Context<Self>,
_button: CursorButton,
_physical_pos: Vector2<f32>,
_normalized_pos: Vector2<f32>
)
Cursor press event. Contains the button pressed and the position it was pressed at.
Arguments
ctx
- The engine context. This can be used to call various API functions.button
- The button pressed.physical_pos
- Cursor position at time of press. This is based on the physical size of the window, with (0,0) being the bottom left.normalized_pos
- Cursor position at time of press. This is normalized where the x and y values are between -1 and 1, with the bottom left of the screen being (-1, -1), and the top right being (1, 1). This may be useful for converting screen space coordinates into world space.
fn on_cursor_released(
&mut self,
_ctx: &mut Context<Self>,
_button: CursorButton,
_physical_pos: Vector2<f32>,
_normalized_pos: Vector2<f32>
)
fn on_cursor_released(
&mut self,
_ctx: &mut Context<Self>,
_button: CursorButton,
_physical_pos: Vector2<f32>,
_normalized_pos: Vector2<f32>
)
Cursor press event. Contains the button pressed and the position it was pressed at.
Arguments
ctx
- The engine context. This can be used to call various API functions.button
- The button released.physical_pos
- Cursor position at time of release. This is base with (0,0) being the bottom left.normalized_pos
- Cursor position at time of release. This is normalized where the x and y values are between -1 and 1, with the bottom left of the screen being (-1, -1), and the top right being (1, 1). This may be useful for converting screen space coordinates into world space.
fn on_cursor_scroll(
&mut self,
_ctx: &mut Context<Self>,
_direction: ScrollDirection
)
fn on_cursor_scroll(
&mut self,
_ctx: &mut Context<Self>,
_direction: ScrollDirection
)
Cursor wheel scroll event..
Arguments
ctx
- The engine context. This can be used to call various API functions.direction
- The direction scrolled.
Cursor moved event. Use this for interacting with UI. Contains the new position of the cursor.
Arguments
ctx
- The engine context. This can be used to call various API functions.physical_pos
- Current cursor position. This is based on the physical size of the window, with (0,0) being the bottom left.normalized_pos
- Current cursor position. This is normalized where the x and y values are between -1 and 1, with the bottom left of the screen being (-1, -1), and the top right being (1, 1). This may be useful for converting screen space coordinates into world space.
Cursor delta event. Use this to control a 3D camera. Contains the represents raw, unfiltered physical motion. Represents the change in physical position of the pointing device.
Arguments
ctx
- The engine context. This can be used to call various API functions.delta
- Change from last position. The units are arbitrary and up to the device.focused
- Flag for if the window is focused. This event may return deltas even when the window is not focused.
fn on_cursor_left(&mut self, _ctx: &mut Context<Self>)
fn on_cursor_left(&mut self, _ctx: &mut Context<Self>)
Cursor left the bounds of the window event.
fn on_cursor_entered(&mut self, _ctx: &mut Context<Self>)
fn on_cursor_entered(&mut self, _ctx: &mut Context<Self>)
Cursor entered the bounds of the window event.
Window resized event. Contains the new dimensions of the window.
Arguments
ctx
- The engine context. This can be used to call various API functions.physical_size
- The size of the viewport.logical_size
- The logical size of the viewport. This is derived from the physical_size divided by the scale_factor.scale_factor
- The window’s scale factor. This is a multiplier between the physical size and logical size of the window.
fn on_window_focused(&mut self, _ctx: &mut Context<Self>, _focused: bool)
fn on_window_focused(&mut self, _ctx: &mut Context<Self>, _focused: bool)
The window gained or lost focus.
Arguments
ctx
- The engine context. This can be used to call various API functions.focused
- The parameter is true if the window has gained focus, and false if it has lost focus.