Skip to main content

Window

Struct Window 

Source
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

Source

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.

Source

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.

Source

pub fn close(&mut self)

Close the window. The inner winit handle is dropped.

Source

pub fn is_closed(&self) -> bool

True if the window has been closed.

Source

pub fn is_running(&self) -> bool

True if the window is still open.

Source

pub fn raw_handle(&self) -> Option<RawWindowHandle>

Raw window handle for EGL surface creation.

Source

pub fn raw_display_handle(&self) -> Option<RawDisplayHandle>

Raw display handle for EGL display connection.

Source

pub fn id(&self) -> Option<WindowId>

The winit window ID.

Source

pub fn size(&self) -> Size2D

Current inner size (live winit query).

Source

pub fn set_size(&self, size: Size2D)

Request a new inner size.

The OS may not honor the exact request — check size() later.

Source

pub fn prev_size(&self) -> Size2D

The size cached at the last update_frame call.

Source

pub fn min_size(&self) -> Option<Size2D>

Minimum window size (cached value, not a live winit query).

Source

pub fn set_min_size(&mut self, size: Option<Size2D>)

Set the minimum window size.

Source

pub fn max_size(&self) -> Option<Size2D>

Maximum window size (cached value, not a live winit query).

Source

pub fn set_max_size(&mut self, size: Option<Size2D>)

Set the maximum window size.

Source

pub fn resizable(&self) -> bool

True if the window is resizable (live winit query).

Source

pub fn set_resizable(&self, enable: bool)

Enable or disable resizing.

Source

pub fn position(&self) -> Coord2D

Desktop position of the window (live winit query via outer_position).

Source

pub fn set_position(&self, pos: Coord2D)

Set the desktop position.

Source

pub fn center_on_screen(&self)

Center the window on the current monitor.

Source

pub fn prev_position(&self) -> Coord2D

Desktop position cached at the last update_frame call.

Source

pub fn position_delta(&mut self) -> CoordOffset

Cumulative window position delta since the last call to this method (reset on read).

Source

pub fn title(&self) -> String

Current window title (live winit query).

Source

pub fn set_title(&self, title: &str)

Set the window title.

Source

pub fn is_fullscreen(&self) -> bool

True if the window is currently fullscreen (live winit query).

Source

pub fn set_fullscreen(&self, enable: bool)

Enter or exit borderless fullscreen.

Source

pub fn toggle_fullscreen(&self)

Toggle fullscreen.

Source

pub fn is_visible(&self) -> bool

True if the window is visible (live winit query).

Source

pub fn set_visible(&self, visible: bool)

Show or hide the window.

Source

pub fn is_minimized(&self) -> bool

True if the window is minimized (live winit query).

Source

pub fn minimize(&self)

Minimize the window.

Source

pub fn restore(&self)

Restore from minimized.

Source

pub fn is_maximized(&self) -> bool

True if the window is maximized (live winit query).

Source

pub fn maximize(&self)

Maximize the window.

Source

pub fn unmaximize(&self)

Unmaximize the window (restore).

Source

pub fn has_focus(&self) -> bool

True if the window has focus (live winit query).

Source

pub fn focus(&self)

Request focus.

Source

pub fn request_redraw(&self)

Request a redraw from winit.

Source

pub fn screen_info(&self) -> Option<ScreenInfo>

Information about the monitor this window is on.

Source

pub fn cursor_pos(&self) -> Coord2D

Cached cursor position (updated via events or set_cursor_pos).

Source

pub fn set_cursor_pos(&mut self, pos: Coord2D)

Move the OS cursor and update the cached position.

Source

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.

Source

pub fn cursor_pos_normalized(&self) -> Coord2D

Cursor position normalized to 0..1 where (0,0) = bottom-left, (1,1) = top-right.

Source

pub fn is_cursor_inside(&self) -> bool

True if the cursor is inside the window client area (updated via events).

Source

pub fn is_cursor_visible(&self) -> bool

True if the cursor is visible (cached, not a live winit query).

Source

pub fn set_cursor_visible(&mut self, visible: bool)

Show or hide the cursor.

Source

pub fn toggle_cursor_visible(&mut self)

Toggle cursor visibility.

Source

pub fn is_cursor_grabbed(&self) -> bool

True if the cursor is grabbed (locked + hidden, for raw input).

Source

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.

Source

pub fn toggle_cursor_grab(&mut self)

Toggle cursor grab.

Source

pub fn is_cursor_confined(&self) -> bool

True if the cursor is confined (clamped to window, visible).

Source

pub fn set_cursor_confine(&mut self, confine: bool) -> Result<(), ()>

Confine or release the cursor. Returns Err(()) if unsupported.

Source

pub fn toggle_cursor_confine(&mut self)

Toggle cursor confine.

Source

pub fn is_cursor_loopback(&self) -> bool

True if cursor loopback (software edge-wrapping) is enabled.

Source

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.

Source

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§

Source§

impl Debug for Window

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more