Columns + CellWidth/CellHeight + a row-major CellOffset/LayoutCells pass. CellWidth<=0 keeps the single-cell fill mode (toolbar slot sizes to the list — unchanged); CellWidth>0 tiles cells in a grid. Layout runs on AddItem and per-frame in OnDraw so a list resize reflows. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using AcDream.App.UI;
|
|
|
|
namespace AcDream.App.Tests.UI;
|
|
|
|
public class UiItemListGridTests
|
|
{
|
|
[Fact]
|
|
public void CellOffset_RowMajor()
|
|
{
|
|
Assert.Equal((0f, 0f), UiItemList.CellOffset(0, 3, 36, 36));
|
|
Assert.Equal((72f, 0f), UiItemList.CellOffset(2, 3, 36, 36));
|
|
Assert.Equal((36f, 36f), UiItemList.CellOffset(4, 3, 36, 36)); // col 1, row 1
|
|
}
|
|
|
|
[Fact]
|
|
public void GridMode_PositionsCellsInColumns()
|
|
{
|
|
var list = new UiItemList { Columns = 3, CellWidth = 36, CellHeight = 36 };
|
|
list.Flush(); // drop the ctor's default cell
|
|
for (int i = 0; i < 7; i++) list.AddItem(new UiItemSlot());
|
|
|
|
var c4 = list.GetItem(4)!;
|
|
Assert.Equal(36f, c4.Left);
|
|
Assert.Equal(36f, c4.Top);
|
|
Assert.Equal(36f, c4.Width);
|
|
Assert.Equal(36f, c4.Height);
|
|
}
|
|
|
|
[Fact]
|
|
public void FillMode_SizesSingleCellToList()
|
|
{
|
|
// CellWidth defaults to 0 = "fill the list" (single-cell toolbar legacy).
|
|
var list = new UiItemList { Width = 36, Height = 36 };
|
|
list.Flush();
|
|
list.AddItem(new UiItemSlot());
|
|
|
|
var c = list.Cell;
|
|
Assert.Equal(0f, c.Left);
|
|
Assert.Equal(0f, c.Top);
|
|
Assert.Equal(36f, c.Width);
|
|
Assert.Equal(36f, c.Height);
|
|
}
|
|
}
|