Struct rsvg::length::CssLength

source ·
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>

source

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);
source

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().

source

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.

source

pub fn to_inches(&self, params: &NormalizeParams) -> f64

source

pub fn to_cm(&self, params: &NormalizeParams) -> f64

source

pub fn to_mm(&self, params: &NormalizeParams) -> f64

source

pub fn to_picas(&self, params: &NormalizeParams) -> f64

Trait Implementations§

source§

impl<N: Clone + Normalize, V: Clone + Validate> Clone for CssLength<N, V>

source§

fn clone(&self) -> CssLength<N, V>

Returns a copy 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<N: Debug + Normalize, V: Debug + Validate> Debug for CssLength<N, V>

source§

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

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

impl<N: Normalize, V: Validate> Default for CssLength<N, V>

source§

fn default() -> Self

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

impl<N: Normalize, V: Validate> From<CssLength<N, V>> for RsvgLength

source§

fn from(l: CssLength<N, V>) -> RsvgLength

Converts to this type from the input type.
source§

impl<N: Normalize, V: Validate> Parse for CssLength<N, V>

source§

fn parse<'i>( parser: &mut Parser<'i, '_> ) -> Result<CssLength<N, V>, ParseError<'i>>

Parses a value out of the parser. Read more
source§

fn parse_str(s: &str) -> Result<Self, ParseError<'_>>

Convenience function to parse a value out of a &str. Read more
source§

impl<N: PartialEq + Normalize, V: PartialEq + Validate> PartialEq for CssLength<N, V>

source§

fn eq(&self, other: &CssLength<N, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<N: Copy + Normalize, V: Copy + Validate> Copy for CssLength<N, V>

source§

impl<N: Normalize, V: Validate> StructuralPartialEq for CssLength<N, V>

Auto Trait Implementations§

§

impl<N, V> RefUnwindSafe for CssLength<N, V>

§

impl<N, V> Send for CssLength<N, V>
where N: Send, V: Send,

§

impl<N, V> Sync for CssLength<N, V>
where N: Sync, V: Sync,

§

impl<N, V> Unpin for CssLength<N, V>
where N: Unpin, V: Unpin,

§

impl<N, V> UnwindSafe for CssLength<N, V>
where N: UnwindSafe, V: UnwindSafe,

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

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

§

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>,

§

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>,

§

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.
source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,