From 5467c19c80c992f03890264ed58156305a26b19a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 23 Oct 2023 03:13:28 +0200 Subject: Replace `Primitive::Translate` with `Transform` --- graphics/src/primitive.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'graphics/src/primitive.rs') 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 { /// The content of the clip content: Box>, }, - /// 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>, }, /// A cached primitive. @@ -125,12 +126,12 @@ pub enum Primitive { } impl Primitive { - /// Creates a [`Primitive::Group`]. + /// Groups the current [`Primitive`]. pub fn group(primitives: Vec) -> 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 Primitive { } } - /// 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), } } -- cgit