From f5df3bea409a7bb29997143522542516d06e2c40 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/druid/src/widget/image.rs b/druid/src/widget/image.rs index 9ba71065e..59ec65e04 100644 --- a/druid/src/widget/image.rs +++ b/druid/src/widget/image.rs @@ -205,7 +205,13 @@ 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; + // We are using the image scale properties so if one dimension + // would be over scaled to keep AR fixed then we just clip back to the `bc.max()` + width = width.min(max.width); + height = height.min(max.height); + let size = Size::new(width, height); trace!("Computed size: {}", size); size }