From 1eba3e7cdef4e24af79d33ed13e7d32b5a377378 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 6 Apr 2026 07:53:53 -0400 Subject: [PATCH] fix: improve DrawingListBox rendering and scroll stability Add LightGray separator lines between items to visually distinguish adjacent quantity bars. Preserve scroll position and selection when updating the drawing list by saving/restoring TopIndex and SelectedItem. Use incremental item removal instead of full list rebuild when hiding depleted drawings. Wrap list modifications in BeginUpdate/EndUpdate to reduce flicker. Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest/Controls/DrawingListBox.cs | 4 ++++ OpenNest/Forms/EditNestForm.cs | 30 ++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/OpenNest/Controls/DrawingListBox.cs b/OpenNest/Controls/DrawingListBox.cs index 60a180c..9982b16 100644 --- a/OpenNest/Controls/DrawingListBox.cs +++ b/OpenNest/Controls/DrawingListBox.cs @@ -125,6 +125,10 @@ namespace OpenNest.Controls pt.Y += 18; e.Graphics.DrawString(text3, Font, detailBrush, pt); } + + using var separatorPen = new Pen(Color.LightGray); + var separatorY = e.Bounds.Bottom - 1; + e.Graphics.DrawLine(separatorPen, e.Bounds.X, separatorY, e.Bounds.Right, separatorY); } protected override void OnMouseMove(MouseEventArgs e) diff --git a/OpenNest/Forms/EditNestForm.cs b/OpenNest/Forms/EditNestForm.cs index 0a475fc..5a5334f 100644 --- a/OpenNest/Forms/EditNestForm.cs +++ b/OpenNest/Forms/EditNestForm.cs @@ -259,6 +259,11 @@ namespace OpenNest.Forms public void UpdateDrawingList() { + var topIndex = drawingListBox1.TopIndex; + var selected = drawingListBox1.SelectedItem; + + drawingListBox1.BeginUpdate(); + drawingListBox1.Items.Clear(); foreach (var dwg in Nest.Drawings.OrderBy(d => d.Name).ToList()) @@ -268,6 +273,14 @@ namespace OpenNest.Forms drawingListBox1.Items.Add(dwg); } + + if (selected != null && drawingListBox1.Items.Contains(selected)) + drawingListBox1.SelectedItem = selected; + + if (topIndex < drawingListBox1.Items.Count) + drawingListBox1.TopIndex = topIndex; + + drawingListBox1.EndUpdate(); } public void Save() @@ -935,9 +948,20 @@ namespace OpenNest.Forms drawingListBox1.Invoke(new MethodInvoker(() => { if (hideNestedButton.Checked) - UpdateDrawingList(); - else - drawingListBox1.Refresh(); + { + drawingListBox1.BeginUpdate(); + + for (var i = drawingListBox1.Items.Count - 1; i >= 0; i--) + { + var dwg = (Drawing)drawingListBox1.Items[i]; + if (dwg.Quantity.Required > 0 && dwg.Quantity.Remaining == 0) + drawingListBox1.Items.RemoveAt(i); + } + + drawingListBox1.EndUpdate(); + } + + drawingListBox1.Invalidate(); })); }