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
+4
View File
@@ -125,6 +125,10 @@ namespace OpenNest.Controls
pt.Y += 18; pt.Y += 18;
e.Graphics.DrawString(text3, Font, detailBrush, pt); 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) protected override void OnMouseMove(MouseEventArgs e)
+27 -3
View File
@@ -259,6 +259,11 @@ namespace OpenNest.Forms
public void UpdateDrawingList() public void UpdateDrawingList()
{ {
var topIndex = drawingListBox1.TopIndex;
var selected = drawingListBox1.SelectedItem;
drawingListBox1.BeginUpdate();
drawingListBox1.Items.Clear(); drawingListBox1.Items.Clear();
foreach (var dwg in Nest.Drawings.OrderBy(d => d.Name).ToList()) foreach (var dwg in Nest.Drawings.OrderBy(d => d.Name).ToList())
@@ -268,6 +273,14 @@ namespace OpenNest.Forms
drawingListBox1.Items.Add(dwg); 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() public void Save()
@@ -935,9 +948,20 @@ namespace OpenNest.Forms
drawingListBox1.Invoke(new MethodInvoker(() => drawingListBox1.Invoke(new MethodInvoker(() =>
{ {
if (hideNestedButton.Checked) if (hideNestedButton.Checked)
UpdateDrawingList(); {
else drawingListBox1.BeginUpdate();
drawingListBox1.Refresh();
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();
})); }));
} }