Trait appit::WindowBehavior

source ·
pub trait WindowBehavior<AppMessage>: Sized + 'static
where AppMessage: Message,
{ type Context: Send;
Show 34 methods // Required methods fn initialize( window: &mut RunningWindow<AppMessage>, context: Self::Context ) -> Self; fn redraw(&mut self, window: &mut RunningWindow<AppMessage>); // Provided methods fn build<App>(app: &mut App) -> WindowBuilder<'_, Self, App, AppMessage> where App: AsApplication<AppMessage> + ?Sized, Self::Context: Default { ... } fn build_with<App>( app: &mut App, context: Self::Context ) -> WindowBuilder<'_, Self, App, AppMessage> where App: AsApplication<AppMessage> + ?Sized { ... } fn run_with_event_callback( app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response + 'static ) -> Result<(), EventLoopError> where Self::Context: Default { ... } fn run_with_context_and_event_callback( context: Self::Context, app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response + 'static ) -> Result<(), EventLoopError> { ... } fn open<App>( app: &mut App ) -> Result<Option<Window<AppMessage::Window>>, OsError> where App: AsApplication<AppMessage> + ?Sized, Self::Context: Default { ... } fn open_with<App>( app: &mut App, context: Self::Context ) -> Result<Option<Window<AppMessage::Window>>, OsError> where App: AsApplication<AppMessage> + ?Sized { ... } fn close_requested( &mut self, window: &mut RunningWindow<AppMessage> ) -> bool { ... } fn focus_changed(&mut self, window: &mut RunningWindow<AppMessage>) { ... } fn occlusion_changed(&mut self, window: &mut RunningWindow<AppMessage>) { ... } fn scale_factor_changed(&mut self, window: &mut RunningWindow<AppMessage>) { ... } fn resized(&mut self, window: &mut RunningWindow<AppMessage>) { ... } fn theme_changed(&mut self, window: &mut RunningWindow<AppMessage>) { ... } fn dropped_file( &mut self, window: &mut RunningWindow<AppMessage>, path: PathBuf ) { ... } fn hovered_file( &mut self, window: &mut RunningWindow<AppMessage>, path: PathBuf ) { ... } fn hovered_file_cancelled(&mut self, window: &mut RunningWindow<AppMessage>) { ... } fn received_character( &mut self, window: &mut RunningWindow<AppMessage>, char: char ) { ... } fn keyboard_input( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, event: KeyEvent, is_synthetic: bool ) { ... } fn modifiers_changed(&mut self, window: &mut RunningWindow<AppMessage>) { ... } fn ime(&mut self, window: &mut RunningWindow<AppMessage>, ime: Ime) { ... } fn cursor_moved( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, position: PhysicalPosition<f64> ) { ... } fn cursor_entered( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId ) { ... } fn cursor_left( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId ) { ... } fn mouse_wheel( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: MouseScrollDelta, phase: TouchPhase ) { ... } fn mouse_input( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, state: ElementState, button: MouseButton ) { ... } fn touchpad_pressure( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, pressure: f32, stage: i64 ) { ... } fn axis_motion( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, axis: AxisId, value: f64 ) { ... } fn touch(&mut self, window: &mut RunningWindow<AppMessage>, touch: Touch) { ... } fn pinch_gesture( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: f64, phase: TouchPhase ) { ... } fn pan_gesture( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: PhysicalPosition<f32>, phase: TouchPhase ) { ... } fn double_tap_gesture( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId ) { ... } fn touchpad_rotate( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: f32, phase: TouchPhase ) { ... } fn event( &mut self, window: &mut RunningWindow<AppMessage>, event: AppMessage::Window ) { ... }
}
Expand description

The behavior that drives the contents of a window.

With winit and appit, the act of populating the window is up to the consumers of the libraries. This trait provides functions for each of the events a window may receive, enabling the type to react and update its state.

Required Associated Types§

source

type Context: Send

A type that is passed to initialize().

This allows providing data to the window from the thread that is opening the window without requiring that WindowBehavior also be Send.

Required Methods§

source

fn initialize( window: &mut RunningWindow<AppMessage>, context: Self::Context ) -> Self

Returns a new instance of this behavior after initializing itself with the window and context.

source

fn redraw(&mut self, window: &mut RunningWindow<AppMessage>)

Displays the contents of the window.

Provided Methods§

source

fn build<App>(app: &mut App) -> WindowBuilder<'_, Self, App, AppMessage>
where App: AsApplication<AppMessage> + ?Sized, Self::Context: Default,

Returns a new window builder for this behavior. When the window is initialized, a default Context will be passed.

source

fn build_with<App>( app: &mut App, context: Self::Context ) -> WindowBuilder<'_, Self, App, AppMessage>
where App: AsApplication<AppMessage> + ?Sized,

Returns a new window builder for this behavior. When the window is initialized, the provided context will be passed.

source

