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) <noreply@anthropic.com>
This commit is contained in:
2026-04-06 07:53:53 -04:00
parent d65f3460a9
commit 1eba3e7cde
2 changed files with 31 additions and 3 deletions

View File

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

View File

@@ -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();
}));
}