diff options
author | 2024-02-02 14:31:17 +0100 | |
---|---|---|
committer | 2024-02-02 14:31:17 +0100 | |
commit | a06682ff420678f7068265191738ab70ebe30b4c (patch) | |
tree | f4291eaa9ca54e4b58143492b9b00e7d8f99dae3 /widget | |
parent | d8dffa411b8c1bbee538e3b51aae6f768e293789 (diff) | |
download | iced-a06682ff420678f7068265191738ab70ebe30b4c.tar.gz iced-a06682ff420678f7068265191738ab70ebe30b4c.tar.bz2 iced-a06682ff420678f7068265191738ab70ebe30b4c.zip |
Use `with_translation` wherever possible
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/image/viewer.rs | 29 | ||||
-rw-r--r-- | widget/src/pane_grid.rs | 29 | ||||
-rw-r--r-- | widget/src/qr_code.rs | 9 |
3 files changed, 29 insertions, 38 deletions
diff --git a/widget/src/image/viewer.rs b/widget/src/image/viewer.rs index 0006f978..9666ff9f 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, - Transformation, Vector, Widget, + Vector, Widget, }; use std::hash::Hash; @@ -328,21 +328,18 @@ where }; renderer.with_layer(bounds, |renderer| { - renderer.with_transformation( - Transformation::translate(translation.x, translation.y), - |renderer| { - image::Renderer::draw( - renderer, - self.handle.clone(), - self.filter_method, - Rectangle { - x: bounds.x, - y: bounds.y, - ..Rectangle::with_size(image_size) - }, - ); - }, - ); + renderer.with_translation(translation, |renderer| { + image::Renderer::draw( + renderer, + self.handle.clone(), + self.filter_method, + 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 24389462..4f9a265a 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, Element, Layout, Length, Pixels, Point, Rectangle, Shell, Size, - Transformation, Vector, Widget, + Vector, Widget, }; /// A collection of panes distributed using either vertical or horizontal splits @@ -965,21 +965,18 @@ pub fn draw<Theme, Renderer, T>( 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( - pane, - renderer, - default_style, - layout, - pane_cursor, - viewport, - ); - }); - }, - ); + renderer.with_translation(translation, |renderer| { + renderer.with_layer(bounds, |renderer| { + draw_pane( + pane, + renderer, + default_style, + layout, + pane_cursor, + viewport, + ); + }); + }); } } diff --git a/widget/src/qr_code.rs b/widget/src/qr_code.rs index da63d949..6a748e63 100644 --- a/widget/src/qr_code.rs +++ b/widget/src/qr_code.rs @@ -5,8 +5,7 @@ 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, Transformation, - Vector, Widget, + Color, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget, }; use crate::graphics::geometry::Renderer as _; use crate::Renderer; @@ -120,10 +119,8 @@ impl<'a, Message, Theme> Widget<Message, Theme, Renderer> for QRCode<'a> { }); }); - let translation = Vector::new(bounds.x, bounds.y); - - renderer.with_transformation( - Transformation::translate(translation.x, translation.y), + renderer.with_translation( + bounds.position() - Point::ORIGIN, |renderer| { renderer.draw(vec![geometry]); }, |