Sfoglia il codice sorgente

Size calculation update for setting padding

Ruben 5 mesi fa
parent
commit
a3d952e565

+ 1 - 1
src/PicView.Avalonia.MacOS/App.axaml.cs

@@ -232,7 +232,7 @@ public class App : Application, IPlatformSpecificService, IPlatformWindowService
     
     
     #endregion
     #endregion
     
     
-    public int Padding { get; set; } // TODO should be the width or height of the dock. Half if auto-hiding
+    public double Padding { get; set; } // TODO should be the width or height of the dock. Half if auto-hiding
 
 
     public int CombinedTitleButtonsWidth { get; set; } = 165;
     public int CombinedTitleButtonsWidth { get; set; } = 165;
     
     

+ 13 - 3
src/PicView.Avalonia.Win32/App.axaml.cs

@@ -9,6 +9,7 @@ using PicView.Avalonia.ColorManagement;
 using PicView.Avalonia.Interfaces;
 using PicView.Avalonia.Interfaces;
 using PicView.Avalonia.Navigation;
 using PicView.Avalonia.Navigation;
 using PicView.Avalonia.StartUp;
 using PicView.Avalonia.StartUp;
+using PicView.Avalonia.UI;
 using PicView.Avalonia.ViewModels;
 using PicView.Avalonia.ViewModels;
 using PicView.Avalonia.Win32.Views;
 using PicView.Avalonia.Win32.Views;
 using PicView.Avalonia.Win32.WindowImpl;
 using PicView.Avalonia.Win32.WindowImpl;
@@ -88,10 +89,19 @@ public class App : Application, IPlatformSpecificService, IPlatformWindowService
 #endif
 #endif
         }
         }
     }
     }
-    
-    public int Padding { get; set; } = 45;
 
 
-    public int CombinedTitleButtonsWidth { get; set; } = 215;
+    public double Padding
+    {
+        get => Settings.WindowProperties.Padding / ScreenHelper.ScreenSize.Scaling;
+    }
+
+    public int CombinedTitleButtonsWidth
+    {
+        get => (int)(Settings.WindowProperties.Maximized && !Settings.WindowProperties.Fullscreen
+            ? _mainWindow?.OffScreenMargin.Left + _mainWindow?.OffScreenMargin.Right + field ?? field
+            : field);
+        set;
+    } = 215;
 
 
     #region Interface Implementations
     #region Interface Implementations
     
     

+ 1 - 1
src/PicView.Avalonia/Interfaces/IPlatformWindowService.cs

@@ -5,7 +5,7 @@ public interface IPlatformWindowService
     /// <summary>
     /// <summary>
     /// Gets or sets the padding used to calculate space between the screen and the window.
     /// Gets or sets the padding used to calculate space between the screen and the window.
     /// </summary>
     /// </summary>
-    int Padding { get; set; }
+    double Padding { get; }
 
 
     /// <summary>
     /// <summary>
     /// Gets or sets the width of the buttons on the respective title bar implementation.
     /// Gets or sets the width of the buttons on the respective title bar implementation.

+ 9 - 2
src/PicView.Avalonia/StartUp/StartUpHelper.cs

