From 49682cf935537f0621c55095f4c320db625f5d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 24 Oct 2023 05:34:03 +0200 Subject: [PATCH] Introduce `with_transformation` to `Renderer` trait --- core/Cargo.toml | 3 ++- core/src/lib.rs | 2 ++ core/src/mouse/interaction.rs | 1 + core/src/renderer.rs | 20 +++++++++++++++--- core/src/renderer/null.rs | 8 ++++--- {graphics => core}/src/transformation.rs | 13 ++++++------ graphics/Cargo.toml | 1 - graphics/src/lib.rs | 2 -- graphics/src/primitive.rs | 5 +++-- graphics/src/renderer.rs | 18 ++++++++-------- graphics/src/viewport.rs | 4 +--- renderer/src/geometry.rs | 3 +-- renderer/src/lib.rs | 14 ++++++------ src/lib.rs | 3 ++- tiny_skia/src/backend.rs | 15 +++++++------ tiny_skia/src/geometry.rs | 4 ++-- tiny_skia/src/text.rs | 16 ++++++++++---- wgpu/src/backend.rs | 4 ++-- wgpu/src/geometry.rs | 3 +-- wgpu/src/image.rs | 3 +-- wgpu/src/layer.rs | 12 ++++++----- wgpu/src/layer/mesh.rs | 3 +-- wgpu/src/layer/text.rs | 4 ++-- wgpu/src/quad.rs | 4 ++-- wgpu/src/text.rs | 14 ++++++------ wgpu/src/triangle.rs | 4 ++-- widget/src/canvas.rs | 10 ++++----- widget/src/image/viewer.rs | 27 +++++++++++++----------- widget/src/pane_grid.rs | 10 +++++---- widget/src/qr_code.rs | 12 +++++++---- winit/src/conversion.rs | 1 + 31 files changed, 139 insertions(+), 104 deletions(-) rename {graphics => core}/src/transformation.rs (89%) diff --git a/core/Cargo.toml b/core/Cargo.toml index 7acb751119..122967775d 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -12,10 +12,11 @@ keywords.workspace = true [dependencies] bitflags.workspace = true +glam.workspace = true log.workspace = true +num-traits.workspace = true thiserror.workspace = true twox-hash.workspace = true -num-traits.workspace = true palette.workspace = true palette.optional = true diff --git a/core/src/lib.rs b/core/src/lib.rs index 54ea58394c..7d98412379 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -48,6 +48,7 @@ mod point; mod rectangle; mod shell; mod size; +mod transformation; mod vector; pub use alignment::Alignment; @@ -73,5 +74,6 @@ pub use renderer::Renderer; 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 072033fdd4..6ad6622926 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 1b327e563c..13e355f609 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, BorderRadius, Color, Rectangle, Vector}; +use crate::{ + Background, BorderRadius, Color, Rectangle, Transformation, Vector, +}; /// A component that can be used by widgets to draw themselves on a screen. pub trait Renderer: Sized { @@ -17,12 +19,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); diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs index 55d58a5918..4b7ee13559 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; @@ -23,9 +25,9 @@ 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 similarity index 89% rename from graphics/src/transformation.rs rename to core/src/transformation.rs index f0c97922fd..92927b43a8 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; @@ -8,6 +8,7 @@ use std::ops::Mul; pub struct Transformation(Mat4); impl Transformation { + /// A transformation that does nothing. pub const IDENTITY: Self = Self(Mat4::IDENTITY); /// Creates an orthographic projection. @@ -30,16 +31,14 @@ impl Transformation { Transformation(Mat4::from_scale(Vec3::new(scaling, scaling, 1.0))) } + /// Returns the scale factor of the [`Transformation`]. pub fn scale_factor(&self) -> f32 { self.0.x_axis.x } - pub fn translation_x(&self) -> f32 { - self.0.w_axis.x - } - - 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) } } diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index ff6986490e..d4787d1739 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -25,7 +25,6 @@ iced_core.workspace = true bitflags.workspace = true bytemuck.workspace = true -glam.workspace = true half.workspace = true log.workspace = true raw-window-handle.workspace = true diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index a0729058ac..45ac616149 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -19,7 +19,6 @@ mod antialiasing; mod error; mod primitive; -mod transformation; mod viewport; pub mod backend; @@ -46,7 +45,6 @@ pub use gradient::Gradient; pub use mesh::Mesh; pub use primitive::Primitive; pub use renderer::Renderer; -pub use transformation::Transformation; pub use viewport::Viewport; pub use iced_core as core; diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index c78abdb59d..2343018506 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -3,9 +3,10 @@ use crate::core::alignment; use crate::core::image; use crate::core::svg; use crate::core::text; -use crate::core::{Background, Color, Font, Pixels, Point, Rectangle, Vector}; +use crate::core::{ + Background, Color, Font, Pixels, Point, Rectangle, Transformation, Vector, +}; use crate::text::paragraph; -use crate::Transformation; use std::sync::Arc; diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs index a9d7895eb6..07d3a78fd0 100644 --- a/graphics/src/renderer.rs +++ b/graphics/src/renderer.rs @@ -6,7 +6,7 @@ use crate::core::renderer; use crate::core::svg; use crate::core::text::Text; use crate::core::{ - Background, Color, Font, Pixels, Point, Rectangle, Size, Vector, + Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation, }; use crate::text; use crate::Primitive; @@ -76,20 +76,20 @@ impl Renderer { } /// Starts recording a translation. - pub fn start_translation(&mut self) -> Vec> { + pub fn start_transformation(&mut self) -> Vec> { std::mem::take(&mut self.primitives) } /// Ends the recording of a translation. - pub fn end_translation( + pub fn end_transformation( &mut self, primitives: Vec>, - translation: Vector, + transformation: Transformation, ) { let layer = std::mem::replace(&mut self.primitives, primitives); self.primitives - .push(Primitive::group(layer).translate(translation)); + .push(Primitive::group(layer).transform(transformation)); } } @@ -104,16 +104,16 @@ impl iced_core::Renderer for Renderer { self.end_layer(current, bounds); } - fn with_translation( + fn with_transformation( &mut self, - translation: Vector, + transformation: Transformation, f: impl FnOnce(&mut Self), ) { - let current = self.start_translation(); + let current = self.start_transformation(); f(self); - self.end_translation(current, translation); + self.end_transformation(current, transformation); } fn fill_quad( diff --git a/graphics/src/viewport.rs b/graphics/src/viewport.rs index 5792555df7..dc8e21d327 100644 --- a/graphics/src/viewport.rs +++ b/graphics/src/viewport.rs @@ -1,6 +1,4 @@ -use crate::Transformation; - -use iced_core::Size; +use crate::core::{Size, Transformation}; /// A viewing region for displaying computer graphics. #[derive(Debug, Clone)] diff --git a/renderer/src/geometry.rs b/renderer/src/geometry.rs index c1650972e0..1f1121c502 100644 --- a/renderer/src/geometry.rs +++ b/renderer/src/geometry.rs @@ -2,9 +2,8 @@ mod cache; pub use cache::Cache; -use crate::core::{Point, Rectangle, Size, Vector}; +use crate::core::{Point, Rectangle, Size, Transformation, Vector}; use crate::graphics::geometry::{Fill, Path, Stroke, Text}; -use crate::graphics::Transformation; use crate::Renderer; macro_rules! delegate { diff --git a/renderer/src/lib.rs b/renderer/src/lib.rs index 7594d532dd..c0d32304a6 100644 --- a/renderer/src/lib.rs +++ b/renderer/src/lib.rs @@ -20,7 +20,7 @@ pub use geometry::Geometry; use crate::core::renderer; use crate::core::text::{self, Text}; use crate::core::{ - Background, Color, Font, Pixels, Point, Rectangle, Size, Vector, + Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation, }; use crate::graphics::text::Paragraph; use crate::graphics::Mesh; @@ -97,20 +97,20 @@ impl core::Renderer for Renderer { } } - fn with_translation( + fn with_transformation( &mut self, - translation: Vector, + transformation: Transformation, f: impl FnOnce(&mut Self), ) { match self { Self::TinySkia(renderer) => { - let primitives = renderer.start_translation(); + let primitives = renderer.start_transformation(); f(self); match self { Self::TinySkia(renderer) => { - renderer.end_translation(primitives, translation); + renderer.end_transformation(primitives, transformation); } #[cfg(feature = "wgpu")] _ => unreachable!(), @@ -118,14 +118,14 @@ impl core::Renderer for Renderer { } #[cfg(feature = "wgpu")] Self::Wgpu(renderer) => { - let primitives = renderer.start_translation(); + let primitives = renderer.start_transformation(); f(self); match self { #[cfg(feature = "wgpu")] Self::Wgpu(renderer) => { - renderer.end_translation(primitives, translation); + renderer.end_transformation(primitives, transformation); } _ => unreachable!(), } diff --git a/src/lib.rs b/src/lib.rs index cb6e86d4c7..4f92103d8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,7 +185,8 @@ pub use crate::core::alignment; pub use crate::core::gradient; pub use crate::core::{ color, Alignment, Background, BorderRadius, Color, ContentFit, Degrees, - Gradient, Length, Padding, Pixels, Point, Radians, Rectangle, Size, Vector, + Gradient, Length, Padding, Pixels, Point, Radians, Rectangle, Size, + Transformation, Vector, }; pub use crate::runtime::Command; diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs index e8f93fde6b..2900625c85 100644 --- a/tiny_skia/src/backend.rs +++ b/tiny_skia/src/backend.rs @@ -1,7 +1,7 @@ -use crate::core::{Background, Color, Gradient, Rectangle}; +use crate::core::{Background, Color, Gradient, Rectangle, Transformation}; use crate::graphics::backend; use crate::graphics::text; -use crate::graphics::{Damage, Transformation, Viewport}; +use crate::graphics::{Damage, Viewport}; use crate::primitive::{self, Primitive}; use std::borrow::Cow; @@ -374,11 +374,12 @@ impl Backend { self.text_pipeline.draw_paragraph( paragraph, - *position * transformation, + *position, *color, - scale_factor * transformation.scale_factor(), + scale_factor, pixels, clip_mask, + transformation, ); } Primitive::Text { @@ -623,13 +624,15 @@ fn into_color(color: Color) -> tiny_skia::Color { } fn into_transform(transformation: Transformation) -> tiny_skia::Transform { + let translation = transformation.translation(); + tiny_skia::Transform { sx: transformation.scale_factor(), kx: 0.0, ky: 0.0, sy: transformation.scale_factor(), - tx: transformation.translation_x(), - ty: transformation.translation_y(), + tx: translation.x, + ty: translation.y, } } diff --git a/tiny_skia/src/geometry.rs b/tiny_skia/src/geometry.rs index 06a770e652..dc919ba345 100644 --- a/tiny_skia/src/geometry.rs +++ b/tiny_skia/src/geometry.rs @@ -1,8 +1,8 @@ -use crate::core::{Point, Rectangle, Size, Vector}; +use crate::core::{Point, Rectangle, Size, Transformation, Vector}; use crate::graphics::geometry::fill::{self, Fill}; use crate::graphics::geometry::stroke::{self, Stroke}; use crate::graphics::geometry::{Path, Style, Text}; -use crate::graphics::{Gradient, Transformation}; +use crate::graphics::Gradient; use crate::primitive::{self, Primitive}; pub struct Frame { diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs index cb3ef54c7d..07da1ddd57 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/src/text.rs @@ -1,6 +1,6 @@ use crate::core::alignment; use crate::core::text::{LineHeight, Shaping}; -use crate::core::{Color, Font, Pixels, Point, Rectangle}; +use crate::core::{Color, Font, Pixels, Point, Rectangle, Transformation}; use crate::graphics::text::cache::{self, Cache}; use crate::graphics::text::paragraph; use crate::graphics::text::FontSystem; @@ -44,6 +44,7 @@ impl Pipeline { scale_factor: f32, pixels: &mut tiny_skia::PixmapMut<'_>, clip_mask: Option<&tiny_skia::Mask>, + transformation: Transformation, ) { use crate::core::text::Paragraph as _; @@ -62,6 +63,7 @@ impl Pipeline { scale_factor, pixels, clip_mask, + transformation, ); } @@ -112,6 +114,7 @@ impl Pipeline { scale_factor, pixels, clip_mask, + Transformation::IDENTITY, ); } @@ -132,8 +135,9 @@ fn draw( scale_factor: f32, pixels: &mut tiny_skia::PixmapMut<'_>, clip_mask: Option<&tiny_skia::Mask>, + transformation: Transformation, ) { - let bounds = bounds * scale_factor; + let bounds = bounds * transformation * scale_factor; let x = match horizontal_alignment { alignment::Horizontal::Left => bounds.x, @@ -151,7 +155,8 @@ fn draw( for run in buffer.layout_runs() { for glyph in run.glyphs { - let physical_glyph = glyph.physical((x, y), scale_factor); + let physical_glyph = glyph + .physical((x, y), scale_factor * transformation.scale_factor()); if let Some((buffer, placement)) = glyph_cache.allocate( physical_glyph.cache_key, @@ -169,7 +174,10 @@ fn draw( pixels.draw_pixmap( physical_glyph.x + placement.left, physical_glyph.y - placement.top - + (run.line_y * scale_factor).round() as i32, + + (run.line_y + * scale_factor + * transformation.scale_factor()) + .round() as i32, pixmap, &tiny_skia::PixmapPaint::default(), tiny_skia::Transform::identity(), diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index b4de5e8344..bb22c169a4 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -1,8 +1,8 @@ -use crate::core::{Color, Size}; +use crate::core::{Color, Size, Transformation}; use crate::graphics; use crate::graphics::backend; use crate::graphics::color; -use crate::graphics::{Transformation, Viewport}; +use crate::graphics::Viewport; use crate::primitive::{self, Primitive}; use crate::quad; use crate::text; diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs index 2f4b44106c..cf3fbafca6 100644 --- a/wgpu/src/geometry.rs +++ b/wgpu/src/geometry.rs @@ -1,5 +1,5 @@ //! Build and draw geometry. -use crate::core::{Point, Rectangle, Size, Vector}; +use crate::core::{Point, Rectangle, Size, Transformation, Vector}; use crate::graphics::color; use crate::graphics::geometry::fill::{self, Fill}; use crate::graphics::geometry::{ @@ -7,7 +7,6 @@ use crate::graphics::geometry::{ }; use crate::graphics::gradient::{self, Gradient}; use crate::graphics::mesh::{self, Mesh}; -use crate::graphics::Transformation; use crate::primitive::{self, Primitive}; use lyon::geom::euclid; diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 553ba33057..279bebe241 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -8,8 +8,7 @@ mod vector; use atlas::Atlas; -use crate::core::{Rectangle, Size}; -use crate::graphics::Transformation; +use crate::core::{Rectangle, Size, Transformation}; use crate::layer; use crate::Buffer; diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index 00ebc14aeb..4934a581b9 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -10,10 +10,12 @@ pub use text::Text; use crate::core; use crate::core::alignment; -use crate::core::{Color, Font, Pixels, Point, Rectangle, Size, Vector}; +use crate::core::{ + Color, Font, Pixels, Point, Rectangle, Size, Transformation, Vector, +}; use crate::graphics; use crate::graphics::color; -use crate::graphics::{Transformation, Viewport}; +use crate::graphics::Viewport; use crate::primitive::{self, Primitive}; use crate::quad::{self, Quad}; @@ -122,9 +124,9 @@ impl<'a> Layer<'a> { layer.text.push(Text::Managed { paragraph: paragraph.clone(), - position: *position * transformation, + position: *position, color: *color, - scale: transformation.scale_factor(), + transformation, }); } Primitive::Text { @@ -142,7 +144,7 @@ impl<'a> Layer<'a> { layer.text.push(Text::Cached(text::Cached { content, - bounds: *bounds * transformation, + bounds: *bounds + transformation.translation(), size: *size * transformation.scale_factor(), line_height: *line_height, color: *color, diff --git a/wgpu/src/layer/mesh.rs b/wgpu/src/layer/mesh.rs index af3dc74a52..5ed7c6544c 100644 --- a/wgpu/src/layer/mesh.rs +++ b/wgpu/src/layer/mesh.rs @@ -1,7 +1,6 @@ //! A collection of triangle primitives. -use crate::core::Rectangle; +use crate::core::{Rectangle, Transformation}; use crate::graphics::mesh; -use crate::graphics::Transformation; /// A mesh of triangles. #[derive(Debug, Clone, Copy)] diff --git a/wgpu/src/layer/text.rs b/wgpu/src/layer/text.rs index 6465436704..d8568009fd 100644 --- a/wgpu/src/layer/text.rs +++ b/wgpu/src/layer/text.rs @@ -1,6 +1,6 @@ use crate::core::alignment; use crate::core::text; -use crate::core::{Color, Font, Pixels, Point, Rectangle}; +use crate::core::{Color, Font, Pixels, Point, Rectangle, Transformation}; use crate::graphics::text::paragraph; /// A paragraph of text. @@ -10,7 +10,7 @@ pub enum Text<'a> { paragraph: paragraph::Weak, position: Point, color: Color, - scale: f32, + transformation: Transformation, }, Cached(Cached<'a>), } diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 662b9eb71d..49140efbd9 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -4,9 +4,9 @@ mod solid; use gradient::Gradient; use solid::Solid; -use crate::core::{Background, Rectangle}; +use crate::core::{Background, Rectangle, Transformation}; +use crate::graphics; use crate::graphics::color; -use crate::graphics::{self, Transformation}; use bytemuck::{Pod, Zeroable}; use wgpu::util::DeviceExt; diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 317e3a8bb3..a3ce9b807c 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -1,5 +1,5 @@ use crate::core::alignment; -use crate::core::{Rectangle, Size}; +use crate::core::{Rectangle, Size, Transformation}; use crate::graphics::color; use crate::graphics::text::cache::{self, Cache}; use crate::graphics::text::{FontSystem, Paragraph}; @@ -117,12 +117,12 @@ impl Pipeline { horizontal_alignment, vertical_alignment, color, - scale, + transformation, ) = match section { Text::Managed { position, color, - scale, + transformation, .. } => { use crate::core::text::Paragraph as _; @@ -138,7 +138,7 @@ impl Pipeline { paragraph.horizontal_alignment(), paragraph.vertical_alignment(), *color, - *scale, + *transformation, ) } Text::Cached(text) => { @@ -157,12 +157,12 @@ impl Pipeline { text.horizontal_alignment, text.vertical_alignment, text.color, - 1.0, + Transformation::IDENTITY, ) } }; - let bounds = bounds * scale_factor; + let bounds = bounds * transformation * scale_factor; let left = match horizontal_alignment { alignment::Horizontal::Left => bounds.x, @@ -192,7 +192,7 @@ impl Pipeline { buffer, left, top, - scale: scale * scale_factor, + scale: scale_factor * transformation.scale_factor(), bounds: glyphon::TextBounds { left: clip_bounds.x as i32, top: clip_bounds.y as i32, diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 029127b930..bbbd7806e2 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -1,8 +1,8 @@ //! Draw meshes of triangles. mod msaa; -use crate::core::Size; -use crate::graphics::{Antialiasing, Transformation}; +use crate::core::{Size, Transformation}; +use crate::graphics::Antialiasing; use crate::layer::mesh::{self, Mesh}; use crate::Buffer; diff --git a/widget/src/canvas.rs b/widget/src/canvas.rs index ebd1312170..2a59925d1e 100644 --- a/widget/src/canvas.rs +++ b/widget/src/canvas.rs @@ -7,7 +7,6 @@ pub use event::Event; pub use program::Program; pub use crate::graphics::geometry::*; -pub use crate::graphics::Transformation; pub use crate::renderer::geometry::*; use crate::core; @@ -15,8 +14,9 @@ use crate::core::layout::{self, Layout}; use crate::core::mouse; use crate::core::renderer; use crate::core::widget::tree::{self, Tree}; -use crate::core::{Clipboard, Element, Shell, Widget}; -use crate::core::{Length, Rectangle, Size, Vector}; +use crate::core::{ + Clipboard, Element, Length, Rectangle, Shell, Size, Transformation, Widget, +}; use crate::graphics::geometry; use std::marker::PhantomData; @@ -210,8 +210,8 @@ where let state = tree.state.downcast_ref::(); - renderer.with_translation( - Vector::new(bounds.x, bounds.y), + renderer.with_transformation( + Transformation::translate(bounds.x, bounds.y), |renderer| { renderer.draw( self.program.draw(state, renderer, theme, bounds, cursor), diff --git a/widget/src/image/viewer.rs b/widget/src/image/viewer.rs index 44624fc8ef..00b8dcfd2c 100644 --- a/widget/src/image/viewer.rs +++ b/widget/src/image/viewer.rs @@ -7,7 +7,7 @@ use crate::core::renderer; use crate::core::widget::tree::{self, Tree}; use crate::core::{ Clipboard, Element, Layout, Length, Pixels, Point, Rectangle, Shell, Size, - Vector, Widget, + Transformation, Vector, Widget, }; use std::hash::Hash; @@ -325,17 +325,20 @@ where }; renderer.with_layer(bounds, |renderer| { - renderer.with_translation(translation, |renderer| { - image::Renderer::draw( - renderer, - self.handle.clone(), - Rectangle { - x: bounds.x, - y: bounds.y, - ..Rectangle::with_size(image_size) - }, - ); - }); + renderer.with_transformation( + Transformation::translate(translation.x, translation.y), + |renderer| { + image::Renderer::draw( + renderer, + self.handle.clone(), + Rectangle { + x: bounds.x, + y: bounds.y, + ..Rectangle::with_size(image_size) + }, + ); + }, + ); }); } } diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index 2d25a543ee..b63e2a1bbd 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -43,7 +43,7 @@ use crate::core::widget; use crate::core::widget::tree::{self, Tree}; use crate::core::{ Clipboard, Color, Element, Layout, Length, Pixels, Point, Rectangle, Shell, - Size, Vector, Widget, + Size, Transformation, Vector, Widget, }; /// A collection of panes distributed using either vertical or horizontal splits @@ -931,9 +931,11 @@ pub fn draw( if let Some(cursor_position) = cursor.position() { let bounds = layout.bounds(); - renderer.with_translation( - cursor_position - - Point::new(bounds.x + origin.x, bounds.y + origin.y), + let translation = cursor_position + - Point::new(bounds.x + origin.x, bounds.y + origin.y); + + renderer.with_transformation( + Transformation::translate(translation.x, translation.y), |renderer| { renderer.with_layer(bounds, |renderer| { draw_pane( diff --git a/widget/src/qr_code.rs b/widget/src/qr_code.rs index 1dc4da7fac..b7f2a8c706 100644 --- a/widget/src/qr_code.rs +++ b/widget/src/qr_code.rs @@ -5,7 +5,8 @@ use crate::core::mouse; use crate::core::renderer::{self, Renderer as _}; use crate::core::widget::Tree; use crate::core::{ - Color, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget, + Color, Element, Layout, Length, Point, Rectangle, Size, Transformation, + Vector, Widget, }; use crate::graphics::geometry::Renderer as _; use crate::Renderer; @@ -122,9 +123,12 @@ impl<'a, Message, Theme> Widget> for QRCode<'a> { let translation = Vector::new(bounds.x, bounds.y); - renderer.with_translation(translation, |renderer| { - renderer.draw(vec![geometry]); - }); + renderer.with_transformation( + Transformation::translate(translation.x, translation.y), + |renderer| { + renderer.draw(vec![geometry]); + }, + ); } } diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 3ecd044c8a..33e1c02378 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -250,6 +250,7 @@ pub fn mouse_interaction( } Interaction::ResizingVertically => winit::window::CursorIcon::NsResize, Interaction::NotAllowed => winit::window::CursorIcon::NotAllowed, + Interaction::ZoomIn => winit::window::CursorIcon::ZoomIn, } }