diff options
author | 2023-04-05 05:49:30 +0200 | |
---|---|---|
committer | 2023-04-05 05:49:30 +0200 | |
commit | 1bba9a080f796276d5da87bf8decd2ed89ef218a (patch) | |
tree | 48fda95025eed66dd921c56c134866a22b336b9d /tiny_skia | |
parent | 4cae262d22cde458cbb5d0667e4bcf6adce9242a (diff) | |
download | iced-1bba9a080f796276d5da87bf8decd2ed89ef218a.tar.gz iced-1bba9a080f796276d5da87bf8decd2ed89ef218a.tar.bz2 iced-1bba9a080f796276d5da87bf8decd2ed89ef218a.zip |
Fix `Svg` and `Image` primitives in `iced_tiny_skia`
Diffstat (limited to 'tiny_skia')
-rw-r--r-- | tiny_skia/src/backend.rs | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs index b1417409..8bc2321c 100644 --- a/tiny_skia/src/backend.rs +++ b/tiny_skia/src/backend.rs @@ -205,7 +205,7 @@ impl Backend { } let clip_mask = (!physical_bounds.is_within(&clip_bounds)) - .then(|| clip_mask as &_); + .then_some(clip_mask as &_); let transform = tiny_skia::Transform::from_translate( translation.x, @@ -269,7 +269,7 @@ impl Backend { } let clip_mask = (!physical_bounds.is_within(&clip_bounds)) - .then(|| clip_mask as &_); + .then_some(clip_mask as &_); self.text_pipeline.draw( content, @@ -285,25 +285,23 @@ impl Backend { } #[cfg(feature = "image")] Primitive::Image { handle, bounds } => { - if !clip_bounds - .intersects(&((*bounds + translation) * scale_factor)) - { + let physical_bounds = (*bounds + translation) * scale_factor; + + if !clip_bounds.intersects(&physical_bounds) { return; } + let clip_mask = (!physical_bounds.is_within(&clip_bounds)) + .then_some(clip_mask as &_); + let transform = tiny_skia::Transform::from_translate( translation.x, translation.y, ) .post_scale(scale_factor, scale_factor); - self.raster_pipeline.draw( - handle, - *bounds, - pixels, - transform, - Some(clip_mask), - ); + self.raster_pipeline + .draw(handle, *bounds, pixels, transform, clip_mask); } #[cfg(feature = "svg")] Primitive::Svg { @@ -311,12 +309,21 @@ impl Backend { bounds, color, } => { + let physical_bounds = (*bounds + translation) * scale_factor; + + if !clip_bounds.intersects(&physical_bounds) { + return; + } + + let clip_mask = (!physical_bounds.is_within(&clip_bounds)) + .then_some(clip_mask as &_); + self.vector_pipeline.draw( handle, *color, (*bounds + translation) * scale_factor, pixels, - clip_bounds.map(|_| clip_mask as &_), + clip_mask, ); } Primitive::Fill { @@ -340,7 +347,7 @@ impl Backend { } let clip_mask = (!physical_bounds.is_within(&clip_bounds)) - .then(|| clip_mask as &_); + .then_some(clip_mask as &_); pixels.fill_path( path, @@ -373,7 +380,7 @@ impl Backend { } let clip_mask = (!physical_bounds.is_within(&clip_bounds)) - .then(|| clip_mask as &_); + .then_some(clip_mask as &_); pixels.stroke_path( path, |