Struct gsk4::Transform

source ·
#[repr(transparent)]
pub struct Transform { /* private fields */ }
Expand description

Transform is an object to describe transform matrices.

Unlike graphene::Matrix, Transform retains the steps in how a transform was constructed, and allows inspecting them. It is modeled after the way CSS describes transforms.

Transform objects are immutable and cannot be changed after creation. This means code can safely expose them as properties of objects without having to worry about others changing them.

Implementations§

Return the inner pointer to the underlying C value.

Returns the category this transform belongs to.

Returns

The category of the transform

Multiplies @self with the given @matrix.

matrix

the matrix to multiply @self with

Returns

The new transform

Applies a perspective projection transform.

This transform scales points in X and Y based on their Z value, scaling points with positive Z values away from the origin, and those with negative Z values towards the origin. Points on the z=0 plane are unchanged.

depth

distance of the z=0 plane. Lower values give a more flattened pyramid and therefore a more pronounced perspective effect.

Returns

The new transform

Converts a Transform to a 2D transformation matrix.

@self must be a 2D transformation. If you are not sure, use gsk_transform_get_category() >= TransformCategory::_2d to check.

The returned values have the following layout:

  | xx yx |   |  a  b  0 |
  | xy yy | = |  c  d  0 |
  | dx dy |   | tx ty  1 |

This function can be used to convert between a Transform and a matrix type from other 2D drawing libraries, in particular Cairo.

Returns
out_xx

return location for the xx member

out_yx

return location for the yx member

out_xy

return location for the xy member

out_yy

return location for the yy member

out_dx

return location for the x0 member

out_dy

return location for the y0 member

Available on crate feature v4_6 only.

Converts a Transform to 2D transformation factors.

To recreate an equivalent transform from the factors returned by this function, use

gsk_transform_skew (
    gsk_transform_scale (
        gsk_transform_rotate (
            gsk_transform_translate (NULL, &GRAPHENE_POINT_T (dx, dy)),
            angle),
        scale_x, scale_y),
    skew_x, skew_y)

@self must be a 2D transformation. If you are not sure, use

gsk_transform_get_category() >= [`TransformCategory::_2d`][crate::TransformCategory::_2d]

to check.

Returns
out_skew_x

return location for the skew factor in the x direction

out_skew_y

return location for the skew factor in the y direction

out_scale_x

return location for the scale factor in the x direction

out_scale_y

return location for the scale factor in the y direction

out_angle

return location for the rotation angle

out_dx

return location for the translation in the x direction

out_dy

return location for the translation in the y direction

Converts a Transform to 2D affine transformation factors.

To recreate an equivalent transform from the factors returned by this function, use

gsk_transform_scale (gsk_transform_translate (NULL,
                                              &GRAPHENE_POINT_T (dx, dy)),
                     sx, sy)

@self must be a 2D affine transformation. If you are not sure, use

gsk_transform_get_category() >= [`TransformCategory::_2dAffine`][crate::TransformCategory::_2dAffine]

to check.

Returns
out_scale_x

return location for the scale factor in the x direction

out_scale_y

return location for the scale factor in the y direction

out_dx

return location for the translation in the x direction

out_dy

return location for the translation in the y direction

Computes the actual value of @self and stores it in @out_matrix.

The previous value of @out_matrix will be ignored.

Returns
out_matrix

The matrix to set

Converts a matrix into a string that is suitable for printing.

The resulting string can be parsed with parse().

This is a wrapper around Gsk::Transform::print().

Returns

A new string for @self

Converts a Transform to a translation operation.

@self must be a 2D transformation. If you are not sure, use

gsk_transform_get_category() >= [`TransformCategory::_2dTranslate`][crate::TransformCategory::_2dTranslate]

to check.

Returns
out_dx

return location for the translation in the x direction

out_dy

return location for the translation in the y direction

Transforms a graphene::Rect using the given transform @self.

The result is the bounding box containing the coplanar quad.

rect

a graphene::Rect

Returns
out_rect

return location for the bounds of the transformed rectangle

Transforms a graphene::Point using the given transform @self.

point

a graphene::Point

Returns
out_point

return location for the transformed point

Parses the given @string into a transform and puts it in @out_transform.

Strings printed via to_str() can be read in again successfully using this function.

If @string does not describe a valid transform, false is returned and None is put in @out_transform.

string

the string to parse

Returns

true if @string described a valid transform.

out_transform

The location to put the transform in

Inverts the given transform.

If @self is not invertible, None is returned. Note that inverting None also returns None, which is the correct inverse of None. If you need to differentiate between those cases, you should check @self is not None before calling this function.

Returns

The inverted transform

Rotates @self @angle degrees in 2D - or in 3D-speak, around the z axis.

angle

the rotation angle, in degrees (clockwise)

Returns

The new transform

Rotates @self @angle degrees around @axis.

For a rotation in 2D space, use rotate()

angle

the rotation angle, in degrees (clockwise)

axis

The rotation axis

Returns

The new transform

Scales @self in 2-dimensional space by the given factors.

Use scale_3d() to scale in all 3 dimensions.

factor_x

scaling factor on the X axis

factor_y

scaling factor on the Y axis

Returns

The new transform

Scales @self by the given factors.

factor_x

scaling factor on the X axis

factor_y

scaling factor on the Y axis

factor_z

scaling factor on the Z axis

Returns

The new transform

Available on crate feature v4_6 only.

Applies a skew transform.

skew_x

skew factor, in degrees, on the X axis

skew_y

skew factor, in degrees, on the Y axis

Returns

The new transform

Applies all the operations from @other to @self.

other

Transform to apply

Returns

The new transform

Translates @self in 2-dimensional space by @point.

point

the point to translate the transform by

Returns

The new transform

Translates @self by @point.

point

the point to translate the transform by

Returns

The new transform

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Returns the type identifier of Self.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Ensures that the type has been registered with the type system.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.