diff options
author | 2023-10-23 03:13:28 +0200 | |
---|---|---|
committer | 2024-02-02 01:53:23 +0100 | |
commit | 5467c19c80c992f03890264ed58156305a26b19a (patch) | |
tree | 141f48d4329ccb518d85fb121f51c22835744a11 /graphics/src/primitive.rs | |
parent | 759f0e922598504705b543185bc7140a652b726a (diff) | |
download | iced-5467c19c80c992f03890264ed58156305a26b19a.tar.gz iced-5467c19c80c992f03890264ed58156305a26b19a.tar.bz2 iced-5467c19c80c992f03890264ed58156305a26b19a.zip |
Replace `Primitive::Translate` with `Transform`
Diffstat (limited to 'graphics/src/primitive.rs')
-rw-r--r-- | graphics/src/primitive.rs | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index aed59e1a..32008698 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -8,6 +8,7 @@ use crate::core::{ }; use crate::text::editor; use crate::text::paragraph; +use crate::Transformation; use std::sync::Arc; @@ -104,12 +105,12 @@ pub enum Primitive<T> { /// The content of the clip content: Box<Primitive<T>>, }, - /// A primitive that applies a translation - Translate { - /// The translation vector - translation: Vector, + /// A primitive that applies a [`Transformation`] + Transform { + /// The [`Transformation`] + transformation: Transformation, - /// The primitive to translate + /// The primitive to transform content: Box<Primitive<T>>, }, /// A cached primitive. @@ -125,12 +126,12 @@ pub enum Primitive<T> { } impl<T> Primitive<T> { - /// Creates a [`Primitive::Group`]. + /// Groups the current [`Primitive`]. pub fn group(primitives: Vec<Self>) -> Self { Self::Group { primitives } } - /// Creates a [`Primitive::Clip`]. + /// Clips the current [`Primitive`]. pub fn clip(self, bounds: Rectangle) -> Self { Self::Clip { bounds, @@ -138,10 +139,21 @@ impl<T> Primitive<T> { } } - /// Creates a [`Primitive::Translate`]. + /// Translates the current [`Primitive`]. pub fn translate(self, translation: Vector) -> Self { - Self::Translate { - translation, + Self::Transform { + transformation: Transformation::translate( + translation.x, + translation.y, + ), + content: Box::new(self), + } + } + + /// Transforms the current [`Primitive`]. + pub fn transform(self, transformation: Transformation) -> Self { + Self::Transform { + transformation, content: Box::new(self), } } |