pub trait WindowBehavior<WindowEvent = ()>: Sized + 'staticwhere
WindowEvent: Send + 'static,{
type Context: Send + 'static;
Show 44 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>,
);
// Provided methods
fn pre_initialize(context: &Self::Context, winit: &Window) { ... }
fn initial_window_attributes(context: &Self::Context) -> WindowAttributes { ... }
fn power_preference(context: &Self::Context) -> PowerPreference { ... }
fn memory_hints(context: &Self::Context) -> MemoryHints { ... }
fn limits(adapter_limits: Limits, context: &Self::Context) -> Limits { ... }
fn multisample_count(context: &Self::Context) -> NonZeroU32 { ... }
fn initialized(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
) { ... }
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 moved(
&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§
Sourcetype Context: Send + 'static
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§
Sourcefn initialize(
window: Window<'_, WindowEvent>,
graphics: &mut Graphics<'_>,
context: Self::Context,
) -> Self
fn initialize( window: Window<'_, WindowEvent>, graphics: &mut Graphics<'_>, context: Self::Context, ) -> Self
Initialize a new instance from the provided context.
Sourcefn render<'pass>(
&'pass mut self,
window: Window<'_, WindowEvent>,
graphics: &mut RenderingGraphics<'_, 'pass>,
)
fn render<'pass>( &'pass mut self, window: Window<'_, WindowEvent>, graphics: &mut RenderingGraphics<'_, 'pass>, )
Render the contents of the window.
Provided Methods§
Sourcefn pre_initialize(context: &Self::Context, winit: &Window)
fn pre_initialize(context: &Self::Context, winit: &Window)
Invoked before wgpu is initialized for this window.
Sourcefn initial_window_attributes(context: &Self::Context) -> WindowAttributes
fn initial_window_attributes(context: &Self::Context) -> WindowAttributes
Returns the window attributes to use when creating the window.
Sourcefn power_preference(context: &Self::Context) -> PowerPreference
fn power_preference(context: &Self::Context) -> PowerPreference
Returns the power preference to initialize wgpu
with.
Sourcefn memory_hints(context: &Self::Context) -> MemoryHints
fn memory_hints(context: &Self::Context) -> MemoryHints
Returns the memory hints to initialize wgpu
with.
Sourcefn limits(adapter_limits: Limits, context: &Self::Context) -> Limits
fn limits(adapter_limits: Limits, context: &Self::Context) -> Limits
Returns the limits to apply for the wgpu
instance.
Sourcefn multisample_count(context: &Self::Context) -> NonZeroU32
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.
Sourcefn initialized(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
)
fn initialized( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, )
Executed once after the window has been fully initialized.
Sourcefn prepare(
&mut self,
window: Window<'_, WindowEvent>,
graphics: &mut Graphics<'_>,
)
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.
Sourcefn present_mode(&self) -> PresentMode
fn present_mode(&self) -> PresentMode
Returns the swap chain present mode to use for this window.
Sourcefn clear_color(&self) -> Option<Color>
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)
.
Sourcefn composite_alpha_mode(
&self,
supported_modes: &[CompositeAlphaMode],
) -> CompositeAlphaMode
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.
Sourcefn run() -> Result<(), EventLoopError>
fn run() -> Result<(), EventLoopError>
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.
Sourcefn run_with(context: Self::Context) -> Result<(), EventLoopError>
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.
Sourcefn open_with<App>(
app: &mut App,
context: Self::Context,
) -> Result<Option<WindowHandle<WindowEvent>>, OsError>
fn open_with<App>( app: &mut App, context: Self::Context, ) -> Result<Option<WindowHandle<WindowEvent>>, OsError>
Sourcefn close_requested(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
) -> bool
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.
Sourcefn focus_changed(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
)
fn focus_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, )
The window has gained or lost keyboard focus. Window::focused()
returns the current state.
Sourcefn occlusion_changed(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
)
fn occlusion_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, )
The window has been occluded or revealed. Window::occluded()
returns
the current state.
Sourcefn scale_factor_changed(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
)
fn scale_factor_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, )
The window’s scale factor has changed. Window::scale()
returns the
current scale.
Sourcefn resized(&mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine)
fn resized(&mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine)
The window has been resized. Window::inner_size()
returns the
current size.
Sourcefn moved(&mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine)
fn moved(&mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine)
The window has been moved. [Window::position()
] returns the current
position.
Sourcefn theme_changed(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
)
fn theme_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, )
The window’s theme has been updated. Window::theme()
returns the
current theme.
Sourcefn dropped_file(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
path: PathBuf,
)
fn dropped_file( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, path: PathBuf, )
A file has been dropped on the window.
Sourcefn hovered_file(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
path: PathBuf,
)
fn hovered_file( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, path: PathBuf, )
A file is hovering over the window.
Sourcefn hovered_file_cancelled(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
)
fn hovered_file_cancelled( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, )
A file being overed has been cancelled.
Sourcefn received_character(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
char: char,
)
fn received_character( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, char: char, )
An input event has generated a character.
Sourcefn keyboard_input(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
input: KeyEvent,
is_synthetic: bool,
)
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.
Sourcefn modifiers_changed(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
)
fn modifiers_changed( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, )
The keyboard modifier keys have changed. Window::modifiers()
returns
the current modifier keys state.
Sourcefn ime(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
ime: Ime,
)
fn ime( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, ime: Ime, )
An international input even thas occurred for the window.
Sourcefn cursor_moved(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
position: PhysicalPosition<f64>,
)
fn cursor_moved( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, position: PhysicalPosition<f64>, )
A cursor has moved over the window.
Sourcefn cursor_entered(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
)
fn cursor_entered( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, )
A cursor has hovered over the window.
Sourcefn cursor_left(
&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, )
A cursor is no longer hovering over the window.
Sourcefn mouse_wheel(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
delta: MouseScrollDelta,
phase: TouchPhase,
)
fn mouse_wheel( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: MouseScrollDelta, phase: TouchPhase, )
An event from a mouse wheel.
Sourcefn mouse_input(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
state: ElementState,
button: MouseButton,
)
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.
Sourcefn touchpad_pressure(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
pressure: f32,
stage: i64,
)
fn touchpad_pressure( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, pressure: f32, stage: i64, )
A pressure-sensitive touchpad was touched.
Sourcefn axis_motion(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
axis: AxisId,
value: f64,
)
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.
Sourcefn touch(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
touch: Touch,
)
fn touch( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, touch: Touch, )
A touch event.
Sourcefn pinch_gesture(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
delta: f64,
phase: TouchPhase,
)
fn pinch_gesture( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: f64, phase: TouchPhase, )
A pinch-to-zoom gesture.
Sourcefn pan_gesture(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
delta: Point<f32>,
phase: TouchPhase,
)
fn pan_gesture( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: Point<f32>, phase: TouchPhase, )
A pan/scroll gesture.
Sourcefn double_tap_gesture(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
)
fn double_tap_gesture( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, )
A double-tap gesture directed at the window.
Sourcefn touchpad_rotate(
&mut self,
window: Window<'_, WindowEvent>,
kludgine: &mut Kludgine,
device_id: DeviceId,
delta: f32,
phase: TouchPhase,
)
fn touchpad_rotate( &mut self, window: Window<'_, WindowEvent>, kludgine: &mut Kludgine, device_id: DeviceId, delta: f32, phase: TouchPhase, )
A touchpad-originated rotation gesture.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.