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(physical_width: f32, physical_height: f32) -> Self
pub fn new(physical_width: f32, physical_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 physical_size(&self) -> UVec2
pub fn physical_size(&self) -> UVec2
The window’s client size 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<'de> Deserialize<'de> for WindowResolution
impl<'de> Deserialize<'de> for WindowResolution
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 + RegisterForReflection,
Option<f32>: FromReflect + TypePath + RegisterForReflection,
f32: FromReflect + TypePath + RegisterForReflection,
impl FromReflect for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath + RegisterForReflection,
Option<f32>: FromReflect + TypePath + RegisterForReflection,
f32: FromReflect + TypePath + RegisterForReflection,
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 + RegisterForReflection,
Option<f32>: FromReflect + TypePath + RegisterForReflection,
f32: FromReflect + TypePath + RegisterForReflection,
impl GetTypeRegistration for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath + RegisterForReflection,
Option<f32>: FromReflect + TypePath + RegisterForReflection,
f32: FromReflect + TypePath + RegisterForReflection,
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration
for this type.Source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
Source§impl PartialEq for WindowResolution
impl PartialEq for WindowResolution
Source§impl Reflect for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath + RegisterForReflection,
Option<f32>: FromReflect + TypePath + RegisterForReflection,
f32: FromReflect + TypePath + RegisterForReflection,
impl Reflect for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath + RegisterForReflection,
Option<f32>: FromReflect + TypePath + RegisterForReflection,
f32: FromReflect + TypePath + RegisterForReflection,
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 apply(&mut self, value: &(dyn Reflect + 'static))
fn apply(&mut self, value: &(dyn Reflect + 'static))
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 Serialize for WindowResolution
impl Serialize for WindowResolution
Source§impl Struct for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath + RegisterForReflection,
Option<f32>: FromReflect + TypePath + RegisterForReflection,
f32: FromReflect + TypePath + RegisterForReflection,
impl Struct for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath + RegisterForReflection,
Option<f32>: FromReflect + TypePath + RegisterForReflection,
f32: FromReflect + TypePath + RegisterForReflection,
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 + RegisterForReflection,
Option<f32>: FromReflect + TypePath + RegisterForReflection,
f32: FromReflect + TypePath + RegisterForReflection,
impl Typed for WindowResolutionwhere
Self: Any + Send + Sync,
u32: FromReflect + TypePath + RegisterForReflection,
Option<f32>: FromReflect + TypePath + RegisterForReflection,
f32: FromReflect + TypePath + RegisterForReflection,
impl StructuralPartialEq for WindowResolution
Auto Trait Implementations§
impl Freeze for WindowResolution
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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