AppHandler

Trait AppHandler 

Source
pub trait AppHandler {
Show 18 methods // Required methods fn min_size(&self) -> (u16, u16); fn start_size(&self) -> (u16, u16); fn cursor_should_be_visible(&self) -> bool; fn redraw(&mut self) -> bool; fn got_focus(&mut self); fn lost_focus(&mut self); fn window_created(&mut self, window: Arc<Window>); fn resized(&mut self, size: PhysicalSize<u32>); fn keyboard_input( &mut self, element_state: ElementState, physical_key: PhysicalKey, ); fn cursor_entered(&mut self); fn cursor_left(&mut self); fn cursor_moved(&mut self, physical_position: PhysicalPosition<u32>); fn mouse_input(&mut self, element_state: ElementState, button: MouseButton); fn mouse_wheel(&mut self, delta: MouseScrollDelta, touch_phase: TouchPhase); fn pinch_gesture(&mut self, delta: f64, touch_phase: TouchPhase); fn mouse_motion(&mut self, delta: (f64, f64)); fn touch(&mut self, touch: Touch); fn scale_factor_changed( &mut self, scale_factor: f64, inner_size_writer: InnerSizeWriter, );
}
Expand description

AppHandler - Handle window, cursor, mouse and keyboard events, designed for games and graphical applications.

Think of AppHandler as your app’s backstage crew, handling everything from window setup to keyboard and mouse inputs, and making sure each frame redraws smoothly.

Required Methods§

Source

fn min_size(&self) -> (u16, u16)

Returns the minimum window size (width, height) in pixels that the application requires.

This can be used to enforce a minimum size on the window, preventing it from being resized below this dimension.

Source

fn start_size(&self) -> (u16, u16)

Returns the starting window size (width, height) in pixels when the application launches.

This size will be used to set the initial window dimensions on startup.

Source

fn cursor_should_be_visible(&self) -> bool

Source

fn redraw(&mut self) -> bool

Called to trigger a redraw of the application’s content.

This method is generally called when the window needs to refresh its contents, such as after a resize or focus change. Return false if application should close

Source

fn got_focus(&mut self)

Called when the application window gains focus.

This can be used to resume or activate specific behaviors when the window becomes active.

Source

fn lost_focus(&mut self)

Called when the application window loses focus.

Useful for suspending actions or input handling when the application window is not in the foreground.

Source

fn window_created(&mut self, window: Arc<Window>)

Called after the application window has been created and is ready to use.

Use this method to perform any initialization that requires access to the window, such as setting up rendering contexts.

§Parameters
  • window: A reference-counted pointer to the application window.
Source

fn resized(&mut self, size: PhysicalSize<u32>)

Called whenever the window is resized, providing the new physical size.

This method should handle adjustments to the application’s layout and content based on the window’s new dimensions.

§Parameters
  • size: The new size of the window in physical pixels.
Source

fn keyboard_input( &mut self, element_state: ElementState, physical_key: PhysicalKey, )

Processes keyboard input events, such as key presses and releases.

§Parameters
  • element_state: Indicates whether the key is pressed or released.
  • physical_key: The physical key that was pressed or released.
Source

fn cursor_entered(&mut self)

Called when the cursor enters the window.

This can trigger visual changes or status updates when the cursor moves into the application window area.

Source

fn cursor_left(&mut self)

Called when the cursor leaves the window.

This can be used to revert visual changes or trigger actions when the cursor exits the application window.

Source

fn cursor_moved(&mut self, physical_position: PhysicalPosition<u32>)

Handles cursor movement within the window, providing the new position.

§Parameters
  • physical_position: The current position of the cursor in physical screen coordinates.
Source

fn mouse_input(&mut self, element_state: ElementState, button: MouseButton)

Handles mouse button input events, such as presses and releases.

§Parameters
  • element_state: Indicates whether the mouse button is pressed or released.
  • button: The mouse button that was pressed or released.
Source

fn mouse_wheel(&mut self, delta: MouseScrollDelta, touch_phase: TouchPhase)

Processes mouse wheel events, which indicate scrolling actions.

§Parameters
  • delta: The amount of scroll, which may be specified in lines or pixels.
  • touch_phase: The phase of the scroll gesture, which can indicate the start, movement, or end of the gesture.
Source

fn pinch_gesture(&mut self, delta: f64, touch_phase: TouchPhase)

Source

fn mouse_motion(&mut self, delta: (f64, f64))

Handles mouse motion. the delta follows no standard, so it is up to the game to apply a factor as it sees fit.

Source

fn touch(&mut self, touch: Touch)

Handles touch input events, such as screen touches and gestures.

§Parameters
  • touch: Describes the touch event, including position, phase, and other touch-specific information.
Source

fn scale_factor_changed( &mut self, scale_factor: f64, inner_size_writer: InnerSizeWriter, )

Handles changes to the display scale factor, usually due to monitor DPI changes.

This method receives the new scale factor and a writer to update the inner size of the application.

§Parameters
  • scale_factor: The new scale factor, which may be applied to adjust rendering.
  • inner_size_writer: A writer to update the inner size.

Implementors§