[][src]Struct rsvg_internals::Length

pub struct Length<N: Normalize> {
    pub length: f64,
    pub unit: LengthUnit,
    orientation: PhantomData<N>,
}

A CSS length value.

This is equivalent to CSS lengths.

Length implements the Parse trait, so it can be parsed out of a cssparser::Parser.

Examples of construction:

This example is not tested
// 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 = Length::<Both>::parse_str("5px").unwrap();

During the rendering phase, a Length needs to be normalized into the current coordinate system's units with the normalize 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

Methods

impl<N: Normalize> Length<N>[src]

pub fn new(l: f64, unit: LengthUnit) -> Length<N>[src]

Creates a Length.

The compiler needs to know the type parameter N which represents the length's orientation. You can specify it explicitly, or call the parametrized method:

This example is not tested
// Explicit type
let width: Length<Horizontal> = Length::new(42.0, LengthUnit::Cm);

// Inferred type
let height = Length::<Vertical>::new(42.0, LengthUnit::Cm);

pub fn check_nonnegative(self) -> Result<Self, ValueErrorKind>[src]

Returns Ok(self) if the length is >= 0, or an error.

This is usually used right after parsing a length value, as part of a validation step:

This example is not tested
let mut parser = Parser::new(...);

let length = Length::<Horizontal>::parse(&mut parser).and_then(Length::check_nonnegative)?;

pub fn normalize(&self, values: &ComputedValues, params: &ViewParams) -> f64[src]

Normalizes a specified length into a used value.

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

Trait Implementations

impl<N: Clone + Normalize> Clone for Length<N>[src]

impl<N: Copy + Normalize> Copy for Length<N>[src]

impl<N: Debug + Normalize> Debug for Length<N>[src]

impl<N: Normalize> Default for Length<N>[src]

impl<N: Normalize> From<Length<N>> for RsvgLength[src]

impl<N: Normalize> Parse for Length<N>[src]

impl<N: PartialEq + Normalize> PartialEq<Length<N>> for Length<N>[src]

impl<N: Normalize> StructuralPartialEq for Length<N>[src]

Auto Trait Implementations

impl<N> RefUnwindSafe for Length<N> where
    N: RefUnwindSafe

impl<N> Send for Length<N> where
    N: Send

impl<N> Sync for Length<N> where
    N: Sync

impl<N> Unpin for Length<N> where
    N: Unpin

impl<N> UnwindSafe for Length<N> where
    N: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Scalar for T where
    T: PartialEq<T> + Copy + Any + Debug
[src]

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,