pub trait WindowBehavior<WindowEvent = ()>: Sized + 'static
where WindowEvent: Send + 'static,
{ type Context: Send + 'static;
Show 40 methods // Required methods fn initialize( window: Window<'_, WindowEvent>, graphics: &mut Graphics<'_>, context: Self::Context ) -> Self; fn render<'pass>( &'pass mut self, window: Window<'_, WindowEvent>, graphics: &mut RenderingGraphics<'_, 'pass> ) -> bool; // Provided methods fn initial_window_attributes(context: &Self::Context) -> WindowAttributes { ... } fn power_preference(context: &Self::Context) -> PowerPreference { ... } fn limits(adapter_limits: Limits, context: &Self::Context) -> Limits { ... } fn multisample_count(context: &Self::Context) -> NonZeroU32 { ... } fn prepare( &mut self, window: Window<'_, WindowEvent>, graphics: &mut Graphics<'_> ) { ... } fn present_mode(&self) -> PresentMode { ... } fn clear_color(&self) -> Option<Color> { ... } fn composite_alpha_mode( &self, supported_modes: &[CompositeAlphaMode] ) -> CompositeAlphaMode { ... } fn run() -> Result<(), EventLoopError> where Self::Context: Default { ... } fn run_with(context: Self::Context) -> Result<(), EventLoopError> { ... } fn open<App>( app: &mut App ) -> Result<Option<WindowHandle<WindowEvent>>, OsError> where App: AsApplication<AppEvent<WindowEvent>> + ?Sized, Self::Context: Default { ... } fn open_with<App>( app: &mut App, context: Self::Context ) -> Result<Option<WindowHandle<WindowEvent>>, OsError> where App: AsApplication<AppEvent<WindowEvent>> + ?Sized { ... } fn close_requested( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine ) -> bool { ... } fn focus_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine ) { ... } fn occlusion_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine ) { ... } fn scale_factor_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine ) { ... } fn resized( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine ) { ... } fn theme_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine ) { ... } fn dropped_file( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, path: PathBuf ) { ... } fn hovered_file( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, path: PathBuf ) { ... } fn hovered_file_cancelled( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine ) { ... } fn received_character( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, char: char ) { ... } fn keyboard_input( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, input: KeyEvent, is_synthetic: bool ) { ... } fn modifiers_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine ) { ... } fn ime( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, ime: Ime ) { ... } fn cursor_moved( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, position: PhysicalPosition<f64> ) { ... } fn cursor_entered( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId ) { ... } fn cursor_left( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId ) { ... } fn mouse_wheel( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: MouseScrollDelta, phase: TouchPhase ) { ... } fn mouse_input( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, state: ElementState, button: MouseButton ) { ... } fn touchpad_pressure( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, pressure: f32, stage: i64 ) { ... } fn axis_motion( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, axis: AxisId, value: f64 ) { ... } fn touch( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, touch: Touch ) { ... } fn pinch_gesture( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: f64, phase: TouchPhase ) { ... } fn pan_gesture( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: Point<f32>, phase: TouchPhase ) { ... } fn double_tap_gesture( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId ) { ... } fn touchpad_rotate( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: f32, phase: TouchPhase ) { ... } fn event( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, event: WindowEvent ) { ... }
}
Expand description

The behavior of a window.

Required Associated Types§

source

type Context: Send + 'static

The type of value provided during initialize().

In Kludgine, each window runs in its own thread. Kludgine allows does not require WindowBehavior implementors to implement Send, but it can be useful to receive input from the thread that is opening the window. This is where Context is useful: it must implement Send, allowing some data to still be passed when opening the window.

Required Methods§

source

fn initialize( window: Window<'_, WindowEvent>, graphics: &mut Graphics<'_>, context: Self::Context ) -> Self

Initialize a new instance from the provided context.

source

fn render<'pass>( &'pass mut self, window: Window<'_, WindowEvent>, graphics: &mut RenderingGraphics<'_, 'pass> ) -> bool

Render the contents of the window.

Provided Methods§

source

fn initial_window_attributes(context: &Self::Context) -> WindowAttributes

Returns the window attributes to use when creating the window.

source

fn power_preference(context: &Self::Context) -> PowerPreference

