Trait appit::WindowBehavior
source · pub trait WindowBehavior<AppMessage>: Sized + 'staticwhere
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§
sourcetype Context: Send
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§
sourcefn initialize(
window: &mut RunningWindow<AppMessage>,
context: Self::Context
) -> Self
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.
sourcefn redraw(&mut self, window: &mut RunningWindow<AppMessage>)
fn redraw(&mut self, window: &mut RunningWindow<AppMessage>)
Displays the contents of the window.
Provided Methods§
sourcefn build<App>(app: &mut App) -> WindowBuilder<'_, Self, App, AppMessage>
fn build<App>(app: &mut App) -> WindowBuilder<'_, Self, App, AppMessage>
Returns a new window builder for this behavior. When the window is
initialized, a default Context
will be passed.
sourcefn build_with<App>(
app: &mut App,
context: Self::Context
) -> WindowBuilder<'_, Self, App, AppMessage>where
App: AsApplication<AppMessage> + ?Sized,
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.
sourcefn run_with_event_callback(
app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response + 'static
) -> Result<(), EventLoopError>
fn run_with_event_callback( app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response + 'static ) -> Result<(), EventLoopError>
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.
sourcefn run_with_context_and_event_callback(
context: Self::Context,
app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response + 'static
) -> Result<(), EventLoopError>
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.
sourcefn open<App>(
app: &mut App
) -> Result<Option<Window<AppMessage::Window>>, OsError>
fn open<App>( app: &mut App ) -> Result<Option<Window<AppMessage::Window>>, OsError>
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
].
sourcefn open_with<App>(
app: &mut App,
context: Self::Context
) -> Result<Option<Window<AppMessage::Window>>, OsError>where
App: AsApplication<AppMessage> + ?Sized,
fn open_with<App>(
app: &mut App,
context: Self::Context
) -> Result<Option<Window<AppMessage::Window>>, OsError>where
App: AsApplication<AppMessage> + ?Sized,
sourcefn close_requested(&mut self, window: &mut RunningWindow<AppMessage>) -> bool
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.
sourcefn focus_changed(&mut self, window: &mut RunningWindow<AppMessage>)
fn focus_changed(&mut self, window: &mut RunningWindow<AppMessage>)
The window has gained or lost keyboard focus.
RunningWindow::focused()
returns the current state.
sourcefn occlusion_changed(&mut self, window: &mut RunningWindow<AppMessage>)
fn occlusion_changed(&mut self, window: &mut RunningWindow<AppMessage>)
The window has been occluded or revealed. RunningWindow::occluded()
returns the current state.
sourcefn scale_factor_changed(&mut self, window: &mut RunningWindow<AppMessage>)
fn scale_factor_changed(&mut self, window: &mut RunningWindow<AppMessage>)
The window’s scale factor has changed. RunningWindow::scale()
returns the current scale.
sourcefn resized(&mut self, window: &mut RunningWindow<AppMessage>)
fn resized(&mut self, window: &mut RunningWindow<AppMessage>)
The window has been resized. RunningWindow::inner_size()
returns the current size.
sourcefn theme_changed(&mut self, window: &mut RunningWindow<AppMessage>)
fn theme_changed(&mut self, window: &mut RunningWindow<AppMessage>)
The window’s theme has been updated. RunningWindow::theme()
returns the current theme.
sourcefn dropped_file(
&mut self,
window: &mut RunningWindow<AppMessage>,
path: PathBuf
)
fn dropped_file( &mut self, window: &mut RunningWindow<AppMessage>, path: PathBuf )
A file has been dropped on the window.
sourcefn hovered_file(
&mut self,
window: &mut RunningWindow<AppMessage>,
path: PathBuf
)
fn hovered_file( &mut self, window: &mut RunningWindow<AppMessage>, path: PathBuf )
A file is hovering over the window.
sourcefn hovered_file_cancelled(&mut self, window: &mut RunningWindow<AppMessage>)
fn hovered_file_cancelled(&mut self, window: &mut RunningWindow<AppMessage>)
A file being overed has been cancelled.
sourcefn received_character(
&mut self,
window: &mut RunningWindow<AppMessage>,
char: char
)
fn received_character( &mut self, window: &mut RunningWindow<AppMessage>, char: char )
An input event has generated a character.
sourcefn keyboard_input(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId,
event: KeyEvent,
is_synthetic: bool
)
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.
sourcefn modifiers_changed(&mut self, window: &mut RunningWindow<AppMessage>)
fn modifiers_changed(&mut self, window: &mut RunningWindow<AppMessage>)
The keyboard modifier keys have changed. RunningWindow::modifiers()
returns the current modifier keys state.
sourcefn ime(&mut self, window: &mut RunningWindow<AppMessage>, ime: Ime)
fn ime(&mut self, window: &mut RunningWindow<AppMessage>, ime: Ime)
An international input even thas occurred for the window.
sourcefn cursor_moved(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId,
position: PhysicalPosition<f64>
)
fn cursor_moved( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, position: PhysicalPosition<f64> )
A cursor has moved over the window.
sourcefn cursor_entered(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId
)
fn cursor_entered( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId )
A cursor has hovered over the window.
sourcefn cursor_left(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId
)
fn cursor_left( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId )
A cursor is no longer hovering over the window.
sourcefn mouse_wheel(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId,
delta: MouseScrollDelta,
phase: TouchPhase
)
fn mouse_wheel( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: MouseScrollDelta, phase: TouchPhase )
An event from a mouse wheel.
sourcefn mouse_input(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId,
state: ElementState,
button: MouseButton
)
fn mouse_input( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, state: ElementState, button: MouseButton )
A mouse button was pressed or released.
sourcefn touchpad_pressure(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId,
pressure: f32,
stage: i64
)
fn touchpad_pressure( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, pressure: f32, stage: i64 )
A pressure-sensitive touchpad was touched.
sourcefn axis_motion(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId,
axis: AxisId,
value: f64
)
fn axis_motion( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, axis: AxisId, value: f64 )
A multi-axis input device has registered motion.
sourcefn touch(&mut self, window: &mut RunningWindow<AppMessage>, touch: Touch)
fn touch(&mut self, window: &mut RunningWindow<AppMessage>, touch: Touch)
A touch event.
sourcefn pinch_gesture(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId,
delta: f64,
phase: TouchPhase
)
fn pinch_gesture( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: f64, phase: TouchPhase )
A magnification gesture.
sourcefn pan_gesture(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId,
delta: PhysicalPosition<f32>,
phase: TouchPhase
)
fn pan_gesture( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: PhysicalPosition<f32>, phase: TouchPhase )
A pan/scroll gesture.
sourcefn double_tap_gesture(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId
)
fn double_tap_gesture( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId )
A request to smart-magnify the window.
sourcefn touchpad_rotate(
&mut self,
window: &mut RunningWindow<AppMessage>,
device_id: DeviceId,
delta: f32,
phase: TouchPhase
)
fn touchpad_rotate( &mut self, window: &mut RunningWindow<AppMessage>, device_id: DeviceId, delta: f32, phase: TouchPhase )
A touchpad-originated rotation gesture.
sourcefn event(
&mut self,
window: &mut RunningWindow<AppMessage>,
event: AppMessage::Window
)
fn event( &mut self, window: &mut RunningWindow<AppMessage>, event: AppMessage::Window )
A user event has been received by the window.