scene_management

Struct DisplayMetrics

Source
pub struct DisplayMetrics { /* private fields */ }
Expand description

DisplayMetrics encapsulate data associated with a display device.

DisplayMetrics are created from a display’s width and height in pixels. Pixel density and expected viewing distance can be supplied for more accurate metrics (e.g., [width_in_mm] uses the display’s pixel density to give the correct width).

If density or viewing distance is not supplied, default values are calculated based on the display dimensions.

Implementations§

Source§

impl DisplayMetrics

Source

pub fn new( size_in_pixels: Size, density_in_pixels_per_mm: Option<f32>, viewing_distance: Option<ViewingDistance>, display_rotation: Option<DisplayRotation>, ) -> DisplayMetrics

Creates a new DisplayMetrics struct.

The width and height of the display in pixels are required to construct sensible display metrics. Defaults can be computed for the other metrics, but they may not match expectations.

For example, a default display pixel density can be determined based on width and height in pixels, but it’s unlikely to match the actual density of the display.

§Parameters
  • size_in_pixels: The size of the display, in pixels.
  • density_in_pixels_per_mm: The density of the display, in pixels per mm. If no density is provided, a best guess is made based on the width and height of the display.
  • viewing_distance: The expected viewing distance for the display (i.e., how far away the user is expected to be from the display) in mm. Defaults to [DisplayMetrics::DEFAULT_VIEWING_DISTANCE]. This is used to compute the ratio of pixels per pip.
  • display_rotation: The rotation of the display, counter-clockwise, in 90-degree increments.
Source

pub fn pixels_per_pip(&self) -> f32

Returns the number of pixels per pip.

Source

pub fn pips_per_mm(&self) -> f32

Returns the number of pips per millimeter.

Source

pub fn mm_per_pip(&self) -> f32

Returns the number of millimeters per pip.

Source

pub fn width_in_pixels(&self) -> u32

Returns the width of the display in pixels.

Source

pub fn height_in_pixels(&self) -> u32

Returns the height of the display in pixels.

Source

pub fn size_in_pixels(&self) -> Size

Returns the size of the display in pixels.

Source

pub fn width_in_pips(&self) -> f32

Returns the width of the display in pips.

Source

pub fn height_in_pips(&self) -> f32

Returns the height of the display in pips.

Source

pub fn size_in_pips(&self) -> Size

Returns the size of the display in pips.

Source

pub fn width_in_mm(&self) -> f32

Returns the width of the display in millimeters.

Source

pub fn height_in_mm(&self) -> f32

Returns the height of the display in millimeters.

Source

pub fn size_in_mm(&self) -> Size

Returns the size of the display in millimeters.

Source

pub fn rotation(&self) -> DisplayRotation

Source

pub fn rotation_in_degrees(&self) -> u32

Source

pub fn viewing_distance(&self) -> ViewingDistance

Source

pub fn viewing_distance_in_mm(&self) -> f32

Source

pub fn physical_pixel_ratio(&self) -> f32

Trait Implementations§

Source§

impl Clone for DisplayMetrics

Source§

fn clone(&self) -> DisplayMetrics

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DisplayMetrics

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Copy for DisplayMetrics

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> AsRcAny for T
where T: Any,

Source§

fn as_rc_any(self: Rc<T>) -> Rc<dyn Any>

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoAny for T
where T: 'static + Send + Sync,

Source§

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

Cast the given object into a dyn std::any::Any.
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<St> WithTag for St

Source§

fn tagged<T>(self, tag: T) -> Tagged<T, St>

Produce a new stream from this one which yields item tupled with a constant tag