pub struct CssLength<N: Normalize, V: Validate> {
pub length: f64,
pub unit: LengthUnit,
orientation: PhantomData<N>,
validation: PhantomData<V>,
}
Expand description
A CSS length value.
This is equivalent to CSS lengths.
CssLength
implements the Parse
trait, so it can be parsed out of a
[cssparser::Parser
].
This type will be normally used through the type aliases Length
and ULength
Examples of construction:
// Explicit type
let width: Length<Horizontal> = Length::new(42.0, LengthUnit::Cm);
// Inferred type
let height = Length::<Vertical>::new(42.0, LengthUnit::Cm);
// Parsed
let radius = ULength::<Both>::parse_str("5px").unwrap();
During the rendering phase, a CssLength
needs to be converted to user-space
coordinates with the CssLength::to_user
method.
Fields§
§length: f64
Numeric part of the length
unit: LengthUnit
Unit part of the length
orientation: PhantomData<N>
Dummy; used internally for the type parameter N
validation: PhantomData<V>
Dummy; used internally for the type parameter V
Implementations§
source§impl<N: Normalize, V: Validate> CssLength<N, V>
impl<N: Normalize, V: Validate> CssLength<N, V>
sourcepub fn new(l: f64, unit: LengthUnit) -> CssLength<N, V>
pub fn new(l: f64, unit: LengthUnit) -> CssLength<N, V>
Creates a CssLength.
The compiler needs to know the type parameters N
and V
which represents the
length’s orientation and validation.
You can specify them explicitly, or call the parametrized method:
// Explicit type
let width: Length<Horizontal> = Length::new(42.0, LengthUnit::Cm);
// Inferred type
let height = Length::<Vertical>::new(42.0, LengthUnit::Cm);
sourcepub fn to_user(&self, params: &NormalizeParams) -> f64
pub fn to_user(&self, params: &NormalizeParams) -> f64
Convert a Length with units into user-space coordinates.
Lengths may come with non-pixel units, and when rendering, they need to be normalized
to pixels based on the current viewport (e.g. for lengths with percent units), and
based on the current element’s set of ComputedValues
(e.g. for lengths with Em
units that need to be resolved against the current font size).
Those parameters can be obtained with NormalizeParams::new()
.
sourcepub fn to_points(&self, params: &NormalizeParams) -> f64
pub fn to_points(&self, params: &NormalizeParams) -> f64
Converts a Length to points. Pixels are taken to be respect with the DPI.
§Panics
Will panic if the length is in Percent, Em, or Ex units.
pub fn to_inches(&self, params: &NormalizeParams) -> f64
pub fn to_cm(&self, params: &NormalizeParams) -> f64
pub fn to_mm(&self, params: &NormalizeParams) -> f64
pub fn to_picas(&self, params: &NormalizeParams) -> f64
Trait Implementations§
source§impl<N: Normalize, V: Validate> From<CssLength<N, V>> for RsvgLength
impl<N: Normalize, V: Validate> From<CssLength<N, V>> for RsvgLength
source§fn from(l: CssLength<N, V>) -> RsvgLength
fn from(l: CssLength<N, V>) -> RsvgLength
source§impl<N: PartialEq + Normalize, V: PartialEq + Validate> PartialEq for CssLength<N, V>
impl<N: PartialEq + Normalize, V: PartialEq + Validate> PartialEq for CssLength<N, V>
impl<N: Copy + Normalize, V: Copy + Validate> Copy for CssLength<N, V>
impl<N: Normalize, V: Validate> StructuralPartialEq for CssLength<N, V>
Auto Trait Implementations§
impl<N, V> Freeze for CssLength<N, V>
impl<N, V> RefUnwindSafe for CssLength<N, V>where
N: RefUnwindSafe,
V: RefUnwindSafe,
impl<N, V> Send for CssLength<N, V>
impl<N, V> Sync for CssLength<N, V>
impl<N, V> Unpin for CssLength<N, V>
impl<N, V> UnwindSafe for CssLength<N, V>where
N: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.