pub struct Window { /* private fields */ }
Expand description
An operating system window that can present content and receive user input.
Window Sizes
There are three sizes associated with a window. The physical size which is the height and width in physical pixels on the monitor. The logical size which is the physical size scaled by an operating system provided factor to account for monitors with differing pixel densities or user preference. And the requested size, measured in logical pixels, which is the value submitted to the API when creating the window, or requesting that it be resized.
The actual size, in logical pixels, of the window may not match the requested size due to operating system limits on the window size, or the quantization of the logical size when converting the physical size to the logical size through the scaling factor.
Implementations
impl Window
impl Window
pub fn new(
id: WindowId,
window_descriptor: &WindowDescriptor,
physical_width: u32,
physical_height: u32,
scale_factor: f64,
position: Option<IVec2>,
raw_window_handle: RawWindowHandle
) -> Window
pub fn id(&self) -> WindowId
pub fn requested_width(&self) -> f32
pub fn requested_width(&self) -> f32
The requested window client area width in logical pixels from window creation or the last call to set_resolution.
This may differ from the actual width depending on OS size limits and the scaling factor for high DPI monitors.
pub fn requested_height(&self) -> f32
pub fn requested_height(&self) -> f32
The requested window client area height in logical pixels from window creation or the last call to set_resolution.
This may differ from the actual width depending on OS size limits and the scaling factor for high DPI monitors.
pub fn physical_width(&self) -> u32
pub fn physical_width(&self) -> u32
The window’s client area width in physical pixels.
pub fn physical_height(&self) -> u32
pub fn physical_height(&self) -> u32
The window’s client area height in physical pixels.
pub fn resize_constraints(&self) -> WindowResizeConstraints
pub fn resize_constraints(&self) -> WindowResizeConstraints
The window’s client resize constraint in logical pixels.
pub fn set_maximized(&mut self, maximized: bool)
pub fn set_minimized(&mut self, minimized: bool)
pub fn set_minimized(&mut self, minimized: bool)
Sets the window to minimized or back.
Platform-specific
- iOS / Android / Web: Unsupported.
- Wayland: Un-minimize is unsupported.
pub fn set_position(&mut self, position: IVec2)
pub fn set_position(&mut self, position: IVec2)
Modifies the position of the window in physical pixels.
Note that the top-left hand corner of the desktop is not necessarily the same as the screen. If the user uses a desktop with multiple monitors, the top-left hand corner of the desktop is the top-left hand corner of the monitor at the top-left of the desktop. This automatically un-maximizes the window if it’s maximized.
Platform-specific
- iOS: Can only be called on the main thread. Sets the top left coordinates of the window in the screen space coordinate system.
- Web: Sets the top-left coordinates relative to the viewport.
- Android / Wayland: Unsupported.
pub fn set_resize_constraints(
&mut self,
resize_constraints: WindowResizeConstraints
)
pub fn set_resize_constraints(
&mut self,
resize_constraints: WindowResizeConstraints
)
Modifies the minimum and maximum window bounds for resizing in logical pixels.
pub fn set_resolution(&mut self, width: f32, height: f32)
pub fn set_resolution(&mut self, width: f32, height: f32)
Request the OS to resize the window such the the client area matches the specified width and height.
pub fn set_scale_factor_override(&mut self, scale_factor: Option<f64>)
pub fn set_scale_factor_override(&mut self, scale_factor: Option<f64>)
Override the os-reported scaling factor
pub fn update_scale_factor_from_backend(&mut self, scale_factor: f64)
pub fn update_actual_size_from_backend(
&mut self,
physical_width: u32,
physical_height: u32
)
pub fn update_actual_position_from_backend(&mut self, position: IVec2)
pub fn scale_factor(&self) -> f64
pub fn scale_factor(&self) -> f64
The ratio of physical pixels to logical pixels
physical_pixels = logical_pixels * scale_factor
pub fn backend_scale_factor(&self) -> f64
pub fn backend_scale_factor(&self) -> f64
The window scale factor as reported by the window backend. This value is unaffected by scale_factor_override.
pub fn scale_factor_override(&self) -> Option<f64>
pub fn title(&self) -> &str
pub fn set_title(&mut self, title: String)
pub fn vsync(&self) -> bool
pub fn set_vsync(&mut self, vsync: bool)
pub fn resizable(&self) -> bool
pub fn set_resizable(&mut self, resizable: bool)
pub fn decorations(&self) -> bool
pub fn set_decorations(&mut self, decorations: bool)
pub fn cursor_locked(&self) -> bool
pub fn set_cursor_lock_mode(&mut self, lock_mode: bool)
pub fn cursor_visible(&self) -> bool
pub fn set_cursor_visibility(&mut self, visibile_mode: bool)
pub fn cursor_icon(&self) -> CursorIcon
pub fn set_cursor_icon(&mut self, icon: CursorIcon)
pub fn physical_cursor_position(&self) -> Option<DVec2>
pub fn physical_cursor_position(&self) -> Option<DVec2>
The current mouse position, in physical pixels.
pub fn cursor_position(&self) -> Option<Vec2>
pub fn cursor_position(&self) -> Option<Vec2>
The current mouse position, in logical pixels, taking into account the screen scale factor.
pub fn set_cursor_position(&mut self, position: Vec2)
pub fn update_focused_status_from_backend(&mut self, focused: bool)
pub fn update_cursor_physical_position_from_backend(
&mut self,
cursor_position: Option<DVec2>
)
pub fn mode(&self) -> WindowMode
pub fn set_mode(&mut self, mode: WindowMode)
pub fn drain_commands(&mut self) -> impl Iterator<Item = WindowCommand>
pub fn is_focused(&self) -> bool
pub fn raw_window_handle(&self) -> RawWindowHandleWrapper
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Window
impl Send for Window
impl Sync for Window
impl Unpin for Window
impl UnwindSafe for Window
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<F, A>impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<F, A>impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
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
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn as_any(&self) -> &(dyn Any + 'static)
pub 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. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub 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. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more