pub struct Window { /* private fields */ }Expand description
A winit window wrapper with frame-tracking and cursor management.
Owns an optional [Arc<WinitWindow>]. When closed, the inner handle is
set to None and all methods become no-ops returning default values.
§Frame tracking
Call update_frame once per frame after
processing events. This computes:
- Cursor delta (movement since last frame)
- Window position delta
- Cursor loopback wrapping
§Cursor modes
The window supports three cursor modes:
- Grab — cursor is locked to the window (hidden, infinite movement)
- Confine — cursor is confined to the window area (visible, clamped)
- Loopback — cursor position wraps at window edges (software, for raw input in first-person controls)
Grab and confine are winit-level operations; loopback is implemented by
update_frame warping the cursor.
Implementations§
Source§impl Window
impl Window
Sourcepub fn new(el: &EventLoop<()>, title: &str, size: Size2D) -> Self
pub fn new(el: &EventLoop<()>, title: &str, size: Size2D) -> Self
Create a new window.
The window starts hidden — call set_visible(true)
when ready, or let the game loop manage visibility.
Sourcepub fn new_transparent(el: &EventLoop<()>, title: &str, size: Size2D) -> Self
pub fn new_transparent(el: &EventLoop<()>, title: &str, size: Size2D) -> Self
Create a new transparent window (requires a compositor that supports transparency).
Same as new but sets with_transparent(true) on the winit window.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
True if the window is still open.
Sourcepub fn raw_handle(&self) -> Option<RawWindowHandle>
pub fn raw_handle(&self) -> Option<RawWindowHandle>
Raw window handle for EGL surface creation.
Sourcepub fn raw_display_handle(&self) -> Option<RawDisplayHandle>
pub fn raw_display_handle(&self) -> Option<RawDisplayHandle>
Raw display handle for EGL display connection.
Sourcepub fn set_size(&self, size: Size2D)
pub fn set_size(&self, size: Size2D)
Request a new inner size.
The OS may not honor the exact request — check size() later.
Sourcepub fn prev_size(&self) -> Size2D
pub fn prev_size(&self) -> Size2D
The size cached at the last update_frame call.
Sourcepub fn min_size(&self) -> Option<Size2D>
pub fn min_size(&self) -> Option<Size2D>
Minimum window size (cached value, not a live winit query).
Sourcepub fn set_min_size(&mut self, size: Option<Size2D>)
pub fn set_min_size(&mut self, size: Option<Size2D>)
Set the minimum window size.
Sourcepub fn max_size(&self) -> Option<Size2D>
pub fn max_size(&self) -> Option<Size2D>
Maximum window size (cached value, not a live winit query).
Sourcepub fn set_max_size(&mut self, size: Option<Size2D>)
pub fn set_max_size(&mut self, size: Option<Size2D>)
Set the maximum window size.
Sourcepub fn set_resizable(&self, enable: bool)
pub fn set_resizable(&self, enable: bool)
Enable or disable resizing.
Sourcepub fn position(&self) -> Coord2D
pub fn position(&self) -> Coord2D
Desktop position of the window (live winit query via outer_position).
Sourcepub fn set_position(&self, pos: Coord2D)
pub fn set_position(&self, pos: Coord2D)
Set the desktop position.
Sourcepub fn center_on_screen(&self)
pub fn center_on_screen(&self)
Center the window on the current monitor.
Sourcepub fn prev_position(&self) -> Coord2D
pub fn prev_position(&self) -> Coord2D
Desktop position cached at the last update_frame call.
Sourcepub fn position_delta(&mut self) -> CoordOffset
pub fn position_delta(&mut self) -> CoordOffset
Cumulative window position delta since the last call to this method (reset on read).
Sourcepub fn is_fullscreen(&self) -> bool
pub fn is_fullscreen(&self) -> bool
True if the window is currently fullscreen (live winit query).
Sourcepub fn set_fullscreen(&self, enable: bool)
pub fn set_fullscreen(&self, enable: bool)
Enter or exit borderless fullscreen.
Sourcepub fn toggle_fullscreen(&self)
pub fn toggle_fullscreen(&self)
Toggle fullscreen.
Sourcepub fn is_visible(&self) -> bool
pub fn is_visible(&self) -> bool
True if the window is visible (live winit query).
Sourcepub fn set_visible(&self, visible: bool)
pub fn set_visible(&self, visible: bool)
Show or hide the window.
Sourcepub fn is_minimized(&self) -> bool
pub fn is_minimized(&self) -> bool
True if the window is minimized (live winit query).
Sourcepub fn is_maximized(&self) -> bool
pub fn is_maximized(&self) -> bool
True if the window is maximized (live winit query).
Sourcepub fn unmaximize(&self)
pub fn unmaximize(&self)
Unmaximize the window (restore).
Sourcepub fn request_redraw(&self)
pub fn request_redraw(&self)
Request a redraw from winit.
Sourcepub fn screen_info(&self) -> Option<ScreenInfo>
pub fn screen_info(&self) -> Option<ScreenInfo>
Information about the monitor this window is on.
Sourcepub fn cursor_pos(&self) -> Coord2D
pub fn cursor_pos(&self) -> Coord2D
Cached cursor position (updated via events or set_cursor_pos).
Sourcepub fn set_cursor_pos(&mut self, pos: Coord2D)
pub fn set_cursor_pos(&mut self, pos: Coord2D)
Move the OS cursor and update the cached position.
Sourcepub fn cursor_delta(&self) -> CoordOffset
pub fn cursor_delta(&self) -> CoordOffset
Cursor delta since the last frame (computed by update_frame).
Y is inverted (positive = up) to match screen coordinates.
Sourcepub fn cursor_pos_normalized(&self) -> Coord2D
pub fn cursor_pos_normalized(&self) -> Coord2D
Cursor position normalized to 0..1 where (0,0) = bottom-left, (1,1) = top-right.
Sourcepub fn is_cursor_inside(&self) -> bool
pub fn is_cursor_inside(&self) -> bool
True if the cursor is inside the window client area (updated via events).
Sourcepub fn is_cursor_visible(&self) -> bool
pub fn is_cursor_visible(&self) -> bool
True if the cursor is visible (cached, not a live winit query).
Sourcepub fn set_cursor_visible(&mut self, visible: bool)
pub fn set_cursor_visible(&mut self, visible: bool)
Show or hide the cursor.
Sourcepub fn toggle_cursor_visible(&mut self)
pub fn toggle_cursor_visible(&mut self)
Toggle cursor visibility.
Sourcepub fn is_cursor_grabbed(&self) -> bool
pub fn is_cursor_grabbed(&self) -> bool
True if the cursor is grabbed (locked + hidden, for raw input).
Sourcepub fn set_cursor_grab(&mut self, grab: bool) -> Result<(), ()>
pub fn set_cursor_grab(&mut self, grab: bool) -> Result<(), ()>
Lock or release the cursor (grab mode). Returns Err(()) if the platform
does not support cursor locking.
Sourcepub fn toggle_cursor_grab(&mut self)
pub fn toggle_cursor_grab(&mut self)
Toggle cursor grab.
Sourcepub fn is_cursor_confined(&self) -> bool
pub fn is_cursor_confined(&self) -> bool
True if the cursor is confined (clamped to window, visible).
Sourcepub fn set_cursor_confine(&mut self, confine: bool) -> Result<(), ()>
pub fn set_cursor_confine(&mut self, confine: bool) -> Result<(), ()>
Confine or release the cursor. Returns Err(()) if unsupported.
Sourcepub fn toggle_cursor_confine(&mut self)
pub fn toggle_cursor_confine(&mut self)
Toggle cursor confine.
Sourcepub fn is_cursor_loopback(&self) -> bool
pub fn is_cursor_loopback(&self) -> bool
True if cursor loopback (software edge-wrapping) is enabled.
Sourcepub fn set_cursor_loopback(&mut self, loopback: bool)
pub fn set_cursor_loopback(&mut self, loopback: bool)
Enable or disable loopback mode. When enabled, update_frame
will wrap the cursor position at window edges, useful for first-person camera control.
Sourcepub fn update_frame(&mut self)
pub fn update_frame(&mut self)
Call once per frame after processing events.
Snapshots cursor position, computes cursor/window deltas, and applies loopback wrapping if enabled.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Window
impl !UnwindSafe for Window
impl Freeze for Window
impl Send for Window
impl Sync for Window
impl Unpin for Window
impl UnsafeUnpin for Window
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.