Trait kludgine::app::WindowBehavior
source · pub trait WindowBehavior<WindowEvent = ()>: Sized + 'staticwhere
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§
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>
) -> bool
fn render<'pass>( &'pass mut self, window: Window<'_, WindowEvent>, graphics: &mut RenderingGraphics<'_, 'pass> ) -> bool
Render the contents of the window.
Provided Methods§
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 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 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<App>(
app: &mut App
) -> Result<Option<WindowHandle<WindowEvent>>, OsError>
fn open<App>( app: &mut App ) -> Result<Option<WindowHandle<WindowEvent>>, 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<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.
[RunningWindow::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. [RunningWindow::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. [RunningWindow::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. [RunningWindow::inner_size()
]
returns the current size.
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. [RunningWindow::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. [RunningWindow::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.