refactor(desktop): share the large browse dialogs' sizing

LargeDialogBounds computes the bounds the large browse dialogs open at:
nine tenths of the owner screen's working area, centered, never below the
dialog's minimum size. WinForms' DialogBounds now calls it with the
screen's working area, with unchanged behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-11-11 21:13:53 -05:00
1 parent cb5e2a5854
commit a7302d3224
3 files changed
+58 -7

No files matched your search

@@ -0,0 +1,28 @@
namespace OpenNest.Desktop.Tests;
public class LargeDialogBoundsTests
{
[Fact]
public void Centered_NineTenthsOfTheWorkingArea()
{
var bounds = LargeDialogBounds.Centered(new PixelRect(0, 0, 1920, 1040), 800, 600);
Assert.Equal(new PixelRect(96, 52, 1728, 936), bounds);
}
[Fact]
public void Centered_OnASecondaryScreen()
{
var bounds = LargeDialogBounds.Centered(new PixelRect(1920, -200, 2560, 1400), 800, 600);
Assert.Equal(new PixelRect(1920 + 128, -200 + 70, 2304, 1260), bounds);
}
[Fact]
public void Centered_NeverBelowTheMinimumOrBeforeTheWorkingArea()
{
var bounds = LargeDialogBounds.Centered(new PixelRect(100, 50, 1000, 700), 1200, 900);
Assert.Equal(new PixelRect(100, 50, 1200, 900), bounds);
}
}
+24
View File
@@ -0,0 +1,24 @@
namespace OpenNest.Desktop;
/// <summary>
/// Sizing shared by the large browse dialogs (File &gt; Open, Drawing Library, Shape Library) so
/// they open at the same size: a normal window nine tenths of the owner screen's working area,
/// centered in it so its bottom row stays clear of the taskbar.
/// </summary>
public static class LargeDialogBounds
{
/// <summary>
/// The bounds in <paramref name="workingArea"/> (screen pixels), never smaller than the
/// dialog's minimum size and never starting left of or above the working area.
/// </summary>
public static PixelRect Centered(PixelRect workingArea, int minimumWidth, int minimumHeight)
{
var width = System.Math.Max(minimumWidth, workingArea.Width * 9 / 10);
var height = System.Math.Max(minimumHeight, workingArea.Height * 9 / 10);
return new PixelRect(
System.Math.Max(workingArea.X, workingArea.X + (workingArea.Width - width) / 2),
System.Math.Max(workingArea.Y, workingArea.Y + (workingArea.Height - height) / 2),
width,
height);
}
}
+6 -7
View File
@@ -1,5 +1,6 @@
using System.Drawing;
using System.Windows.Forms;
using OpenNest.Desktop;
namespace OpenNest.Forms;
@@ -20,12 +21,10 @@ internal static class DialogBounds
public static void FitToOwnerScreen(Form form)
{
var area = Screen.FromControl(form.Owner ?? form).WorkingArea;
var width = System.Math.Max(form.MinimumSize.Width, area.Width * 9 / 10);
var height = System.Math.Max(form.MinimumSize.Height, area.Height * 9 / 10);
form.Bounds = new Rectangle(
System.Math.Max(area.Left, area.Left + (area.Width - width) / 2),
System.Math.Max(area.Top, area.Top + (area.Height - height) / 2),
width,
height);
var bounds = LargeDialogBounds.Centered(
new PixelRect(area.X, area.Y, area.Width, area.Height),
form.MinimumSize.Width,
form.MinimumSize.Height);
form.Bounds = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height);
}
}