Skip to main content

ResolutionContext

Struct ResolutionContext 

Source
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: f32

The computed font-size of the current element (for em in non-font properties)

§parent_font_size: f32

The computed font-size of the parent element (for em in font-size property)

§root_font_size: f32

The computed font-size of the root element (for rem units)

§containing_block_size: PhysicalSize

The 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: PhysicalSize

The 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

Source

pub const fn default_const() -> Self

Create a minimal context for testing or default resolution

Source

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)

Source

pub const fn with_containing_block( self, containing_block_size: PhysicalSize, ) -> Self

Create a context with containing block information (for percentage units)

Source

pub const fn with_element_size(self, element_size: PhysicalSize) -> Self

Create a context with element size information (for border-radius, transforms)

Source

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

Source§

fn clone(&self) -> ResolutionContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResolutionContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ResolutionContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for ResolutionContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.