Skip to main content

Module pixel

Module pixel 

Source
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 by prop_cache.rs; does not distinguish rem from em. Marked #[doc(hidden)].

Structs§

CssLogicalSize
Logical size in CSS logical coordinate system
NormalizedPercentage
A normalized percentage value (0.0 = 0%, 1.0 = 100%)
PhysicalSize
Physical size (always width x height, regardless of writing mode)
PixelNoValueGivenError
Wrapper for NoValueGiven error in pixel value parsing.
PixelValue
A CSS length value consisting of a numeric value and a unit (px, em, rem, %, etc.).
PixelValueNoPercent
Same as PixelValue, but doesn’t allow a “%” sign
ResolutionContext
Context information needed to properly resolve CSS units (em, rem, %) to pixels.

Enums§

CssPixelValueParseError
CssPixelValueParseErrorOwned
Owned version of CssPixelValueParseError.
OptionPixelValue
OptionPixelValueNoPercent
PixelValueOrSystem
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.
PixelValueWithAuto
PropertyContext
Specifies which property context we’re resolving for, to determine correct reference values
SystemMetricRef
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”