Struct bevy::window::WindowResolution
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§
§impl WindowResolution
impl WindowResolution
pub fn new(logical_width: f32, logical_height: f32) -> WindowResolution
pub fn new(logical_width: f32, logical_height: f32) -> WindowResolution
Creates a new WindowResolution
.
pub fn with_scale_factor_override(
self,
scale_factor_override: f64
) -> WindowResolution
pub fn with_scale_factor_override( self, scale_factor_override: f64 ) -> WindowResolution
Builder method for adding a scale factor override to the resolution.
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 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 base_scale_factor(&self) -> f64
pub fn base_scale_factor(&self) -> f64
The window scale factor as reported by the window backend.
This value is unaffected by WindowResolution::scale_factor_override
.
pub fn scale_factor_override(&self) -> Option<f64>
pub fn scale_factor_override(&self) -> Option<f64>
The scale factor set with WindowResolution::set_scale_factor_override
.
This value may be different from the scale factor reported by the window backend.
pub 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
.
pub fn set_scale_factor(&mut self, scale_factor: f64)
pub fn set_scale_factor(&mut self, scale_factor: f64)
Set the window’s scale factor, this may get overridden by the backend.
pub fn set_scale_factor_override(&mut self, scale_factor_override: Option<f64>)
pub fn set_scale_factor_override(&mut self, scale_factor_override: Option<f64>)
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§
§impl Clone for WindowResolution
impl Clone for WindowResolution
§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 more§impl Debug for WindowResolution
impl Debug for WindowResolution
§impl Default for WindowResolution
impl Default for WindowResolution
§fn default() -> WindowResolution
fn default() -> WindowResolution
§impl<'de> Deserialize<'de> for WindowResolution
impl<'de> Deserialize<'de> for WindowResolution
§fn deserialize<__D>(
__deserializer: __D
) -> Result<WindowResolution, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<WindowResolution, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
§impl<I> From<[I; 2]> for WindowResolutionwhere
I: Into<f32>,
impl<I> From<[I; 2]> for WindowResolutionwhere I: Into<f32>,
§fn from(_: [I; 2]) -> WindowResolution
fn from(_: [I; 2]) -> WindowResolution
§impl<I> From<(I, I)> for WindowResolutionwhere
I: Into<f32>,
impl<I> From<(I, I)> for WindowResolutionwhere I: Into<f32>,
§fn from(_: (I, I)) -> WindowResolution
fn from(_: (I, I)) -> WindowResolution
§impl From<DVec2> for WindowResolution
impl From<DVec2> for WindowResolution
§fn from(res: DVec2) -> WindowResolution
fn from(res: DVec2) -> WindowResolution
§impl From<Vec2> for WindowResolution
impl From<Vec2> for WindowResolution
§fn from(res: Vec2) -> WindowResolution
fn from(res: Vec2) -> WindowResolution
§impl FromReflect for WindowResolutionwhere
u32: FromReflect + TypePath,
Option<f64>: FromReflect + TypePath,
f64: FromReflect + TypePath,
impl FromReflect for WindowResolutionwhere u32: FromReflect + TypePath, Option<f64>: FromReflect + TypePath, f64: FromReflect + TypePath,
§fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<WindowResolution>
fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<WindowResolution>
Self
from a reflected value.§impl GetTypeRegistration for WindowResolutionwhere
u32: FromReflect + TypePath,
Option<f64>: FromReflect + TypePath,
f64: FromReflect + TypePath,
impl GetTypeRegistration for WindowResolutionwhere u32: FromReflect + TypePath, Option<f64>: FromReflect + TypePath, f64: FromReflect + TypePath,
§impl PartialEq<WindowResolution> for WindowResolution
impl PartialEq<WindowResolution> for WindowResolution
§fn eq(&self, other: &WindowResolution) -> bool
fn eq(&self, other: &WindowResolution) -> bool
self
and other
values to be equal, and is used
by ==
.§impl Reflect for WindowResolutionwhere
u32: FromReflect + TypePath,
Option<f64>: FromReflect + TypePath,
f64: FromReflect + TypePath,
impl Reflect for WindowResolutionwhere u32: FromReflect + TypePath, Option<f64>: FromReflect + TypePath, f64: FromReflect + TypePath,
§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
§fn into_any(self: Box<WindowResolution, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<WindowResolution, Global>) -> Box<dyn Any, Global>
Box<dyn Any>
.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any
.§fn into_reflect(self: Box<WindowResolution, Global>) -> Box<dyn Reflect, Global>
fn into_reflect(self: Box<WindowResolution, Global>) -> Box<dyn Reflect, Global>
§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
§fn clone_value(&self) -> Box<dyn Reflect, Global>
fn clone_value(&self) -> Box<dyn Reflect, Global>
Reflect
trait object. Read more§fn set(
&mut self,
value: Box<dyn Reflect, Global>
) -> Result<(), Box<dyn Reflect, Global>>
fn set( &mut self, value: Box<dyn Reflect, Global> ) -> Result<(), Box<dyn Reflect, Global>>
§fn apply(&mut self, value: &(dyn Reflect + 'static))
fn apply(&mut self, value: &(dyn Reflect + 'static))
§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
§fn reflect_owned(self: Box<WindowResolution, Global>) -> ReflectOwned
fn reflect_owned(self: Box<WindowResolution, Global>) -> ReflectOwned
§fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
§impl Serialize for WindowResolution
impl Serialize for WindowResolution
§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,
§impl Struct for WindowResolutionwhere
u32: FromReflect + TypePath,
Option<f64>: FromReflect + TypePath,
f64: FromReflect + TypePath,
impl Struct for WindowResolutionwhere u32: FromReflect + TypePath, Option<f64>: FromReflect + TypePath, f64: FromReflect + TypePath,
§fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>
name
as a &dyn Reflect
.§fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>
fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>
name
as a
&mut dyn Reflect
.§fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>
index
as a
&dyn Reflect
.§fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
index
as a &mut dyn Reflect
.§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
.§impl TypePath for WindowResolutionwhere
u32: FromReflect + TypePath,
Option<f64>: FromReflect + TypePath,
f64: FromReflect + TypePath,
impl TypePath for WindowResolutionwhere u32: FromReflect + TypePath, Option<f64>: FromReflect + TypePath, f64: FromReflect + TypePath,
§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
§impl Typed for WindowResolutionwhere
u32: FromReflect + TypePath,
Option<f64>: FromReflect + TypePath,
f64: FromReflect + TypePath,
impl Typed for WindowResolutionwhere u32: FromReflect + TypePath, Option<f64>: FromReflect + TypePath, f64: 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§
§impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
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
.§fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§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.§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.§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere T: TypePath,
§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
.§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
.§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
.§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.§impl<T> GetPath for Twhere
T: Reflect + ?Sized,
impl<T> GetPath for Twhere T: Reflect + ?Sized,
§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 more§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 more§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 more§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§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for Pwhere
R: Read + ReadEndian<P>,
P: Default,
impl<R, P> ReadPrimitive<R> for Pwhere R: Read + ReadEndian<P>, P: Default,
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.