Expand description
CSS length and pixel value types, parsing, and unit resolution.
Defines PixelValue (a numeric value + CSS unit like px, em, rem, %),
ResolutionContext (contextual information for resolving relative units),
and PropertyContext (which property is being resolved, affecting % and em semantics).
Resolution paths:
resolve_with_context()— the correct method for new code; properly distinguishes em vs rem, and resolves % based on property type per the CSS spec.to_pixels_internal()— legacy fallback used byprop_cache.rs; does not distinguish rem from em. Marked#[doc(hidden)].
Structs§
- CssLogical
Size - Logical size in CSS logical coordinate system
- Normalized
Percentage - A normalized percentage value (0.0 = 0%, 1.0 = 100%)
- Physical
Size - Physical size (always width x height, regardless of writing mode)
- Pixel
NoValue Given Error - Wrapper for NoValueGiven error in pixel value parsing.
- Pixel
Value - A CSS length value consisting of a numeric value and a unit (px, em, rem, %, etc.).
- Pixel
Value NoPercent - Same as PixelValue, but doesn’t allow a “%” sign
- Resolution
Context - Context information needed to properly resolve CSS units (em, rem, %) to pixels.
Enums§
- CssPixel
Value Parse Error - CssPixel
Value Parse Error Owned - Owned version of CssPixelValueParseError.
- Option
Pixel Value - Option
Pixel Value NoPercent - Pixel
Value OrSystem - A pixel value reference that can be either a concrete value or a system metric. System metrics are lazily evaluated at runtime based on the user’s system theme.
- Pixel
Value With Auto - Property
Context - Specifies which property context we’re resolving for, to determine correct reference values
- System
Metric Ref - Reference to a specific system metric value. These are resolved at runtime based on the user’s system preferences.
Constants§
- DEFAULT_
FONT_ SIZE - Default font size in pixels (16px), matching the CSS “medium” keyword and all major browser defaults (CSS 2.1 §15.7).
- MEDIUM_
BORDER_ THICKNESS - border-width: medium = 3px (per CSS spec, default)
- PT_
TO_ PX - Conversion factor from points to pixels (1pt = 1/72 inch, 1in = 96px, therefore 1pt = 96/72 px)
- THICK_
BORDER_ THICKNESS - border-width: thick = 5px (per CSS spec)
- THIN_
BORDER_ THICKNESS - border-width: thin = 1px (per CSS spec)
Functions§
- parse_
pixel_ value - parse_
pixel_ value_ no_ percent - parse_
pixel_ value_ or_ system - Parse a pixel value that may include system metric references.
- parse_
pixel_ value_ with_ auto - Parses a pixel value, but also tries values like “auto”, “initial”, “inherit” and “none”