浏览代码

Fixed incorrect size, when `Auto fit window` is on while scrolling is enabled, and improved size calculation. Fixed incorrect title width.

Ruben 7 月之前
父节点
当前提交
5f05ceeb63

+ 24 - 3
src/PicView.Avalonia/Navigation/UpdateImage.cs

@@ -79,9 +79,10 @@ public static class UpdateImage
 
             vm.ImageType = preLoadValue.ImageModel.ImageType;
 
-            WindowResizing.SetSize(preLoadValue.ImageModel.PixelWidth, preLoadValue.ImageModel.PixelHeight,
-                nextPreloadValue?.ImageModel?.PixelWidth ?? 0, nextPreloadValue?.ImageModel?.PixelHeight ?? 0,
-                preLoadValue.ImageModel.Rotation, vm);
+            if (!Settings.Zoom.ScrollEnabled)
+            {
+                SetSize();
+            }
 
             UIHelper.GetToolTipMessage.IsVisible = false;
         }, DispatcherPriority.Send);
@@ -110,6 +111,16 @@ public static class UpdateImage
                 SetTitleHelper.SetTitle(vm, preLoadValue.ImageModel);
             }
         }
+        
+        if (Settings.Zoom.ScrollEnabled)
+        {
+            // Bad fix for scrolling
+            // TODO: Implement proper scrolling fix
+            Settings.Zoom.ScrollEnabled = false;
+            await Dispatcher.UIThread.InvokeAsync(SetSize);
+            Settings.Zoom.ScrollEnabled = true;
+            await Dispatcher.UIThread.InvokeAsync(SetSize, DispatcherPriority.Send);
+        }
 
         if (Settings.WindowProperties.KeepCentered)
         {
@@ -126,6 +137,16 @@ public static class UpdateImage
         }
 
         SetStats(vm, index, preLoadValue.ImageModel);
+        
+        return;
+
+        void SetSize()
+        {
+            WindowResizing.SetSize(preLoadValue.ImageModel.PixelWidth, preLoadValue.ImageModel.PixelHeight,
+                nextPreloadValue?.ImageModel?.PixelWidth ?? 0, nextPreloadValue?.ImageModel?.PixelHeight ?? 0,
+                preLoadValue.ImageModel.Rotation, vm);
+        }
+
     }
 
     #endregion

+ 1 - 4
src/PicView.Avalonia/WindowBehavior/WindowResizing.cs

@@ -203,8 +203,7 @@ public static class WindowResizing
         {
             return null;
         }
-
-        const int padding = 45;
+        
         var screenSize = ScreenHelper.ScreenSize;
         var desktopMinWidth = desktop.MainWindow.MinWidth;
         var desktopMinHeight = desktop.MainWindow.MinHeight;
@@ -231,7 +230,6 @@ public static class WindowResizing
                 desktopMinHeight,
                 ImageSizeCalculationHelper.GetInterfaceSize(),
                 rotation,
-                padding,
                 screenSize.Scaling,
                 vm.TitlebarHeight,
                 vm.BottombarHeight,
@@ -250,7 +248,6 @@ public static class WindowResizing
                 desktopMinHeight,
                 ImageSizeCalculationHelper.GetInterfaceSize(),
                 rotation,
-                padding,
                 screenSize.Scaling,
                 vm.TitlebarHeight,
                 vm.BottombarHeight,

+ 31 - 33
src/PicView.Core/Calculations/ImageSizeCalculationHelper.cs

