From 5aa2c45536c5b00360936d5e4fb3a0b66d13d4a5 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 23 Nov 2026 00:19:04 -0500 Subject: [PATCH] fix(auto-nest): keep layout thumbnails full height when captions overflow A card whose sheet captions alone were wider than the strip shrank its sheets to a third of full height and scrolled anyway, so cards with more distinct sheets drew much smaller than the rest. They now keep full height and scroll. Co-Authored-By: Claude Opus 5.5 --- .../Forms/NestReviewFormTests.cs | 18 ++++++++++++++++++ OpenNest/Controls/SheetStripControl.cs | 10 +++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/OpenNest.WinForms.Tests/Forms/NestReviewFormTests.cs b/OpenNest.WinForms.Tests/Forms/NestReviewFormTests.cs index 95e386da..65b4d260 100644 --- a/OpenNest.WinForms.Tests/Forms/NestReviewFormTests.cs +++ b/OpenNest.WinForms.Tests/Forms/NestReviewFormTests.cs @@ -73,6 +73,24 @@ public class NestReviewFormTests Assert.Equal(200.0 / outline.Area, strip.Utilization, 6); }, TimeSpan.FromMinutes(1), "The STA test did not complete."); + [Fact] + public void SheetsKeepFullHeightWhenTheCaptionsAloneOverflowTheWidth() => 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 }; + + strip.SetSheets(new[] { new ProposedPlate(0, stock, Array.Empty()) }); + var one = strip.PixelsPerUnit; + // Twelve captions cannot fit 600 pixels at any scale. + strip.SetSheets(Enumerable.Range(0, 12) + .Select(i => new ProposedPlate(i, stock, Array.Empty())) + .ToArray()); + + Assert.True(one > 0); + Assert.Equal(one, strip.PixelsPerUnit, 3); + Assert.True(strip.AutoScrollMinSize.Width > strip.ClientSize.Width); + }, TimeSpan.FromMinutes(1), "The STA test did not complete."); + private static int SheetPixels(OpenNest.Controls.SheetStripControl strip) { using var bitmap = new System.Drawing.Bitmap(strip.Width, strip.Height); diff --git a/OpenNest/Controls/SheetStripControl.cs b/OpenNest/Controls/SheetStripControl.cs index 6ecdef84..620275bb 100644 --- a/OpenNest/Controls/SheetStripControl.cs +++ b/OpenNest/Controls/SheetStripControl.cs @@ -115,9 +115,11 @@ namespace OpenNest.Controls /// /// 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. + /// 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. /// - private float PixelsPerUnit + internal float PixelsPerUnit { get { @@ -128,8 +130,10 @@ namespace OpenNest.Controls if (tallest <= 0 || height <= 0) return 0; var full = (float)(height / tallest); - // Largest scale whose tiles, captions included, fit the width (tile widths grow with scale). 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++) {