Add ResizeX/ResizeY bool properties to UiElement (both true by default). HitEdges() in UiRoot masks out locked axes after edge detection, so a locked edge falls through to window-move behaviour — matching retail, where the vitals bar height is fixed and only widens. MarkupDocument.Build() parses an optional resize="x|y|both|none" attribute on <panel>; vitals.xml gets resize="x" to enforce the horizontal-only constraint in all instances of the panel. Two new tests: HitEdges_RespectsResizeAxisLock (UiRootInputTests) and Build_ResizeAttrX_SetsHorizontalOnly (MarkupDocumentTests). 11/11 green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
using AcDream.App.UI;
|
|
|
|
namespace AcDream.App.Tests.UI;
|
|
|
|
public class MarkupDocumentTests
|
|
{
|
|
private sealed class FakeBinding
|
|
{
|
|
public float HealthPercent => 0.5f;
|
|
public uint? HealthCurrent => 109;
|
|
public uint? HealthMax => 218;
|
|
public float? ManaPercent => null;
|
|
public uint? ManaCurrent => null;
|
|
public uint? ManaMax => null;
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_CreatesPanelWithMeterFillLabelAndGeometry()
|
|
{
|
|
const string xml =
|
|
"<panel id=\"acdream.vitals\" x=\"10\" y=\"30\" w=\"220\" h=\"96\" title=\"Vitals\">" +
|
|
" <meter id=\"health\" x=\"8\" y=\"24\" w=\"200\" h=\"14\" fill=\"{HealthPercent}\" cur=\"{HealthCurrent}\" max=\"{HealthMax}\" color=\"#FFFF0000\"/>" +
|
|
"</panel>";
|
|
|
|
var panel = MarkupDocument.Build(xml, new FakeBinding(), _ => ((uint)1, 32, 32));
|
|
|
|
Assert.IsType<UiNineSlicePanel>(panel);
|
|
Assert.Equal(10f, panel.Left);
|
|
Assert.Equal(220f, panel.Width);
|
|
Assert.Equal(2, panel.Children.Count); // title UiLabel + 1 meter
|
|
var meter = Assert.IsType<UiMeter>(panel.Children[1]);
|
|
Assert.Equal(8f, meter.Left);
|
|
Assert.Equal(200f, meter.Width);
|
|
Assert.Equal(0.5f, meter.Fill());
|
|
Assert.Equal("109/218", meter.Label());
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_NullBindingValuesYieldNullFillAndLabel()
|
|
{
|
|
const string xml =
|
|
"<panel id=\"v\" x=\"0\" y=\"0\" w=\"10\" h=\"10\" title=\"V\">" +
|
|
" <meter id=\"mana\" x=\"0\" y=\"0\" w=\"10\" h=\"2\" fill=\"{ManaPercent}\" cur=\"{ManaCurrent}\" max=\"{ManaMax}\" color=\"#FF0000FF\"/>" +
|
|
"</panel>";
|
|
var panel = MarkupDocument.Build(xml, new FakeBinding(), _ => ((uint)1, 32, 32));
|
|
var meter = Assert.IsType<UiMeter>(panel.Children[1]);
|
|
Assert.Null(meter.Fill());
|
|
Assert.Null(meter.Label());
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_ResizeAttrX_SetsHorizontalOnly()
|
|
{
|
|
const string xml = "<panel id=\"v\" x=\"0\" y=\"0\" w=\"100\" h=\"50\" title=\"V\" resize=\"x\"></panel>";
|
|
var panel = MarkupDocument.Build(xml, new object(), _ => ((uint)1, 32, 32));
|
|
Assert.True(panel.ResizeX);
|
|
Assert.False(panel.ResizeY);
|
|
}
|
|
}
|