PixelSize
struct · ferroui-base · v0.5.0
struct PixelSize
Represents a size in device pixels.
Conversions from floating point saturate at the i32 range (NaN becomes 0).
Members
widthheightEMPTYnewaspect_ratioparsetry_parseequalswith_widthwith_heightto_sizeto_size_vectorto_size_with_dpito_size_with_dpi_vectorfrom_sizefrom_size_ceilingfrom_size_vectorfrom_size_with_dpifrom_size_with_dpi_vector
width
width: i32
The width.
height
height: i32
The height.
EMPTY
const EMPTY: PixelSize
A size representing zero.
new
const fn new(width: i32, height: i32) -> Self
Initializes a new instance of the PixelSize structure.
aspect_ratio
fn aspect_ratio(self: &Self) -> f64
Gets the aspect ratio of the size.
parse
fn parse(s: &str) -> Result<Self, FormatError>
Parses a PixelSize string ("width, height").
try_parse
fn try_parse(source: &str) -> Option<Self>
Tries to parse a PixelSize string. Every kind of malformed input yields
None (the reference implementation raises a format error for some of them,
e.g. trailing tokens; there is no such distinction here).
equals
const fn equals(self: &Self, other: PixelSize) -> bool
Returns a boolean indicating whether the size is equal to the other given size.
with_width
const fn with_width(self: &Self, width: i32) -> PixelSize
Returns a new PixelSize with the same height and the specified width.
with_height
const fn with_height(self: &Self, height: i32) -> PixelSize
Returns a new PixelSize with the same width and the specified height.
to_size
fn to_size(self: &Self, scale: f64) -> Size
Converts the PixelSize to a device-independent Size using the
specified scaling factor.
to_size_vector
fn to_size_vector(self: &Self, scale: Vector) -> Size
Converts the PixelSize to a device-independent Size using the
specified per-axis scaling factor.
to_size_with_dpi
fn to_size_with_dpi(self: &Self, dpi: f64) -> Size
Converts the PixelSize to a device-independent Size using the
specified dots per inch (DPI).
to_size_with_dpi_vector
fn to_size_with_dpi_vector(self: &Self, dpi: Vector) -> Size
Converts the PixelSize to a device-independent Size using the
specified per-axis dots per inch (DPI).
from_size
fn from_size(size: Size, scale: f64) -> PixelSize
Converts a Size to device pixels using the specified scaling factor,
rounding up.
from_size_ceiling
fn from_size_ceiling(size: Size, scale: f64) -> PixelSize
A tolerant ceiling variant of from_size: a value within
1e-6 of an integer snaps to that integer, otherwise it is rounded up.
This prevents floating-point artifacts (e.g. 24.0000001) from producing an
extra pixel while still guaranteeing the pixel size covers the logical size.
from_size_vector
fn from_size_vector(size: Size, scale: Vector) -> PixelSize
Converts a Size to device pixels using the specified per-axis scaling
factor, rounding up.
from_size_with_dpi
fn from_size_with_dpi(size: Size, dpi: f64) -> PixelSize
Converts a Size to device pixels using the specified dots per inch (DPI).
from_size_with_dpi_vector
fn from_size_with_dpi_vector(size: Size, dpi: Vector) -> PixelSize
Converts a Size to device pixels using the specified per-axis dots per inch (DPI).
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeResourceKeyObjectPropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedToStringErasedDestructorIntoEitherMarkupTypedValueTypeRegistrationCloneCopyDebugStructuralPartialEqPartialEqEqHashDefaultFromStrDisplay
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.