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: f32rotate() 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: f32Upper-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
impl TransformSpec
Sourcepub const CENTRE_ORIGIN: (TransformLength, TransformLength)
pub const CENTRE_ORIGIN: (TransformLength, TransformLength)
CSS’s initial transform-origin: 50% 50%.
Sourcepub fn is_identity(&self) -> bool
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.
Sourcepub fn interpolate(self, other: Self, t: f32) -> Self
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).
Sourcepub fn to_matrix(
self,
bounds: Bounds<Pixels>,
scale_factor: f32,
) -> TransformationMatrix
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
impl Clone for TransformSpec
impl Copy for TransformSpec
Source§impl Debug for TransformSpec
impl Debug for TransformSpec
Source§impl Default for TransformSpec
impl Default for TransformSpec
Source§impl<'de> Deserialize<'de> for TransformSpec
impl<'de> Deserialize<'de> for TransformSpec
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for TransformSpec
impl PartialEq for TransformSpec
Source§impl Serialize for TransformSpec
impl Serialize for TransformSpec
impl StructuralPartialEq for TransformSpec
Auto Trait Implementations§
impl Forget for TransformSpec
impl Freeze for TransformSpec
impl Move for TransformSpec
impl RefUnwindSafe for TransformSpec
impl Send for TransformSpec
impl Sync for TransformSpec
impl Unpin for TransformSpec
impl UnsafeUnpin for TransformSpec
impl UnwindSafe for TransformSpec
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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