summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-10-24 05:34:03 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-02 02:24:45 +0100
commitf4d66486016076bb339a338bc589645119962d1e (patch)
treebbb9c4d996216893296cf4323857323542d6e757 /core
parenta6e91d13d5d43796d0e6bb570fb4f010cf27921a (diff)
downloadiced-f4d66486016076bb339a338bc589645119962d1e.tar.gz
iced-f4d66486016076bb339a338bc589645119962d1e.tar.bz2
iced-f4d66486016076bb339a338bc589645119962d1e.zip
Introduce `with_transformation` to `Renderer` trait
Diffstat (limited to '')
-rw-r--r--core/Cargo.toml1
-rw-r--r--core/src/lib.rs2
-rw-r--r--core/src/mouse/interaction.rs1
-rw-r--r--core/src/renderer.rs20
-rw-r--r--core/src/renderer/null.rs8
-rw-r--r--core/src/transformation.rs (renamed from graphics/src/transformation.rs)15
6 files changed, 31 insertions, 16 deletions
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 32dd3df2..2360e822 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -12,6 +12,7 @@ keywords.workspace = true
[dependencies]
bitflags.workspace = true
+glam.workspace = true
log.workspace = true
num-traits.workspace = true
smol_str.workspace = true
diff --git a/core/src/lib.rs b/core/src/lib.rs
index bbc973f0..002336ee 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -49,6 +49,7 @@ mod rectangle;
mod shadow;
mod shell;
mod size;
+mod transformation;
mod vector;
pub use alignment::Alignment;
@@ -75,6 +76,7 @@ pub use shadow::Shadow;
pub use shell::Shell;
pub use size::Size;
pub use text::Text;
+pub use transformation::Transformation;
pub use vector::Vector;
pub use widget::Widget;
diff --git a/core/src/mouse/interaction.rs b/core/src/mouse/interaction.rs
index 072033fd..6ad66229 100644
--- a/core/src/mouse/interaction.rs
+++ b/core/src/mouse/interaction.rs
@@ -13,4 +13,5 @@ pub enum Interaction {
ResizingHorizontally,
ResizingVertically,
NotAllowed,
+ ZoomIn,
}
diff --git a/core/src/renderer.rs b/core/src/renderer.rs
index 0af74bb3..1139b41c 100644
--- a/core/src/renderer.rs
+++ b/core/src/renderer.rs
@@ -5,7 +5,9 @@ mod null;
#[cfg(debug_assertions)]
pub use null::Null;
-use crate::{Background, Border, Color, Rectangle, Shadow, Size, Vector};
+use crate::{
+ Background, Border, Color, Rectangle, Shadow, Size, Transformation, Vector,
+};
/// A component that can be used by widgets to draw themselves on a screen.
pub trait Renderer: Sized {
@@ -14,12 +16,24 @@ pub trait Renderer: Sized {
/// The layer will clip its contents to the provided `bounds`.
fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self));
- /// Applies a `translation` to the primitives recorded in the given closure.
+ /// Applies a [`Transformation`] to the primitives recorded in the given closure.
+ fn with_transformation(
+ &mut self,
+ transformation: Transformation,
+ f: impl FnOnce(&mut Self),
+ );
+
+ /// Applies a translation to the primitives recorded in the given closure.
fn with_translation(
&mut self,
translation: Vector,
f: impl FnOnce(&mut Self),
- );
+ ) {
+ self.with_transformation(
+ Transformation::translate(translation.x, translation.y),
+ f,
+ );
+ }
/// Fills a [`Quad`] with the provided [`Background`].
fn fill_quad(&mut self, quad: Quad, background: impl Into<Background>);
diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs
index 455daa42..75a3c8b6 100644
--- a/core/src/renderer/null.rs
+++ b/core/src/renderer/null.rs
@@ -1,7 +1,9 @@
use crate::alignment;
use crate::renderer::{self, Renderer};
use crate::text::{self, Text};
-use crate::{Background, Color, Font, Pixels, Point, Rectangle, Size, Vector};
+use crate::{
+ Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation,
+};
use std::borrow::Cow;
@@ -21,9 +23,9 @@ impl Null {
impl Renderer for Null {
fn with_layer(&mut self, _bounds: Rectangle, _f: impl FnOnce(&mut Self)) {}
- fn with_translation(
+ fn with_transformation(
&mut self,
- _translation: Vector,
+ _transformation: Transformation,
_f: impl FnOnce(&mut Self),
) {
}
diff --git a/graphics/src/transformation.rs b/core/src/transformation.rs
index e2642980..b2c488b0 100644
--- a/graphics/src/transformation.rs
+++ b/core/src/transformation.rs
@@ -1,4 +1,4 @@
-use crate::core::{Point, Rectangle, Size, Vector};
+use crate::{Point, Rectangle, Size, Vector};
use glam::{Mat4, Vec3, Vec4};
use std::ops::Mul;
@@ -31,19 +31,14 @@ impl Transformation {
Transformation(Mat4::from_scale(Vec3::new(scaling, scaling, 1.0)))
}
- /// The scale factor of the [`Transformation`].
+ /// Returns the scale factor of the [`Transformation`].
pub fn scale_factor(&self) -> f32 {
self.0.x_axis.x
}
- /// The translation on the X axis.
- pub fn translation_x(&self) -> f32 {
- self.0.w_axis.x
- }
-
- /// The translation on the Y axis.
- pub fn translation_y(&self) -> f32 {
- self.0.w_axis.y
+ /// Returns the translation of the [`Transformation`].
+ pub fn translation(&self) -> Vector {
+ Vector::new(self.0.w_axis.x, self.0.w_axis.y)
}
}