@@ -89,9 +89,16 @@ public static class StartUpHelper
 
 
     public static void HandleWindowScalingMode(MainViewModel vm, Window window)
     public static void HandleWindowScalingMode(MainViewModel vm, Window window)
     {
     {
+        ScreenHelper.UpdateScreenSize(window);
+        if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+        {
+            if (Settings.WindowProperties.Padding <= 0)
+            {
+                Settings.WindowProperties.Padding = 45;
+            }
+        }
         if (Settings.WindowProperties.AutoFit)
         if (Settings.WindowProperties.AutoFit)
         {
         {
-            ScreenHelper.UpdateScreenSize(window);
             HandleAutoFit(vm, window);
             HandleAutoFit(vm, window);
         }
         }
         else
         else
@@ -361,7 +368,7 @@ public static class StartUpHelper
         vm.IsAutoFit  = Settings.WindowProperties.AutoFit;
         vm.IsAutoFit  = Settings.WindowProperties.AutoFit;
         vm.IsStayingCentered  = Settings.WindowProperties.KeepCentered;
         vm.IsStayingCentered  = Settings.WindowProperties.KeepCentered;
         vm.IsOpeningInSameWindow  = Settings.UIProperties.OpenInSameWindow;
         vm.IsOpeningInSameWindow  = Settings.UIProperties.OpenInSameWindow;
-        vm.IsShowingConfirmationOnEsc  = Settings.UIProperties.ShowConfirmationOnEsc;
+        vm.IsShowingConfirmationOnEsc  = Settings.UIProperties.ShowConfirmationOnEsc;   
         vm.IsUsingTouchpad  = Settings.Zoom.IsUsingTouchPad;
         vm.IsUsingTouchpad  = Settings.Zoom.IsUsingTouchPad;
         vm.IsAscending  = Settings.Sorting.Ascending;
         vm.IsAscending  = Settings.Sorting.Ascending;
         vm.BackgroundChoice = Settings.UIProperties.BgColorChoice;
         vm.BackgroundChoice = Settings.UIProperties.BgColorChoice;

+ 1 - 6
src/PicView.Avalonia/UI/ScreenHelper.cs

@@ -1,5 +1,4 @@
-using System.Runtime.InteropServices;
-using Avalonia.Controls;
+using Avalonia.Controls;
 using PicView.Core.Sizing;
 using PicView.Core.Sizing;
 
 
 namespace PicView.Avalonia.UI;
 namespace PicView.Avalonia.UI;
@@ -33,10 +32,6 @@ public static class ScreenHelper
         // Need to lock it to prevent multiple calls
         // Need to lock it to prevent multiple calls
         lock (Lock)
         lock (Lock)
         {
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
-            {
-                // TODO: Get macOS dock size
-            }
             var screen = window.Screens.ScreenFromVisual(window);
             var screen = window.Screens.ScreenFromVisual(window);
         
         
             var monitorWidth = screen.WorkingArea.Width / screen.Scaling;
             var monitorWidth = screen.WorkingArea.Width / screen.Scaling;

+ 1 - 1
src/PicView.Avalonia/Views/StartUpMenu.axaml.cs

@@ -127,7 +127,7 @@ public partial class StartUpMenu : UserControl
         }
         }
 
 
         var titleMaxWidth = ImageSizeCalculationHelper.GetTitleMaxWidth(vm.RotationAngle, width, height,
         var titleMaxWidth = ImageSizeCalculationHelper.GetTitleMaxWidth(vm.RotationAngle, width, height,
-            desktop.MainWindow.MinWidth, desktop.MainWindow.MinHeight, ImageSizeCalculationHelper.GetInterfaceSize(),
+            desktop.MainWindow.MinWidth, desktop.MainWindow.MinHeight, vm.PlatformWindowService.CombinedTitleButtonsWidth,
             desktop.MainWindow.Width);
             desktop.MainWindow.Width);
 
 
         if (Settings.Zoom.ScrollEnabled)
         if (Settings.Zoom.ScrollEnabled)

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

@@ -226,6 +226,7 @@ public static class WindowResizing
         if (Settings.ImageScaling.ShowImageSideBySide && secondWidth > 0 && secondHeight > 0)
         if (Settings.ImageScaling.ShowImageSideBySide && secondWidth > 0 && secondHeight > 0)
         {
         {
             size = ImageSizeCalculationHelper.GetSideBySideImageSize(
             size = ImageSizeCalculationHelper.GetSideBySideImageSize(
+                vm.PlatformWindowService.Padding,
                 width,
                 width,
                 height,
                 height,
                 secondWidth,
                 secondWidth,
@@ -233,7 +234,7 @@ public static class WindowResizing
                 screenSize,
                 screenSize,
                 desktopMinWidth,
                 desktopMinWidth,
                 desktopMinHeight,
                 desktopMinHeight,
-                ImageSizeCalculationHelper.GetInterfaceSize(),
+                vm.PlatformWindowService.CombinedTitleButtonsWidth,
                 rotation,
                 rotation,
                 screenSize.Scaling,
                 screenSize.Scaling,
                 vm.TitlebarHeight,
                 vm.TitlebarHeight,
@@ -245,12 +246,13 @@ public static class WindowResizing
         else
         else
         {
         {
             size = ImageSizeCalculationHelper.GetImageSize(
             size = ImageSizeCalculationHelper.GetImageSize(
+                vm.PlatformWindowService.Padding,
                 width,
                 width,
                 height,
                 height,
                 screenSize,
                 screenSize,
                 desktopMinWidth,
                 desktopMinWidth,
                 desktopMinHeight,
                 desktopMinHeight,
-                ImageSizeCalculationHelper.GetInterfaceSize(),
+                vm.PlatformWindowService.CombinedTitleButtonsWidth,
                 rotation,
                 rotation,
                 screenSize.Scaling,
                 screenSize.Scaling,
                 vm.TitlebarHeight,
                 vm.TitlebarHeight,

+ 2 - 1
src/PicView.Core/Config/AppSettings.cs

@@ -2,7 +2,7 @@
 
 
 public class AppSettings
 public class AppSettings
 {
 {
-    public double Version { get; set; } = 1.4;
+    public double Version { get; set; } = SettingsConfiguration.CurrentSettingsVersion;
     public WindowProperties? WindowProperties { get; set; }
     public WindowProperties? WindowProperties { get; set; }
     public UIProperties? UIProperties { get; set; }
     public UIProperties? UIProperties { get; set; }
     public Theme? Theme { get; set; }
     public Theme? Theme { get; set; }
@@ -24,6 +24,7 @@ public class WindowProperties
     public bool Maximized { get; set; } = false;
     public bool Maximized { get; set; } = false;
     public bool Fullscreen { get; set; } = false;
     public bool Fullscreen { get; set; } = false;
     public bool KeepCentered { get; set; } = false;
     public bool KeepCentered { get; set; } = false;
+    public double Padding { get; set; } = 0;
 }
 }
 
 
 public class UIProperties
 public class UIProperties

+ 1 - 1
src/PicView.Core/Config/SettingsConfiguration.cs

@@ -2,7 +2,7 @@
 
 
 public static class SettingsConfiguration
 public static class SettingsConfiguration
 {
 {
-    public const double CurrentSettingsVersion = 1.3;
+    public const double CurrentSettingsVersion = 1.5;
     
     
     public const string ConfigFileName = "UserSettings.json";
     public const string ConfigFileName = "UserSettings.json";
     public const string LocalConfigFilePath = "Config/" + ConfigFileName;
     public const string LocalConfigFilePath = "Config/" + ConfigFileName;

+ 18 - 36
src/PicView.Core/Sizing/ImageSizeCalculationHelper.cs

@@ -1,28 +1,12 @@
-using System.Runtime.InteropServices;
-
-namespace PicView.Core.Sizing;
+namespace PicView.Core.Sizing;
 
 
 public static class ImageSizeCalculationHelper
 public static class ImageSizeCalculationHelper
 {
 {
     private const int MinTitleWidth = 250;
     private const int MinTitleWidth = 250;
-    private const int Padding = 45;
-    
-    /// <summary>
-    ///  Returns the interface size of the titlebar based on OS
-    /// </summary>
-    public static double GetInterfaceSize()
-    {
-        // TODO: find a more elegant solution
-        return RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 165 : 215;
-    }
     
     
-    public static double GetWindowMargin()
-    {
-        // TODO: find a more elegant solution
-        return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 7 : 0;
-    }
-
-    public static ImageSize GetImageSize(double width,
+    public static ImageSize GetImageSize(
+        double padding,
+        double width,
         double height,
         double height,
         ScreenSize screenSize,
         ScreenSize screenSize,
         double minWidth,
         double minWidth,
@@ -49,7 +33,7 @@ public static class ImageSizeCalculationHelper
                          Settings.WindowProperties.Maximized;
                          Settings.WindowProperties.Maximized;
             
             
         var borderSpaceHeight = fullscreen ? 0 : uiTopSize + uiBottomSize + galleryHeight;
         var borderSpaceHeight = fullscreen ? 0 : uiTopSize + uiBottomSize + galleryHeight;
-        var borderSpaceWidth = fullscreen ? 0 : Padding;
+        var borderSpaceWidth = fullscreen ? 0 : padding;
 
 
         var workAreaWidth = screenSize.WorkingAreaWidth - borderSpaceWidth;
         var workAreaWidth = screenSize.WorkingAreaWidth - borderSpaceWidth;
         var workAreaHeight = screenSize.WorkingAreaHeight - borderSpaceHeight;
         var workAreaHeight = screenSize.WorkingAreaHeight - borderSpaceHeight;
@@ -61,19 +45,19 @@ public static class ImageSizeCalculationHelper
 
 
             maxWidth = Settings.ImageScaling.StretchImage 
             maxWidth = Settings.ImageScaling.StretchImage 
                 ? workAreaWidth 
                 ? workAreaWidth 
-                : Math.Min(workAreaWidth - Padding, width);
+                : Math.Min(workAreaWidth - padding, width);
             
             
             maxHeight = workAreaHeight;
             maxHeight = workAreaHeight;
         }
         }
         else if (Settings.WindowProperties.AutoFit)
         else if (Settings.WindowProperties.AutoFit)
         {
         {
             maxWidth = Settings.ImageScaling.StretchImage
             maxWidth = Settings.ImageScaling.StretchImage
-                ? workAreaWidth - Padding
-                : Math.Min(workAreaWidth - Padding, width);
+                ? workAreaWidth - padding
+                : Math.Min(workAreaWidth - padding, width);
                     
                     
             maxHeight = Settings.ImageScaling.StretchImage
             maxHeight = Settings.ImageScaling.StretchImage
-                ? workAreaHeight - Padding
-                : Math.Min(workAreaHeight - Padding, height);
+                ? workAreaHeight - padding
+                : Math.Min(workAreaHeight - padding, height);
         }
         }
         else
         else
         {
         {
@@ -146,7 +130,7 @@ public static class ImageSizeCalculationHelper
                 xWidth = width * aspectRatio;
                 xWidth = width * aspectRatio;
                 xHeight = height * aspectRatio;
                 xHeight = height * aspectRatio;
 
 
-                scrollWidth = Math.Max(xWidth + SizeDefaults.ScrollbarSize, SizeDefaults.WindowMinSize + SizeDefaults.ScrollbarSize + Padding + 16);
+                scrollWidth = Math.Max(xWidth + SizeDefaults.ScrollbarSize, SizeDefaults.WindowMinSize + SizeDefaults.ScrollbarSize + padding + 16);
                 scrollHeight = containerHeight - margin;
                 scrollHeight = containerHeight - margin;
             }
             }
             else
             else
@@ -173,7 +157,9 @@ public static class ImageSizeCalculationHelper
         return new ImageSize(xWidth, xHeight, 0, scrollWidth, scrollHeight, titleMaxWidth, margin, aspectRatio);
         return new ImageSize(xWidth, xHeight, 0, scrollWidth, scrollHeight, titleMaxWidth, margin, aspectRatio);
     }
     }
 
 
-    public static ImageSize GetSideBySideImageSize(double width,
+    public static ImageSize GetSideBySideImageSize(
+        double padding,
+        double width,
         double height,
         double height,
         double secondaryWidth,
         double secondaryWidth,
         double secondaryHeight,
         double secondaryHeight,
@@ -196,11 +182,11 @@ public static class ImageSizeCalculationHelper
         }
         }
 
 
         // Get sizes for both images
         // Get sizes for both images
-        var firstSize = GetImageSize(width, height, screenSize, minWidth, minHeight,
+        var firstSize = GetImageSize(padding, width, height, screenSize, minWidth, minHeight,
             interfaceSize, rotationAngle, dpiScaling, uiTopSize, uiBottomSize, galleryHeight,
             interfaceSize, rotationAngle, dpiScaling, uiTopSize, uiBottomSize, galleryHeight,
             containerWidth,
             containerWidth,
             containerHeight);
             containerHeight);
-        var secondSize = GetImageSize(secondaryWidth, secondaryHeight, screenSize, minWidth,
+        var secondSize = GetImageSize(padding, secondaryWidth, secondaryHeight, screenSize, minWidth,
             minHeight, interfaceSize, rotationAngle, dpiScaling, uiTopSize, uiBottomSize,
             minHeight, interfaceSize, rotationAngle, dpiScaling, uiTopSize, uiBottomSize,
             galleryHeight,
             galleryHeight,
             containerWidth, containerHeight);
             containerWidth, containerHeight);
@@ -217,7 +203,7 @@ public static class ImageSizeCalculationHelper
 
 
         if (Settings.WindowProperties.AutoFit)
         if (Settings.WindowProperties.AutoFit)
         {
         {
-            var widthPadding = Settings.ImageScaling.StretchImage ? 4 : Padding;
+            var widthPadding = Settings.ImageScaling.StretchImage ? 4 : padding;
             var availableWidth = screenSize.WorkingAreaWidth - widthPadding;
             var availableWidth = screenSize.WorkingAreaWidth - widthPadding;
             var availableHeight = screenSize.WorkingAreaHeight - (widthPadding + uiBottomSize + uiTopSize);
             var availableHeight = screenSize.WorkingAreaHeight - (widthPadding + uiBottomSize + uiTopSize);
             if (rotationAngle is 0 or 180)
             if (rotationAngle is 0 or 180)
@@ -288,7 +274,7 @@ public static class ImageSizeCalculationHelper
                 var borderSpaceHeight = fullscreen ? 0 : uiTopSize + uiBottomSize + galleryHeight;
                 var borderSpaceHeight = fullscreen ? 0 : uiTopSize + uiBottomSize + galleryHeight;
                 var workAreaHeight = screenSize.WorkingAreaHeight * dpiScaling - borderSpaceHeight;
                 var workAreaHeight = screenSize.WorkingAreaHeight * dpiScaling - borderSpaceHeight;
                 scrollHeight = Math.Min(xHeight,
                 scrollHeight = Math.Min(xHeight,
-                    Settings.ImageScaling.StretchImage ? workAreaHeight : workAreaHeight - Padding);
+                    Settings.ImageScaling.StretchImage ? workAreaHeight : workAreaHeight - padding);
             }
             }
             else
             else
             {
             {
@@ -344,10 +330,6 @@ public static class ImageSizeCalculationHelper
         }
         }
         else
         else
         {
         {
-            if (Settings.WindowProperties.Maximized)
-            {
-                interfaceSize += GetWindowMargin() * 2;
-            }
             // Fix title width to window size
             // Fix title width to window size
             titleMaxWidth = containerWidth - interfaceSize;
             titleMaxWidth = containerWidth - interfaceSize;
         }
         }