sketch/css/transform
transform
helps you write CSS transforms function, in a fully type-safe
way. Every transform functions are implemented.
Types
The <transform-function>
CSS data type represents a transformation that
affects an element’s appearance. Transformation functions can rotate, resize,
distort, or move an element in 2D or 3D space.
It is used in the transform property.
pub opaque type Transform
Functions
pub fn matrix(
a: Float,
b: Float,
c: Float,
d: Float,
tx: Float,
ty: Float,
) -> Transform
The matrix()
CSS function defines a homogeneous 2D transformation matrix.
transform.matrix(a, b, c, d, tx, ty)
is a shorthand for
transform.matrix_3d(#( #(a, b, 0, 0), #(c, d, 0, 0), #(0, 0, 1, 0), #(tx, ty, 0, 1) ))
pub fn matrix_3d(
values: #(
#(Float, Float, Float, Float),
#(Float, Float, Float, Float),
#(Float, Float, Float, Float),
#(Float, Float, Float, Float),
),
) -> Transform
pub fn perspective(x: Length) -> Transform
The perspective()
CSS function defines a transformation that sets the
distance between the user and the z=0 plane, the perspective from which the
viewer would be if the 2-dimensional interface were 3-dimensional.
pub fn rotate(value: Angle) -> Transform
The rotate()
CSS function defines a transformation that rotates an element
around a fixed point on the 2D plane, without deforming it.
pub fn rotate_3d(
x: Float,
y: Float,
z: Float,
value: Angle,
) -> Transform
The rotate3d()
CSS function defines a transformation that rotates an element
around a fixed axis in 3D space, without deforming it
pub fn rotate_x(x: Angle) -> Transform
The rotateX()
CSS function defines a transformation that rotates an element
oarend the x-axis (horizontal) without deforming it.
rotateX(a)
is equivalent torotate3d(1, 0, 0, a)
.
pub fn rotate_y(y: Angle) -> Transform
The rotateY()
CSS function defines a transformation that rotates an element
oarend the y-axis (vertical) without deforming it.
rotateY(a)
is equivalent torotate3d(0, 1, 0, a)
.
pub fn rotate_z(y: Angle) -> Transform
The rotateZ()
CSS function defines a transformation that rotates an element
oarend the z-axis without deforming it.
rotateZ(a)
is equivalent torotate3d(0, 0, 1, a)
.
pub fn scale(x: Float, y: Float) -> Transform
The scale()
CSS function defines a transformation that resizes an element
on the 2D plane. Because the amount of scaling is defined by a vector [sx, sy],
it can resize the horizontal and vertical dimensions at different scales.
The
scale()
function only scales in 2D. To scale in 3D, usescale3d()
instead.
pub fn scale_3d(x: Float, y: Float, z: Float) -> Transform
The scale3d()
CSS function defines a transformation that resizes an element
in 3D space. Because the amount of scaling is defined by a vector [sx, sy, sz],
it can resize different dimensions at different scales.
pub fn scale_x(x: Float) -> Transform
The scaleX()
CSS function defines a transformation that resizes an element
along the x-axis (horizontally).
scaleX(sx)
is equivalent toscale(sx, 1)
orscale3d(sx, 1, 1)
.
pub fn scale_y(y: Float) -> Transform
The scaleY()
CSS function defines a transformation that resizes an element
along the y-axis (vertically).
scaleY(sy)
is equivalent toscale(1, sy)
orscale3d(1, sy, 1)
.
transform: rotateX(180deg)
; ===transform: scaleY(-1);
pub fn scale_z(y: Float) -> Transform
The scaleZ()
CSS function defines a transformation that resizes an element
along the z-axis.
scaleZ(sy)
is equivalent toscale3d(1, 1, sy)
.
pub fn skew(x: Angle, y: Angle) -> Transform
The skew()
CSS function defines a transformation that skews an element on
the 2D plane.
pub fn skew_x(x: Angle) -> Transform
The skewX()
CSS function defines a transformation that skews an element
in the horizontal direction on the 2D plane.
pub fn skew_y(x: Angle) -> Transform
The skewY()
CSS function defines a transformation that skews an element
in the vertical direction on the 2D plane.
pub fn translate(x: Length, y: Length) -> Transform
The translate()
CSS function repositions an element in the horizontal
and/or vertical directions.
pub fn translate_3d(x: Length, y: Length, z: Length) -> Transform
pub fn translate_x(x: Length) -> Transform
pub fn translate_y(y: Length) -> Transform
pub fn translate_z(y: Length) -> Transform
The translateZ()
CSS function repositions an element along the z-axis in
3D space, i.e., closer to or farther away from the viewer.