fn run_with_event_callback( app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response + 'static ) -> Result<(), EventLoopError>
where Self::Context: Default,

Runs a window with a default instance of this behavior’s Context.

This function is shorthand for creating a PendingApp, opening this window inside of it, and running the pending app.

Messages can be sent to the application’s main thread using Application::send. Each time a message is received by the main event loop, app_callback will be invoked.

§Errors

Returns an EventLoopError upon the loop exiting due to an error. See [EventLoop::run] for more information.

source

fn run_with_context_and_event_callback( context: Self::Context, app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response + 'static ) -> Result<(), EventLoopError>

Runs a window with the provided Context.

This function is shorthand for creating a PendingApp, opening this window inside of it, and running the pending app.

Messages can be sent to the application’s main thread using Application::send. Each time a message is received by the main event loop, app_callback will be invoked.

§Errors

Returns an EventLoopError upon the loop exiting due to an error. See [EventLoop::run] for more information.

source

fn open<App>( app: &mut App ) -> Result<Option<Window<AppMessage::Window>>, OsError>
where App: AsApplication<AppMessage> + ?Sized, Self::Context: Default,

Opens a new window with a default instance of this behavior’s Context. The events of the window will be processed in a thread spawned by this function.

If the application has shut down, this function returns None.

§Errors

The only errors this funciton can return arise from [winit::window::WindowBuilder::build].

source

fn open_with<App>( app: &mut App, context: Self::Context ) -> Result<Option<Window<AppMessage::Window>>, OsError>
where App: AsApplication<AppMessage> + ?Sized,

Opens a new window with the provided Context. The events of the window will be processed in a thread spawned by this function.

If the application has shut down, this function returns None.

§Errors

The only errors this funciton can return arise from [winit::window::WindowBuilder::build].

source

fn close_requested(&mut self, window: &mut RunningWindow<AppMessage>) -> bool

The window has been requested to be closed. This can happen as a result of the user clicking the close button.

If the window should be closed, return true. To prevent closing the window, return false.

source

fn focus_changed(&mut self, window: &mut RunningWindow<AppMessage>)

The window has gained or lost keyboard focus. RunningWindow::focused() returns the current state.

source

fn occlusion_changed(&mut self, window: &mut RunningWindow<AppMessage>)

The window has been occluded or revealed. RunningWindow::occluded() returns the current state.

source

fn scale_factor_changed(&mut self, window: &mut RunningWindow<AppMessage>)

The window’s scale factor has changed. RunningWindow::scale() returns the current scale.

source

fn resized(&mut self, window: &mut RunningWindow<AppMessage>)

The window has been resized. RunningWindow::inner_size() returns the current size.

source

fn theme_changed(&mut self, window: &mut RunningWindow<AppMessage>)

The window’s theme has been updated. RunningWindow::theme() returns the current theme.

source

fn dropped_file( &mut self, window: &mut RunningWindow<AppMessage>, path: PathBuf )

A file has been dropped on the window.

source

fn hovered_file( &mut self, window: &mut RunningWindow<AppMessage>, path: PathBuf )

A file is hovering over the window.

source

fn hovered_file_cancelled(&mut self, window: &mut RunningWindow<AppMessage>)

A file being overed has been cancelled.

source

fn received_character( &mut self, window: &mut RunningWindow<AppMessage>, char: char )

An input event has generated a character.

source

fn keyboard_input( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, event: KeyEvent, is_synthetic: bool )

A keyboard event occurred while the window was focused.

source

fn modifiers_changed(&mut self, window: &mut RunningWindow<AppMessage>)

The keyboard modifier keys have changed. RunningWindow::modifiers() returns the current modifier keys state.

source

fn ime(&mut self, window: &mut RunningWindow<AppMessage>, ime: Ime)

An international input even thas occurred for the window.

source

fn cursor_moved( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, position: PhysicalPosition<f64> )

A cursor has moved over the window.

source

fn cursor_entered( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId )

A cursor has hovered over the window.

source

fn cursor_left( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId )

A cursor is no longer hovering over the window.

source

fn mouse_wheel( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: MouseScrollDelta, phase: TouchPhase )

An event from a mouse wheel.

source

fn mouse_input( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, state: ElementState, button: MouseButton )

A mouse button was pressed or released.

source

fn touchpad_pressure( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, pressure: f32, stage: i64 )

A pressure-sensitive touchpad was touched.

source

fn axis_motion( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, axis: AxisId, value: f64 )

A multi-axis input device has registered motion.

source

fn touch(&mut self, window: &mut RunningWindow<AppMessage>, touch: Touch)

A touch event.

source

fn pinch_gesture( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: f64, phase: TouchPhase )

A magnification gesture.

source

fn pan_gesture( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: PhysicalPosition<f32>, phase: TouchPhase )

A pan/scroll gesture.

source

fn double_tap_gesture( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId )

A request to smart-magnify the window.

source

fn touchpad_rotate( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: f32, phase: TouchPhase )

A touchpad-originated rotation gesture.

source

fn event( &mut self, window: &mut RunningWindow<AppMessage>, event: AppMessage::Window )

A user event has been received by the window.

Object Safety§

This trait is not object safe.

Implementors§