gsk4

Struct Transform

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

GLib type: Shared boxed type with reference counted clone semantics.

Implementations§

Source§

impl Transform

Source

pub fn as_ptr(&self) -> *mut GskTransform

Return the inner pointer to the underlying C value.

Source

pub unsafe fn from_glib_ptr_borrow(ptr: &*mut GskTransform) -> &Self

Borrows the underlying C value.

Source§

impl Transform

Source

pub fn new() -> Transform

Creates a new identity transform.

This function is meant to be used by language bindings. For C code, this is equivalent to using None.

§Returns

A new identity transform

Source

pub fn category(&self) -> TransformCategory

Returns the category this transform belongs to.

§Returns

The category of the transform

Source

pub fn matrix(self, matrix: &Matrix) -> Transform

Multiplies @self with the given @matrix.

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§matrix

the matrix to multiply @self with

§Returns

The new transform

Source

pub fn perspective(self, depth: f32) -> 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.

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§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

Source

pub fn to_2d(&self) -> (f32, f32, f32, f32, f32, f32)

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

Source

pub fn to_2d_components(&self) -> (f32, f32, f32, f32, f32, f32, f32)

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

Source

pub fn to_affine(&self) -> (f32, f32, f32, f32)

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

Source

pub fn to_matrix(&self) -> Matrix

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

Source

pub fn to_str(&self) -> GString

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

Source

pub fn to_translate(&self) -> (f32, f32)

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

Source

pub fn transform_bounds(&self, rect: &Rect) -> Rect

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

Source

pub fn transform_point(&self, point: &Point) -> Point

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

§point

a graphene::Point

§Returns
§out_point

return location for the transformed point

Source§

impl Transform

Source

pub fn parse(string: impl IntoGStr) -> Result<Self, BoolError>

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

Source

pub fn invert(self) -> Result<Self, BoolError>

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.

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§Returns

The inverted transform

Source

pub fn rotate(self, angle: f32) -> Self

Rotates @self @angle degrees in 2D - or in 3D-speak, around the Z axis. The rotation happens around the origin point of (0, 0).

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§angle

the rotation angle, in degrees (clockwise)

§Returns

The new transform

Source

pub fn rotate_3d(self, angle: f32, axis: &Vec3) -> Self

Rotates @self @angle degrees around @axis.

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

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§angle

the rotation angle, in degrees (clockwise)

§axis

The rotation axis

§Returns

The new transform

Source

pub fn scale(self, factor_x: f32, factor_y: f32) -> Self

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

Use scale_3d() to scale in all 3 dimensions.

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§factor_x

scaling factor on the X axis

§factor_y

scaling factor on the Y axis

§Returns

The new transform

Source

pub fn scale_3d(self, factor_x: f32, factor_y: f32, factor_z: f32) -> Self

Scales @self by the given factors.

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§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

Source

pub fn skew(self, skew_x: f32, skew_y: f32) -> Self

Available on crate feature v4_6 only.

Applies a skew transform.

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§skew_x

skew factor, in degrees, on the X axis

§skew_y

skew factor, in degrees, on the Y axis

§Returns

The new transform

Source

pub fn transform(self, other: Option<&Self>) -> Self

Applies all the operations from @other to @self.

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§other

Transform to apply

§Returns

The new transform

Source

pub fn translate(self, point: &Point) -> Self

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

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§point

the point to translate the transform by

§Returns

The new transform

Source

pub fn translate_3d(self, point: &Point3D) -> Self

Translates @self by @point.

This function consumes @self. Use Gsk::Transform::ref() first if you want to keep it around.

§point

the point to translate the transform by

§Returns

The new transform

Trait Implementations§

Source§

impl Clone for Transform

Source§

fn clone(&self) -> Self

Makes a clone of this shared reference.

This increments the strong reference count of the reference. Dropping the reference will decrement it again.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Transform

Source§

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

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

impl Default for Transform

Source§

fn default() -> Self

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

impl Display for Transform

Source§

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

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

impl From<Transform> for Value

Source§

fn from(s: Transform) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Transform

Source§

type Err = BoolError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl HasParamSpec for Transform

Source§

type ParamSpec = ParamSpecBoxed

Source§

type SetValue = Transform

Preferred value to be used as setter for the associated ParamSpec.
Source§

type BuilderFn = fn(_: &str) -> ParamSpecBoxedBuilder<'_, Transform>

Source§

fn param_spec_builder() -> Self::BuilderFn

Source§

impl Hash for Transform

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Transform

Source§

fn cmp(&self, other: &Transform) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Transform

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Transform

Source§

fn partial_cmp(&self, other: &Transform) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StaticType for Transform

Source§

fn static_type() -> Type

Returns the type identifier of Self.
Source§

impl Eq for Transform

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(_: *const GList, _: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GList, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GPtrArray, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec( _: *const GPtrArray, _: usize, ) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GPtrArray, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(_: *const GSList, _: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GSList, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GPtrArray, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GPtrArray, num: usize, ) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GPtrArray, num: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GPtrArray) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GSList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GSList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GSList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GSList) -> Vec<T>

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> IntoClosureReturnValue for T
where T: Into<Value>,

Source§

impl<T> Property for T
where T: HasParamSpec,

Source§

type Value = T

Source§

impl<T> PropertyGet for T
where T: HasParamSpec,

Source§

type Value = T

Source§

fn get<R, F>(&self, f: F) -> R
where F: Fn(&<T as PropertyGet>::Value) -> R,

Source§

impl<T> StaticTypeExt for T
where T: StaticType,

Source§

fn ensure_type()

Ensures that the type has been registered with the type system.
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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> TransparentType for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T> TryFromClosureReturnValue for T
where T: for<'a> FromValue<'a> + StaticType + 'static,

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<'a, T, C, E> FromValueOptional<'a> for T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,