Returns the power preference to initialize wgpu with.

source

fn limits(adapter_limits: Limits, context: &Self::Context) -> Limits

Returns the limits to apply for the wgpu instance.

source

fn multisample_count(context: &Self::Context) -> NonZeroU32

Returns the number of multisamples to perform when rendering this window.

When 1 is returned, multisampling will be fully disabled.

source

fn prepare( &mut self, window: Window<'_, WindowEvent>, graphics: &mut Graphics<'_> )

Prepare the window to render.

This is called directly before render() and is a perfect place to update any prepared graphics as needed.

source

fn present_mode(&self) -> PresentMode

Returns the swap chain present mode to use for this window.

source

fn clear_color(&self) -> Option<Color>

Returns the color to clear the window with. If None is returned, the window will not be cleared between redraws.

The default implementation returns Some(Color::BLACK).

source

fn composite_alpha_mode( &self, supported_modes: &[CompositeAlphaMode] ) -> CompositeAlphaMode

Returns the composite alpha mode to use for rendering the wgpu surface on the window.

supported_modes contains the list of detected alpha modes supported by the surface.

source

fn run() -> Result<(), EventLoopError>
where Self::Context: Default,

Launches a Kludgine app using this window as the primary window.

§Panics

On many platforms, it is a requirement that this function only be called from the thread that is executing the program’s main() function. wgpu may panic when creating a surface if this function is not called from the correct thread.

§Errors

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

source

fn run_with(context: Self::Context) -> Result<(), EventLoopError>

Launches a Kludgine app using this window as the primary window.

The context is passed along to initialize() once the thread it is running on is spawned.

§Panics

On many platforms, it is a requirement that this function only be called from the thread that is executing the program’s main() function. wgpu may panic when creating a surface if this function is not called from the correct thread.

§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<WindowHandle<WindowEvent>>, OsError>
where App: AsApplication<AppEvent<WindowEvent>> + ?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<WindowHandle<WindowEvent>>, OsError>
where App: AsApplication<AppEvent<WindowEvent>> + ?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: Window<'_, WindowEvent>, kludgine: &mut Kludgine ) -> 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: Window<'_, WindowEvent>, kludgine: &mut Kludgine )

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

source

fn occlusion_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine )

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

source

fn scale_factor_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine )

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

source

fn resized(&mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine)

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

source

fn theme_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine )

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

source

fn dropped_file( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, path: PathBuf )

A file has been dropped on the window.

source

fn hovered_file( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, path: PathBuf )

A file is hovering over the window.

source

fn hovered_file_cancelled( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine )

A file being overed has been cancelled.

source

fn received_character( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, char: char )

An input event has generated a character.

source

fn keyboard_input( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, input: KeyEvent, is_synthetic: bool )

A keyboard event occurred while the window was focused.

source

fn modifiers_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine )

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

source

fn ime( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, ime: Ime )

An international input even thas occurred for the window.

source

fn cursor_moved( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, position: PhysicalPosition<f64> )

A cursor has moved over the window.

source

fn cursor_entered( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId )

A cursor has hovered over the window.

source

fn cursor_left( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId )

A cursor is no longer hovering over the window.

source

fn mouse_wheel( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: MouseScrollDelta, phase: TouchPhase )

An event from a mouse wheel.

source

fn mouse_input( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, state: ElementState, button: MouseButton )

A mouse button was pressed or released.

source

fn touchpad_pressure( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, pressure: f32, stage: i64 )

A pressure-sensitive touchpad was touched.

source

fn axis_motion( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, axis: AxisId, value: f64 )

A multi-axis input device has registered motion.

source

fn touch( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, touch: Touch )

A touch event.

source

fn pinch_gesture( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: f64, phase: TouchPhase )

A pinch-to-zoom gesture.

source

fn pan_gesture( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: Point<f32>, phase: TouchPhase )

A pan/scroll gesture.

source

fn double_tap_gesture( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId )

A double-tap gesture directed at the window.

source

fn touchpad_rotate( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: f32, phase: TouchPhase )

A touchpad-originated rotation gesture.

source

fn event( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, event: WindowEvent )

A WindowEvent has been received by this window.

Object Safety§

This trait is not object safe.

Implementors§