#[repr(C)]pub struct PixelValue {
pub metric: SizeMetric,
pub number: FloatValue,
}Fields§
§metric: SizeMetric§number: FloatValueImplementations§
Source§impl PixelValue
impl PixelValue
pub fn scale_for_dpi(&mut self, scale_factor: f32)
Source§impl PixelValue
impl PixelValue
pub const fn zero() -> Self
Sourcepub const fn const_px(value: isize) -> Self
pub const fn const_px(value: isize) -> Self
Same as PixelValue::px(), but only accepts whole numbers,
since using f32 in const fn is not yet stabilized.
Sourcepub const fn const_em(value: isize) -> Self
pub const fn const_em(value: isize) -> Self
Same as PixelValue::em(), but only accepts whole numbers,
since using f32 in const fn is not yet stabilized.
Sourcepub const fn const_em_fractional(pre_comma: isize, post_comma: isize) -> Self
pub const fn const_em_fractional(pre_comma: isize, post_comma: isize) -> Self
Creates an em value from a fractional number in const context.
§Arguments
pre_comma- The integer part (e.g., 1 for 1.5em)post_comma- The fractional part as digits (e.g., 5 for 0.5em, 83 for 0.83em)
§Examples
// 1.5em = const_em_fractional(1, 5)
// 0.83em = const_em_fractional(0, 83)
// 1.17em = const_em_fractional(1, 17)Sourcepub const fn const_pt(value: isize) -> Self
pub const fn const_pt(value: isize) -> Self
Same as PixelValue::pt(), but only accepts whole numbers,
since using f32 in const fn is not yet stabilized.
Sourcepub const fn const_pt_fractional(pre_comma: isize, post_comma: isize) -> Self
pub const fn const_pt_fractional(pre_comma: isize, post_comma: isize) -> Self
Creates a pt value from a fractional number in const context.
Sourcepub const fn const_percent(value: isize) -> Self
pub const fn const_percent(value: isize) -> Self
Same as PixelValue::pt(), but only accepts whole numbers,
since using f32 in const fn is not yet stabilized.
Sourcepub const fn const_in(value: isize) -> Self
pub const fn const_in(value: isize) -> Self
Same as PixelValue::in(), but only accepts whole numbers,
since using f32 in const fn is not yet stabilized.
Sourcepub const fn const_cm(value: isize) -> Self
pub const fn const_cm(value: isize) -> Self
Same as PixelValue::in(), but only accepts whole numbers,
since using f32 in const fn is not yet stabilized.
Sourcepub const fn const_mm(value: isize) -> Self
pub const fn const_mm(value: isize) -> Self
Same as PixelValue::in(), but only accepts whole numbers,
since using f32 in const fn is not yet stabilized.
pub const fn const_from_metric(metric: SizeMetric, value: isize) -> Self
Sourcepub const fn const_from_metric_fractional(
metric: SizeMetric,
pre_comma: isize,
post_comma: isize,
) -> Self
pub const fn const_from_metric_fractional( metric: SizeMetric, pre_comma: isize, post_comma: isize, ) -> Self
Creates a PixelValue from a fractional number in const context.
§Arguments
metric- The size metric (Px, Em, Pt, etc.)pre_comma- The integer partpost_comma- The fractional part as digits
pub fn px(value: f32) -> Self
pub fn em(value: f32) -> Self
pub fn inch(value: f32) -> Self
pub fn cm(value: f32) -> Self
pub fn mm(value: f32) -> Self
pub fn pt(value: f32) -> Self
pub fn percent(value: f32) -> Self
pub fn rem(value: f32) -> Self
pub fn from_metric(metric: SizeMetric, value: f32) -> Self
pub fn interpolate(&self, other: &Self, t: f32) -> Self
Sourcepub fn to_percent(&self) -> Option<NormalizedPercentage>
pub fn to_percent(&self) -> Option<NormalizedPercentage>
Returns the value of the SizeMetric as a normalized percentage (0.0 = 0%, 1.0 = 100%)
Returns Some(NormalizedPercentage) if this is a percentage value, None otherwise.
The returned NormalizedPercentage is already normalized to 0.0-1.0 range,
so you should multiply it directly with the containing block size.
Sourcepub fn resolve_with_context(
&self,
context: &ResolutionContext,
property_context: PropertyContext,
) -> f32
pub fn resolve_with_context( &self, context: &ResolutionContext, property_context: PropertyContext, ) -> f32
Resolve this value to pixels using proper CSS context.
This is the CORRECT way to resolve CSS units. It properly handles:
- em units: Uses element’s own font-size (or parent’s for font-size property)
- rem units: Uses root element’s font-size
- % units: Uses property-appropriate reference (containing block width/height, element size, etc.)
- Absolute units: px, pt, in, cm, mm (already correct)
§Arguments
context- Resolution context with font sizes and dimensionsproperty_context- Which property we’re resolving for (affects % and em resolution)
Trait Implementations§
Source§impl Clone for PixelValue
impl Clone for PixelValue
Source§fn clone(&self) -> PixelValue
fn clone(&self) -> PixelValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more