From bbb0ceada858e349ffccbb762742ebb04c853bf7 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Mon, 27 Jan 2025 16:07:00 +0800 Subject: [PATCH] fix: Ensure each ImageView instance calculates its own aspect ratio - Modified ArrangeOverride methods in ImageView class to independently calculate and apply the aspect ratio based on the instance's image. Signed-off-by: Gadfly --- src/Views/ImageContainer.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Views/ImageContainer.cs b/src/Views/ImageContainer.cs index aecea0b2..b62746ed 100644 --- a/src/Views/ImageContainer.cs +++ b/src/Views/ImageContainer.cs @@ -92,6 +92,20 @@ namespace SourceGit.Views return availableSize; } + + protected override Size ArrangeOverride(Size finalSize) + { + if (Image is { } image) + { + var imageSize = image.Size; + var scaleW = finalSize.Width / imageSize.Width; + var scaleH = finalSize.Height / imageSize.Height; + var scale = Math.Min(scaleW, scaleH); + return new Size(scale * imageSize.Width, scale * imageSize.Height); + } + + return base.ArrangeOverride(finalSize); + } } public class ImageSwipeControl : ImageContainer