Skip to main content

TransformSpec

Struct TransformSpec 

Source
pub struct TransformSpec {
    pub translate: (TransformLength, TransformLength),
    pub rotate: f32,
    pub scale: (f32, f32),
    pub shear: f32,
    pub translation_basis: Option<[[f32; 3]; 2]>,
    pub origin: (TransformLength, TransformLength),
}
Expand description

CSS transform, as the cascade computed it, carried on crate::Style and turned into a TransformationMatrix at paint time by crate::Style::paint.

Deliberately the CSS components rather than a finished matrix, for two reasons. The matrix needs the element’s box to know where its centre is — CSS’s initial transform-origin: 50% 50% — and layout only settles at paint. And an interpolable transform interpolates its components (a browser lerps rotate(0deg) → rotate(90deg) through 45°, not through the matrix entries), so a transition wants these numbers, not their product.

The rendering rule is CSS’s: a transform moves the element’s painted output and its whole subtree, and changes no layout at all. translate here is therefore not the same thing as a margin offset — siblings do not move out of the way.

Fields§

§translate: (TransformLength, TransformLength)

translate(), per axis, in the unit it was authored in — see TransformLength. Kept unresolved because a percentage resolves against the element’s OWN border box, which is only known at paint.

§rotate: f32

rotate() about the element’s centre, in RADIANS, clockwise — which is the direction a positive CSS angle turns on screen.

§scale: (f32, f32)

scale() about the element’s centre. (1.0, 1.0) is no scale.

§shear: f32

Upper-right coefficient of the linear matrix before rotation: R * [[scale.x, shear], [0, scale.y]]. Unlike a tangent multiplied by scale.y this also represents finite rank-one/zero-scale matrices.

§translation_basis: Option<[[f32; 3]; 2]>

Ordered transform lists can mix pixel translations with percentages of either box axis. When present, each row is [pixels, width, height] and replaces translate at paint time. Ordinary TRS lists need none.

§origin: (TransformLength, TransformLength)

transform-origin, per axis, relative to the element’s own border box — the point rotate() and scale() act about. CSS’s initial value is 50% 50%, i.e. (Fraction(0.5), Fraction(0.5)), which is what TransformSpec::IDENTITY carries.

Kept in the same authored unit as translate and for the same reason: a percentage origin resolves against the element’s own box, which is only known at paint. Unlike translate it is measured from the box’s TOP-LEFT, not from its centre, because that is how CSS writes it.

Implementations§

Source§

impl TransformSpec

Source

pub const IDENTITY: Self

transform: none.

Source

pub const CENTRE_ORIGIN: (TransformLength, TransformLength)

CSS’s initial transform-origin: 50% 50%.

Source

pub fn is_identity(&self) -> bool

Is this transform: none — nothing to apply, nothing to pay for?

transform-origin is deliberately NOT part of the answer: an origin on its own changes nothing, exactly as in CSS, and asking otherwise would make every element that merely declares one pay for a matrix.

Source

pub fn interpolate(self, other: Self, t: f32) -> Self

Componentwise interpolation, which is what a browser does when both sides are the same function list: rotate(0deg) → rotate(90deg) sweeps through 45°, not through the matrix entries (which would shear).

Source

pub fn to_matrix( self, bounds: Bounds<Pixels>, scale_factor: f32, ) -> TransformationMatrix

The device-space matrix for an element whose border box is bounds.

Read bottom-up, as matrix products are: move the centre to the origin, scale, rotate, then move back — plus the translate, which rides on the recentring so it is applied in the element’s own frame.

The point rotate/scale act about is origin, resolved against the box and measured from its top-left — CSS’s transform-origin, whose initial 50% 50% lands exactly on the centre.

Trait Implementations§

Source§

impl Clone for TransformSpec

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for TransformSpec

Source§

impl Debug for TransformSpec

Source§

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

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

impl Default for TransformSpec

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for TransformSpec

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for TransformSpec

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for TransformSpec

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for TransformSpec

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
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 = !

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

fn try_from(value: U) -> Result<T, !>

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

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more