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
impl DisplayMetrics
Sourcepub fn new(
size_in_pixels: Size,
density_in_pixels_per_mm: Option<f32>,
viewing_distance: Option<ViewingDistance>,
display_rotation: Option<DisplayRotation>,
) -> DisplayMetrics
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.
Sourcepub fn pixels_per_pip(&self) -> f32
pub fn pixels_per_pip(&self) -> f32
Returns the number of pixels per pip.
Sourcepub fn pips_per_mm(&self) -> f32
pub fn pips_per_mm(&self) -> f32
Returns the number of pips per millimeter.
Sourcepub fn mm_per_pip(&self) -> f32
pub fn mm_per_pip(&self) -> f32
Returns the number of millimeters per pip.
Sourcepub fn width_in_pixels(&self) -> u32
pub fn width_in_pixels(&self) -> u32
Returns the width of the display in pixels.
Sourcepub fn height_in_pixels(&self) -> u32
pub fn height_in_pixels(&self) -> u32
Returns the height of the display in pixels.
Sourcepub fn size_in_pixels(&self) -> Size
pub fn size_in_pixels(&self) -> Size
Returns the size of the display in pixels.
Sourcepub fn width_in_pips(&self) -> f32
pub fn width_in_pips(&self) -> f32
Returns the width of the display in pips.
Sourcepub fn height_in_pips(&self) -> f32
pub fn height_in_pips(&self) -> f32
Returns the height of the display in pips.
Sourcepub fn size_in_pips(&self) -> Size
pub fn size_in_pips(&self) -> Size
Returns the size of the display in pips.
Sourcepub fn width_in_mm(&self) -> f32
pub fn width_in_mm(&self) -> f32
Returns the width of the display in millimeters.
Sourcepub fn height_in_mm(&self) -> f32
pub fn height_in_mm(&self) -> f32
Returns the height of the display in millimeters.
Sourcepub fn size_in_mm(&self) -> Size
pub fn size_in_mm(&self) -> Size
Returns the size of the display in millimeters.
pub fn rotation(&self) -> DisplayRotation
pub fn rotation_in_degrees(&self) -> u32
pub fn viewing_distance(&self) -> ViewingDistance
pub fn viewing_distance_in_mm(&self) -> f32
pub fn physical_pixel_ratio(&self) -> f32
Trait Implementations§
Source§impl Clone for DisplayMetrics
impl Clone for DisplayMetrics
Source§fn clone(&self) -> DisplayMetrics
fn clone(&self) -> DisplayMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DisplayMetrics
impl Debug for DisplayMetrics
impl Copy for DisplayMetrics
Auto Trait Implementations§
impl Freeze for DisplayMetrics
impl RefUnwindSafe for DisplayMetrics
impl Send for DisplayMetrics
impl Sync for DisplayMetrics
impl Unpin for DisplayMetrics
impl UnwindSafe for DisplayMetrics
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
)