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
This commit is contained in:
KazWolfe 2024-02-17 10:06:41 -08:00 committed by GitHub
parent e21b64969f
commit c19e1f0fcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 6 deletions

View file

@ -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;

View file

@ -148,7 +148,6 @@ internal class PluginInstallerWindow : Window, IDisposable
this.SizeConstraints = new WindowSizeConstraints
{
MinimumSize = this.Size.Value,
MaximumSize = new Vector2(5000, 5000),
};
Service<PluginManager>.GetAsync().ContinueWith(pluginManagerTask =>

View file

@ -43,7 +43,6 @@ public class StyleEditorWindow : Window
this.SizeConstraints = new WindowSizeConstraints
{
MinimumSize = new Vector2(890, 560),
MaximumSize = new Vector2(10000, 10000),
};
}

View file

@ -623,15 +623,38 @@ public abstract class Window
/// </summary>
public struct WindowSizeConstraints
{
private Vector2 internalMaxSize = new(float.MaxValue);
/// <summary>
/// Initializes a new instance of the <see cref="WindowSizeConstraints"/> struct.
/// </summary>
public WindowSizeConstraints()
{
}
/// <summary>
/// Gets or sets the minimum size of the window.
/// </summary>
public Vector2 MinimumSize { get; set; }
public Vector2 MinimumSize { get; set; } = new(0);
/// <summary>
/// Gets or sets the maximum size of the window.
/// </summary>
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;
}
}
/// <summary>