From c19e1f0fcd224ec4b3cef14a48d921e34eff8375 Mon Sep 17 00:00:00 2001 From: KazWolfe Date: Sat, 17 Feb 2024 10:06:41 -0800 Subject: [PATCH] Default Minimum/Maximum WindowSizeConstraints (#1574) * feat: Default Minimum/Maximum WindowSizeConstraints If `MinimumSize` or `MaximumSize` are not set when defining a `WindowSizeConstraints`, they will be effectively unbounded. * chore: Make internal windows unbounded on max size * Ignore max value if it's smaller than minimum in any dimension --- .../Internal/Windows/ConsoleWindow.cs | 1 - .../PluginInstaller/PluginInstallerWindow.cs | 1 - .../Windows/StyleEditor/StyleEditorWindow.cs | 1 - Dalamud/Interface/Windowing/Window.cs | 29 +++++++++++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs b/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs index 1b9890a75..63924365d 100644 --- a/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs @@ -71,7 +71,6 @@ internal class ConsoleWindow : Window, IDisposable this.SizeConstraints = new WindowSizeConstraints { MinimumSize = new Vector2(600.0f, 200.0f), - MaximumSize = new Vector2(9999.0f, 9999.0f), }; this.RespectCloseHotkey = false; diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index 83d819634..95c227662 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -148,7 +148,6 @@ internal class PluginInstallerWindow : Window, IDisposable this.SizeConstraints = new WindowSizeConstraints { MinimumSize = this.Size.Value, - MaximumSize = new Vector2(5000, 5000), }; Service.GetAsync().ContinueWith(pluginManagerTask => diff --git a/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs index c202a36ce..9ee4123cd 100644 --- a/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs +++ b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs @@ -43,7 +43,6 @@ public class StyleEditorWindow : Window this.SizeConstraints = new WindowSizeConstraints { MinimumSize = new Vector2(890, 560), - MaximumSize = new Vector2(10000, 10000), }; } diff --git a/Dalamud/Interface/Windowing/Window.cs b/Dalamud/Interface/Windowing/Window.cs index 59cb4d570..a7565c294 100644 --- a/Dalamud/Interface/Windowing/Window.cs +++ b/Dalamud/Interface/Windowing/Window.cs @@ -623,15 +623,38 @@ public abstract class Window /// public struct WindowSizeConstraints { + private Vector2 internalMaxSize = new(float.MaxValue); + + /// + /// Initializes a new instance of the struct. + /// + public WindowSizeConstraints() + { + } + /// /// Gets or sets the minimum size of the window. /// - public Vector2 MinimumSize { get; set; } - + public Vector2 MinimumSize { get; set; } = new(0); + /// /// Gets or sets the maximum size of the window. /// - public Vector2 MaximumSize { get; set; } + public Vector2 MaximumSize + { + get => this.GetSafeMaxSize(); + set => this.internalMaxSize = value; + } + + private Vector2 GetSafeMaxSize() + { + var currentMin = this.MinimumSize; + + if (this.internalMaxSize.X < currentMin.X || this.internalMaxSize.Y < currentMin.Y) + return new Vector2(float.MaxValue); + + return this.internalMaxSize; + } } ///