fix(D.2b): correct edge-anchor mapping (RightEdge==1=stretch) + enable vitals horizontal resize

ToAnchors was inverted vs retail UIElement::UpdateForParentSizeChange @0x00462640:
stretch is RightEdge==1 (not ==2/==4), LeftEdge==2 = track-right. Verified against
all 19 vitals fixture pieces. Enables Resizable/ResizeX on the importer vitals root
(the prior 'dat is fixed-size' conclusion was wrong). At-rest render unchanged
(anchors only fire on resize). Added a 160->200 resize conformance test.
Also fixed DatWidgetFactoryTests.RectAndAnchors_SetFromElementInfo which encoded
the old inverted model (Right=2 expecting Right anchor; corrected to Right=1).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-15 17:05:04 +02:00
parent 825536a2bd
commit 8aa643f3e0
6 changed files with 174 additions and 105 deletions

View file

@ -138,4 +138,54 @@ public class LayoutConformanceTests
foreach (var child in node.Children)
CollectFontDids(child, acc);
}
// ── Test 5: Horizontal resize conformance (160→200) ──────────────────────
/// <summary>
/// Proves end-to-end reflow for a 160→200 width change using the corrected
/// ToAnchors mapping (UIElement::UpdateForParentSizeChange @0x00462640).
///
/// For each piece, margins are computed from the 160-wide design rect and then
/// <see cref="UiElement.ComputeAnchoredRect"/> is applied at parentW=200.
///
/// Expected outcomes:
/// - TL corner (L=1,R=2): Left only → fixed at x=0, w=5
/// - top edge (L=1,R=1): Left+Right → stretches to w=190 at x=5
/// - TR corner (L=2,R=1): Right only → tracks right at x=195, w=5
/// - meter (L=1,R=1): Left+Right → stretches to w=190 at x=5
/// </summary>
[Fact]
public void HorizontalResize_160to200_ReflowsCorrectly()
{
const float designParentW = 160f;
const float newParentW = 200f;
const float parentH = 58f;
// (piece, designX, designW, LeftEdge, RightEdge, expectedX, expectedW)
(string Piece, float DesignX, float DesignW, uint L, uint R, float ExpX, float ExpW)[] cases =
[
("TL corner", 0f, 5f, 1u, 2u, 0f, 5f ),
("top edge", 5f, 150f, 1u, 1u, 5f, 190f),
("TR corner", 155f, 5f, 2u, 1u, 195f, 5f ),
("meter", 5f, 150f, 1u, 1u, 5f, 190f),
];
foreach (var (piece, dX, dW, l, r, expX, expW) in cases)
{
// T/B values don't affect x/w; use real vitals values (top=1, bottom=2)
var anchors = ElementReader.ToAnchors(l, top: 1u, r, bottom: 2u);
// Margins from the design rect at parentW=160
float mL = dX;
float mR = designParentW - (dX + dW);
// Reflow at parentW=200 (parentH irrelevant for x/w assertions)
var (x, _, w, _) = UiElement.ComputeAnchoredRect(
anchors, mL, mT: 0f, mR, mB: 0f, w0: dW, h0: 5f, parentW: newParentW, parentH);
// xUnit 2.x Assert.Equal(float,float,int) = decimal-place precision
Assert.True(Math.Abs(x - expX) < 0.5f, $"{piece}: expected x={expX} got {x}");
Assert.True(Math.Abs(w - expW) < 0.5f, $"{piece}: expected w={expW} got {w}");
}
}
}