@@ -4,6 +4,9 @@ namespace PicView.Core.Calculations;
 
 public static class ImageSizeCalculationHelper
 {
+    private const int MinTitleWidth = 295;
+    private const int Padding = 45;
+    
     /// <summary>
     ///  Returns the interface size of the titlebar based on OS
     /// </summary>
@@ -21,7 +24,6 @@ public static class ImageSizeCalculationHelper
         double monitorMinHeight,
         double interfaceSize,
         double rotationAngle,
-        double padding,
         double dpiScaling,
         double uiTopSize,
         double uiBottomSize,
@@ -42,7 +44,7 @@ public static class ImageSizeCalculationHelper
                          Settings.WindowProperties.Maximized;
             
         var borderSpaceHeight = fullscreen ? 0 : uiTopSize + uiBottomSize + galleryHeight;
-        var borderSpaceWidth = fullscreen ? 0 : padding;
+        var borderSpaceWidth = fullscreen ? 0 : Padding;
 
         var workAreaWidth = monitorWidth - borderSpaceWidth;
         var workAreaHeight = monitorHeight - borderSpaceHeight;
@@ -52,18 +54,21 @@ public static class ImageSizeCalculationHelper
             workAreaWidth -= SizeDefaults.ScrollbarSize * dpiScaling;
             containerWidth -= SizeDefaults.ScrollbarSize * dpiScaling;
 
-            maxWidth = workAreaWidth - padding;
-            maxHeight = height;
+            maxWidth = Settings.ImageScaling.StretchImage 
+                ? workAreaWidth 
+                : Math.Min(workAreaWidth - Padding, width);
+            
+            maxHeight = workAreaHeight;
         }
         else if (Settings.WindowProperties.AutoFit)
         {
             maxWidth = Settings.ImageScaling.StretchImage
-                ? workAreaWidth - padding
-                : Math.Min(workAreaWidth - padding, width);
+                ? workAreaWidth - Padding
+                : Math.Min(workAreaWidth - Padding, width);
                     
             maxHeight = Settings.ImageScaling.StretchImage
-                ? workAreaHeight - padding
-                : Math.Min(workAreaHeight - padding, height);
+                ? workAreaHeight - Padding
+                : Math.Min(workAreaHeight - Padding, height);
         }
         else
         {
@@ -125,19 +130,19 @@ public static class ImageSizeCalculationHelper
         {
             if (Settings.WindowProperties.AutoFit)
             {
-                xWidth = maxWidth - SizeDefaults.ScrollbarSize - 10;
-                xHeight = maxWidth * height / width;
+                xWidth = width * aspectRatio;
+                xHeight = height * aspectRatio;
 
-                scrollWidth = maxWidth;
-                scrollHeight = containerHeight - padding - 8;
+                scrollWidth = Math.Max(xWidth + SizeDefaults.ScrollbarSize, SizeDefaults.WindowMinSize + SizeDefaults.ScrollbarSize + Padding + 16);
+                scrollHeight = containerHeight - margin;
             }
             else
             {
-                scrollWidth = containerWidth + SizeDefaults.ScrollbarSize;
-                scrollHeight = containerHeight - margin;
-
                 xWidth = containerWidth - SizeDefaults.ScrollbarSize + 10;
                 xHeight = height / width * xWidth;
+                
+                scrollWidth = containerWidth + SizeDefaults.ScrollbarSize;
+                scrollHeight = containerHeight - margin;
             }
         }
         else
@@ -165,7 +170,6 @@ public static class ImageSizeCalculationHelper
         double monitorMinHeight,
         double interfaceSize,
         double rotationAngle,
-        double padding,
         double dpiScaling,
         double uiTopSize,
         double uiBottomSize,
@@ -181,11 +185,11 @@ public static class ImageSizeCalculationHelper
 
         // Get sizes for both images
         var firstSize = GetImageSize(width, height, monitorWidth, monitorHeight, monitorMinWidth, monitorMinHeight,
-            interfaceSize, rotationAngle, padding, dpiScaling, uiTopSize, uiBottomSize, galleryHeight,
+            interfaceSize, rotationAngle, dpiScaling, uiTopSize, uiBottomSize, galleryHeight,
             containerWidth,
             containerHeight);
         var secondSize = GetImageSize(secondaryWidth, secondaryHeight, monitorWidth, monitorHeight, monitorMinWidth,
-            monitorMinHeight, interfaceSize, rotationAngle, padding, dpiScaling, uiTopSize, uiBottomSize,
+            monitorMinHeight, interfaceSize, rotationAngle, dpiScaling, uiTopSize, uiBottomSize,
             galleryHeight,
             containerWidth, containerHeight);
 
@@ -201,7 +205,7 @@ public static class ImageSizeCalculationHelper
 
         if (Settings.WindowProperties.AutoFit)
         {
-            var widthPadding = Settings.ImageScaling.StretchImage ? 4 : padding;
+            var widthPadding = Settings.ImageScaling.StretchImage ? 4 : Padding;
             var availableWidth = monitorWidth - widthPadding;
             var availableHeight = monitorHeight - (widthPadding + uiBottomSize + uiTopSize);
             if (rotationAngle is 0 or 180)
@@ -273,7 +277,7 @@ public static class ImageSizeCalculationHelper
                 var workAreaHeight = monitorHeight * dpiScaling - borderSpaceHeight;
                 scrollHeight = Settings.ImageScaling.StretchImage
                     ? workAreaHeight
-                    : workAreaHeight - padding;
+                    : workAreaHeight - Padding;
             }
             else
             {
@@ -325,25 +329,19 @@ public static class ImageSizeCalculationHelper
                 }
             }
 
-            titleMaxWidth = titleMaxWidth - interfaceSize < interfaceSize
-                ? interfaceSize
+            titleMaxWidth = titleMaxWidth - interfaceSize < MinTitleWidth
+                ? MinTitleWidth
                 : titleMaxWidth - interfaceSize;
-            
-            
-            if (Settings.Zoom.ScrollEnabled)
-            {
-                titleMaxWidth += SizeDefaults.ScrollbarSize + 10;
-            }
         }
         else
         {
             // Fix title width to window size
             titleMaxWidth = containerWidth - interfaceSize <= 0 ? 0 : containerWidth - interfaceSize;
-            
-            if (Settings.Zoom.ScrollEnabled)
-            {
-                titleMaxWidth += SizeDefaults.ScrollbarSize;
-            }
+        }
+
+        if (Settings.Zoom.ScrollEnabled)
+        {
+            titleMaxWidth += SizeDefaults.ScrollbarSize;
         }
 
         return titleMaxWidth;