Skip to content

Commit

Permalink
Fix Image not respecting viewport bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jan 26, 2025
1 parent 3428a3d commit d886f39
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions widget/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ where
pub fn draw<Renderer, Handle>(
renderer: &mut Renderer,
layout: Layout<'_>,
viewport: &Rectangle,
handle: &Handle,
content_fit: ContentFit,
filter_method: FilterMethod,
Expand Down Expand Up @@ -218,7 +219,9 @@ pub fn draw<Renderer, Handle>(

if adjusted_fit.width > bounds.width || adjusted_fit.height > bounds.height
{
renderer.with_layer(bounds, render);
if let Some(bounds) = bounds.intersection(viewport) {
renderer.with_layer(bounds, render);
}
} else {
render(renderer);
}
Expand Down Expand Up @@ -262,11 +265,12 @@ where
_style: &renderer::Style,
layout: Layout<'_>,
_cursor: mouse::Cursor,
_viewport: &Rectangle,
viewport: &Rectangle,
) {
draw(
renderer,
layout,
viewport,
&self.handle,
self.content_fit,
self.filter_method,
Expand Down

0 comments on commit d886f39

Please sign in to comment.