summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-02-16 17:35:28 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-02-16 18:19:36 +0700
commit395eacfc103e3123a10bebe4a9330f7c126650a4 (patch)
treeb37e6a3bb2b7c1ea694c4fbbe62005e739c8b6ff /native
parentc6486978de7f47577c85ed18ccb28a760381d421 (diff)
downloadiced-395eacfc103e3123a10bebe4a9330f7c126650a4.tar.gz
iced-395eacfc103e3123a10bebe4a9330f7c126650a4.tar.bz2
iced-395eacfc103e3123a10bebe4a9330f7c126650a4.zip
Use a new clipping layer only when necessary in `Image::draw`
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/image.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs
index 5ddc3642..b253b1b8 100644
--- a/native/src/widget/image.rs
+++ b/native/src/widget/image.rs
@@ -121,8 +121,9 @@ where
let image_size = Size::new(width as f32, height as f32);
let adjusted_fit = self.fit.fit(image_size, layout.bounds().size());
+ let bounds = layout.bounds();
- renderer.with_layer(layout.bounds(), |renderer| {
+ let render = |renderer: &mut Renderer| {
renderer.draw(
self.handle.clone(),
Rectangle {
@@ -131,7 +132,15 @@ where
..layout.bounds()
},
)
- })
+ };
+
+ if adjusted_fit.width > bounds.width
+ || adjusted_fit.height > bounds.height
+ {
+ renderer.with_layer(layout.bounds(), render);
+ } else {
+ render(renderer)
+ }
}
fn hash_layout(&self, state: &mut Hasher) {