Files
OpenNest/OpenNest.Avalonia/DrawingListItem.cs
T
ajandClaude Opus 5.5 7635846094 feat(avalonia): port the Drawings tab and Drawing Properties
The Drawings tab now shows the WinForms rows: each drawing's picture, name,
"[on this plate] nested of required nested", size and area, with the
fully-nested highlight and quantity bar, refreshed 50 ms after parts change
on the shown plate or the nest is edited. Its toolbar sorts the list (the
choice shared with the WinForms app) and hides the fully nested drawings,
with the note to show them again. Its menu deletes a drawing or removes the
unused ones after the WinForms confirmations, and a double-click opens
Drawing Properties; each edit is one undo step through the shared commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:53:18 -05:00

79 lines
2.9 KiB
C#

using System.ComponentModel;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using OpenNest.Avalonia.Rendering;
using OpenNest.Desktop;
namespace OpenNest.Avalonia
{
/// <summary>
/// One row of the Drawings tab list: the shared <see cref="DrawingListRow"/> with its picture
/// and the WinForms row colors (a pale yellow row once nothing remains to nest, a green or
/// orange bar for a required quantity that is or is not all nested). The list updates a row
/// in place while the drawings and their order stay the same.
/// </summary>
public sealed class DrawingListItem : INotifyPropertyChanged
{
/// <summary>The picture's size, as the WinForms list draws it.</summary>
public const int ThumbnailWidth = 85;
public const int ThumbnailHeight = 75;
private static readonly IBrush Plain = Brushes.White;
private static readonly IBrush Highlight = new SolidColorBrush(Color.FromRgb(255, 255, 225));
private static readonly IBrush CompleteBar = new SolidColorBrush(Color.FromRgb(76, 175, 80));
private static readonly IBrush ShortBar = new SolidColorBrush(Color.FromRgb(255, 152, 0));
private DrawingListRow row;
private double scaling;
public DrawingListItem(DrawingListRow row, double scaling)
{
this.row = row;
this.scaling = scaling;
}
public event PropertyChangedEventHandler PropertyChanged;
public Drawing Drawing => row.Drawing;
public string Name => row.Name;
public string Quantity => row.Quantity;
public bool HasQuantity => row.Quantity != null;
public string Size => row.Size;
public string Area => row.Area;
public IBrush Background => row.IsHighlighted ? Highlight : Plain;
public IBrush Bar => row.Bar switch
{
DrawingQuantityBar.Complete => CompleteBar,
DrawingQuantityBar.Short => ShortBar,
_ => Brushes.Transparent,
};
// Drawn when first shown and cached per drawing until its program or color changes.
public Bitmap Thumbnail => DrawingThumbnail.For(row.Drawing, ThumbnailWidth, ThumbnailHeight, scaling);
/// <summary>Shows <paramref name="value"/>, the same drawing's current row.</summary>
public void Update(DrawingListRow value, double renderScaling)
{
row = value;
scaling = renderScaling;
// Every property: a color or program change redraws the picture too.
foreach (var name in Properties)
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
private static readonly string[] Properties =
{
nameof(Drawing), nameof(Name), nameof(Quantity), nameof(HasQuantity), nameof(Size), nameof(Area),
nameof(Background), nameof(Bar), nameof(Thumbnail),
};
}
}