Struct bevy_window::WindowResolution
source · pub struct WindowResolution { /* private fields */ }
Expand description
Controls the size of a Window
Physical, logical and requested sizes
There are three sizes associated with a window:
- the physical size, which represents the actual height and width in physical pixels the window occupies on the monitor,
- the logical size, which represents the size that should be used to scale elements inside the window, measured in logical pixels,
- 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.
Scale factor
The reason logical size and physical size are separated and can be different is to account for the cases where:
- several monitors have different pixel densities,
- the user has set up a pixel density preference in its operating system,
- the Bevy
App
has specified a specific scale factor between both.
The factor between physical size and logical size can be retrieved with
WindowResolution::scale_factor
.
For the first two cases, a scale factor is set automatically by the operating
system through the window backend. You can get it with
WindowResolution::base_scale_factor
.
For the third case, you can override this automatic scale factor with
WindowResolution::set_scale_factor_override
.
Requested and obtained sizes
The logical size should be equal to the requested size after creating/resizing,
when possible.
The reason the requested size and logical size might be different
is because the corresponding physical size might exceed limits (either the
size limits of the monitor, or limits defined in WindowResizeConstraints
).
Note: The requested size is not kept in memory, for example requesting a size too big for the screen, making the logical size different from the requested size, and then setting a scale factor that makes the previous requested size within the limits of the screen will not get back that previous requested size.
Implementations§
source§impl WindowResolution
impl WindowResolution
sourcepub fn new(logical_width: f32, logical_height: f32) -> Self
pub fn new(logical_width: f32, logical_height: f32) -> Self
Creates a new WindowResolution
.
sourcepub fn with_scale_factor_override(self, scale_factor_override: f32) -> Self
pub fn with_scale_factor_override(self, scale_factor_override: f32) -> Self
Builder method for adding a scale factor override to the resolution.
sourcepub fn physical_width(&self) -> u32
pub fn physical_width(&self) -> u32
The window’s client area width in physical pixels.
sourcepub fn physical_height(&self) -> u32
pub fn physical_height(&self) -> u32
The window’s client area height in physical pixels.
sourcepub fn scale_factor(&self) -> f32
pub fn scale_factor(&self) -> f32
The ratio of physical pixels to logical pixels.
physical_pixels = logical_pixels * scale_factor
sourcepub fn base_scale_factor(&self) -> f32
pub fn base_scale_factor(&self) -> f32
The window scale factor as reported by the window backend.
This value is unaffected by WindowResolution::scale_factor_override
.
sourcepub fn scale_factor_override(&self) -> Option<f32>
pub fn scale_factor_override(&self) -> Option<f32>
The scale factor set with WindowResolution::set_scale_factor_override
.
This value may be different from the scale factor reported by the window backend.
sourcepub fn set_physical_resolution(&mut self, width: u32, height: u32)
pub fn set_physical_resolution(&mut self, width: u32, height: u32)
Set the window’s physical resolution.
This will ignore the scale factor setting, so most of the time you should
prefer to use WindowResolution::set
.
sourcepub fn set_scale_factor(&mut self, scale_factor: f32)
pub fn set_scale_factor(&mut self, scale_factor: f32)
Set the window’s scale factor, this may get overridden by the backend.
sourcepub fn set_scale_factor_override(&mut self, scale_factor_override: Option<f32>)
pub fn set_scale_factor_override(&mut self, scale_factor_override: Option<f32>)
Set the window’s scale factor, this will be used over what the backend decides.
This can change the logical and physical sizes if the resulting physical size is not within the limits.
Trait Implementations§
source§impl Clone for WindowResolution
impl Clone for WindowResolution
source§fn clone(&self) -> WindowResolution
fn clone(&self) -> WindowResolution
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for WindowResolution
impl Debug for WindowResolution
source§impl Default for WindowResolution
impl Default for WindowResolution
source§impl<I> From<[I; 2]> for WindowResolution
impl<I> From<[I; 2]> for WindowResolution
source§fn from([width, height]: [I; 2]) -> WindowResolution
fn from([width, height]: [I; 2]) -> WindowResolution
source§impl<I> From<(I, I)> for WindowResolution
impl<I> From<(I, I)> for WindowResolution
source§fn from((width, height): (I, I)) -> WindowResolution
fn from((width, height): (I, I)) -> WindowResolution
source§impl From<DVec2> for WindowResolution
impl From<DVec2> for WindowResolution
source§fn from(res: DVec2) -> WindowResolution
fn from(res: DVec2) -> WindowResolution
source§impl From<Vec2> for WindowResolution
impl From<Vec2> for WindowResolution
source§fn from(res: Vec2) -> WindowResolution
fn from(res: Vec2) -> WindowResolution
source§impl FromReflect for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath,
Option<f32>: FromReflect + TypePath,
f32: FromReflect + TypePath,
impl FromReflect for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath,
Option<f32>: FromReflect + TypePath,
f32: FromReflect + TypePath,
source§fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
Self
from a reflected value.source§fn take_from_reflect(
reflect: Box<dyn Reflect>
) -> Result<Self, Box<dyn Reflect>>
fn take_from_reflect( reflect: Box<dyn Reflect> ) -> Result<Self, Box<dyn Reflect>>
Self
using,
constructing the value using from_reflect
if that fails. Read moresource§impl GetTypeRegistration for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath,
Option<f32>: FromReflect + TypePath,
f32: FromReflect + TypePath,
impl GetTypeRegistration for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath,
Option<f32>: FromReflect + TypePath,
f32: FromReflect + TypePath,
source§impl PartialEq for WindowResolution
impl PartialEq for WindowResolution
source§fn eq(&self, other: &WindowResolution) -> bool
fn eq(&self, other: &WindowResolution) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Reflect for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath,
Option<f32>: FromReflect + TypePath,
f32: FromReflect + TypePath,
impl Reflect for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath,
Option<f32>: FromReflect + TypePath,
f32: FromReflect + TypePath,
source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any
.source§fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
source§fn as_reflect(&self) -> &dyn Reflect
fn as_reflect(&self) -> &dyn Reflect
source§fn as_reflect_mut(&mut self) -> &mut dyn Reflect
fn as_reflect_mut(&mut self) -> &mut dyn Reflect
source§fn clone_value(&self) -> Box<dyn Reflect>
fn clone_value(&self) -> Box<dyn Reflect>
Reflect
trait object. Read moresource§fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
source§fn reflect_owned(self: Box<Self>) -> ReflectOwned
fn reflect_owned(self: Box<Self>) -> ReflectOwned
source§fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
source§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
source§impl Struct for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath,
Option<f32>: FromReflect + TypePath,
f32: FromReflect + TypePath,
impl Struct for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath,
Option<f32>: FromReflect + TypePath,
f32: FromReflect + TypePath,
source§fn field(&self, name: &str) -> Option<&dyn Reflect>
fn field(&self, name: &str) -> Option<&dyn Reflect>
name
as a &dyn Reflect
.source§fn field_mut(&mut self, name: &str) -> Option<&mut dyn Reflect>
fn field_mut(&mut self, name: &str) -> Option<&mut dyn Reflect>
name
as a
&mut dyn Reflect
.source§fn field_at(&self, index: usize) -> Option<&dyn Reflect>
fn field_at(&self, index: usize) -> Option<&dyn Reflect>
index
as a
&dyn Reflect
.source§fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
index
as a &mut dyn Reflect
.source§fn name_at(&self, index: usize) -> Option<&str>
fn name_at(&self, index: usize) -> Option<&str>
index
.source§fn iter_fields(&self) -> FieldIter<'_>
fn iter_fields(&self) -> FieldIter<'_>
source§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
.source§impl TypePath for WindowResolution
impl TypePath for WindowResolution
source§fn type_path() -> &'static str
fn type_path() -> &'static str
source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
source§impl Typed for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath,
Option<f32>: FromReflect + TypePath,
f32: FromReflect + TypePath,
impl Typed for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath,
Option<f32>: FromReflect + TypePath,
f32: FromReflect + TypePath,
impl StructuralPartialEq for WindowResolution
Auto Trait Implementations§
impl RefUnwindSafe for WindowResolution
impl Send for WindowResolution
impl Sync for WindowResolution
impl Unpin for WindowResolution
impl UnwindSafe for WindowResolution
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
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.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
.source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
.source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
.source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.source§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
source§impl<T> GetPath for T
impl<T> GetPath for T
source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>
) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p> ) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read moresource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p> ) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read moresource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path
. Read moresource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read more