pub struct ResolutionContext {
pub element_font_size: f32,
pub parent_font_size: f32,
pub root_font_size: f32,
pub containing_block_size: PhysicalSize,
pub element_size: Option<PhysicalSize>,
pub viewport_size: PhysicalSize,
}Expand description
Context information needed to properly resolve CSS units (em, rem, %) to pixels.
This struct contains all the contextual information that PixelValue::resolve()
needs to correctly convert relative units according to the CSS specification:
-
em units: For most properties, em refers to the element’s own computed font-size. For the font-size property itself, em refers to the parent’s computed font-size.
-
rem units: Always refer to the root element’s computed font-size.
-
% units: Percentage resolution depends on the property:
- Width/height: relative to containing block dimensions
- Margin/padding: relative to containing block width (even top/bottom!)
- Border-radius: relative to element’s own border box dimensions
- Font-size: relative to parent’s font-size
Fields§
§element_font_size: f32The computed font-size of the current element (for em in non-font properties)
parent_font_size: f32The computed font-size of the parent element (for em in font-size property)
root_font_size: f32The computed font-size of the root element (for rem units)
containing_block_size: PhysicalSizeThe containing block dimensions (for % in width/height/margins/padding)
element_size: Option<PhysicalSize>The element’s own border box size (for % in border-radius, transforms) May be None during first layout pass before size is determined
viewport_size: PhysicalSizeThe viewport size in CSS pixels (for vw, vh, vmin, vmax units) This is the layout viewport size, not physical screen size
Implementations§
Source§impl ResolutionContext
impl ResolutionContext
Sourcepub const fn default_const() -> Self
pub const fn default_const() -> Self
Create a minimal context for testing or default resolution
Sourcepub const fn for_fonts(
element_font_size: f32,
parent_font_size: f32,
root_font_size: f32,
) -> Self
pub const fn for_fonts( element_font_size: f32, parent_font_size: f32, root_font_size: f32, ) -> Self
Create a context with only font-size information (for font-relative units)
Sourcepub const fn with_containing_block(
self,
containing_block_size: PhysicalSize,
) -> Self
pub const fn with_containing_block( self, containing_block_size: PhysicalSize, ) -> Self
Create a context with containing block information (for percentage units)
Sourcepub const fn with_element_size(self, element_size: PhysicalSize) -> Self
pub const fn with_element_size(self, element_size: PhysicalSize) -> Self
Create a context with element size information (for border-radius, transforms)
Sourcepub const fn with_viewport_size(self, viewport_size: PhysicalSize) -> Self
pub const fn with_viewport_size(self, viewport_size: PhysicalSize) -> Self
Create a context with viewport size information (for vw, vh, vmin, vmax units)
Trait Implementations§
Source§impl Clone for ResolutionContext
impl Clone for ResolutionContext
Source§fn clone(&self) -> ResolutionContext
fn clone(&self) -> ResolutionContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more