diff --git a/OpenNest.WinForms.Tests/Forms/NestReviewFormTests.cs b/OpenNest.WinForms.Tests/Forms/NestReviewFormTests.cs index 42bbfa27..0ce40224 100644 --- a/OpenNest.WinForms.Tests/Forms/NestReviewFormTests.cs +++ b/OpenNest.WinForms.Tests/Forms/NestReviewFormTests.cs @@ -74,7 +74,7 @@ public class NestReviewFormTests }, TimeSpan.FromMinutes(1), "The STA test did not complete."); [Fact] - public void SheetsKeepFullHeightWhenTheCaptionsAloneOverflowTheWidth() => StaTestThread.Run(() => + public void TwoSheetsFillTheWidthWhenTheyCannotAllFit() => StaTestThread.Run(() => { var stock = new NestPlateStock("sheet", new Size(48, 96), quantity: null, partSpacing: 0.25); using var strip = new OpenNest.Controls.SheetStripControl { Size = new System.Drawing.Size(600, 300), ShowRemnant = true }; @@ -85,9 +85,13 @@ public class NestReviewFormTests strip.SetSheets(Enumerable.Range(0, 12) .Select(i => new ProposedPlate(i, stock, Array.Empty())) .ToArray()); + var scale = strip.PixelsPerUnit; + // One sheet fits at full height; of twelve, the first two share the width. Assert.True(one > 0); - Assert.Equal(one, strip.PixelsPerUnit, 3); + Assert.True(scale < one); + var twoSheets = 2 * 96 * scale + 16; + Assert.InRange(twoSheets, strip.ClientSize.Width - 16 - 8, strip.ClientSize.Width - 16); Assert.True(strip.AutoScrollMinSize.Width > strip.ClientSize.Width); }, TimeSpan.FromMinutes(1), "The STA test did not complete."); diff --git a/OpenNest/Controls/SheetStripControl.cs b/OpenNest/Controls/SheetStripControl.cs index 35db6354..ac69b7c1 100644 --- a/OpenNest/Controls/SheetStripControl.cs +++ b/OpenNest/Controls/SheetStripControl.cs @@ -120,10 +120,9 @@ namespace OpenNest.Controls : $"{tile.Title}\n{tile.Detail}"; /// - /// Pixels per world unit, shared by every sheet. All sheets fit the width when they can; - /// otherwise they shrink to a third of full height and the strip scrolls. When the - /// captions alone are wider than the strip, shrinking cannot avoid the scroll, so the - /// sheets keep full height and the strip scrolls. + /// Pixels per world unit, shared by every sheet and at most full height. All sheets fit + /// the width when that keeps them at least a third of full height; otherwise the strip + /// scrolls with the first two sheets filling the view, so two whole plates always show. /// internal float PixelsPerUnit { @@ -136,23 +135,34 @@ namespace OpenNest.Controls if (tallest <= 0 || height <= 0) return 0; var full = (float)(height / tallest); - var width = ClientSize.Width - Edge * 2 - Gap * (tiles.Count - 1); - if (tiles.Sum(t => TileWidth(t, 0)) > width) - return full; - // Largest scale whose tiles, captions included, fit the width (tile widths grow with scale). - float low = 0, high = full; - for (var i = 0; i < 24; i++) - { - var mid = (low + high) / 2; - if (tiles.Sum(t => TileWidth(t, mid)) <= width) - low = mid; - else - high = mid; - } - return System.Math.Max(low, full / 3); + var all = FitScale(tiles, full); + if (all >= full / 3) + return all; + var two = FitScale(tiles.Take(2).ToList(), full); + return two > 0 ? two : full / 3; } } + /// The largest scale up to at which , + /// captions included, fit the width; 0 when their captions alone are too wide. + private float FitScale(IReadOnlyCollection shown, float full) + { + var width = ClientSize.Width - Edge * 2 - Gap * (shown.Count - 1); + if (shown.Sum(t => TileWidth(t, 0)) > width) + return 0; + // Tile widths grow with scale, so bisect. + float low = 0, high = full; + for (var i = 0; i < 24; i++) + { + var mid = (low + high) / 2; + if (shown.Sum(t => TileWidth(t, mid)) <= width) + low = mid; + else + high = mid; + } + return low; + } + private void UpdateScrollSize() { var scale = PixelsPerUnit; diff --git a/OpenNest/Forms/NestProgressForm.cs b/OpenNest/Forms/NestProgressForm.cs index 8c7e3eed..dccf5e9e 100644 --- a/OpenNest/Forms/NestProgressForm.cs +++ b/OpenNest/Forms/NestProgressForm.cs @@ -204,11 +204,12 @@ namespace OpenNest.Forms Controls.Add(header); Controls.Add(footer); MinimumSize = new System.Drawing.Size(640, 420); - // Tall enough that the layout cards stay readable while the search runs. + // Wide, since a card shows its first two sheets side by side across the width, and + // tall enough that the layout cards stay readable while the search runs. var screen = Owner != null ? Screen.FromControl(Owner) : Screen.FromPoint(Cursor.Position); Size = new System.Drawing.Size( - Size.Width - ClientSize.Width + 920, - System.Math.Max(MinimumSize.Height, (int)(screen.WorkingArea.Height * 0.8))); + System.Math.Max(MinimumSize.Width, (int)(screen.WorkingArea.Width * 0.85)), + System.Math.Max(MinimumSize.Height, (int)(screen.WorkingArea.Height * 0.75))); ResumeLayout(true); }