From 853603c340ea4265de3c9dbf1ada939f6eae177f Mon Sep 17 00:00:00 2001 From: William Salmon Date: Sat, 23 Oct 2021 18:04:09 +0100 Subject: [PATCH] Constrain to max bounds --- druid/src/widget/image.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/druid/src/widget/image.rs b/druid/src/widget/image.rs index 457108af21..096b19153e 100644 --- a/druid/src/widget/image.rs +++ b/druid/src/widget/image.rs @@ -197,7 +197,11 @@ impl Widget for Image { let affine = self.fill.affine_to_fill(max, image_size).as_coeffs(); // The first and forth elements of the affine are the x and y scale factor. // So just multiply them by the original size to get the ideal area based on `self.fill`. - let size = Size::new(affine[0] * image_size.width, affine[3] * image_size.height); + let mut width = affine[0] * image_size.width; + let mut height = affine[3] * image_size.height; + width = width.min(max.width); + height = height.min(max.height); + let size = Size::new(width, height); trace!("Computed size: {}", size); size }