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:
parent
825536a2bd
commit
8aa643f3e0
6 changed files with 174 additions and 105 deletions
|
|
@ -36,10 +36,11 @@ public class DatWidgetFactoryTests
|
|||
// ── Test 4: Rect + anchors set from ElementInfo ───────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// A Type-3 element with X=5,Y=21,W=150,H=16, Left=1,Top=1,Right=2 should have
|
||||
/// A Type-3 element with X=5,Y=21,W=150,H=16, Left=1,Top=1,Right=1 should have
|
||||
/// its rect + anchors copied onto the returned widget.
|
||||
/// Left=1 (near-pin → AnchorEdges.Left), Top=1 (near-pin → AnchorEdges.Top),
|
||||
/// Right=2 (far-pin → AnchorEdges.Right), Bottom=0 (no anchor → neither).
|
||||
/// Per UIElement::UpdateForParentSizeChange @0x00462640:
|
||||
/// Left=1 → AnchorEdges.Left (near-pin); Top=1 → AnchorEdges.Top;
|
||||
/// Right=1 → AnchorEdges.Right (stretch / track parent right); Bottom=0 → neither.
|
||||
/// Combined: Left | Top | Right.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
|
|
@ -51,7 +52,7 @@ public class DatWidgetFactoryTests
|
|||
X = 5, Y = 21,
|
||||
Width = 150, Height = 16,
|
||||
Left = 1, Top = 1,
|
||||
Right = 2, Bottom = 0,
|
||||
Right = 1, Bottom = 0,
|
||||
};
|
||||
var e = DatWidgetFactory.Create(info, NoTex, null)!;
|
||||
Assert.Equal(5f, e.Left);
|
||||
|
|
|
|||
|
|
@ -4,34 +4,33 @@ namespace AcDream.App.Tests.UI.Layout;
|
|||
|
||||
public class ElementReaderTests
|
||||
{
|
||||
// ── ToAnchors ────────────────────────────────────────────────────────────
|
||||
// ── ToAnchors (decomp-backed: UIElement::UpdateForParentSizeChange @0x00462640) ─────────────
|
||||
|
||||
/// <summary>
|
||||
/// Edge value 4 = stretch (pinned to BOTH near AND far sides simultaneously).
|
||||
/// LeftEdge=4 → Left anchor; RightEdge=4 → Right anchor.
|
||||
/// TopEdge=1 → Top only (near-pin); BottomEdge=1 → near-pin (left/top axis), NOT Bottom.
|
||||
/// Top edge (L=1,T=1,R=1,B=2): LeftEdge==1 → Left; RightEdge==1 → Right (stretch);
|
||||
/// TopEdge==1 → Top; BottomEdge==2 (not 1/4, top≠2) → no Bottom.
|
||||
/// This is the top chrome edge — it pins left, stretches width, pins top, fixed height.
|
||||
/// Real vitals values from format doc §11 (0x10000634).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EdgeFlagsToAnchors_LeftRight_Stretches()
|
||||
public void ToAnchors_TopEdge_StretchesWidth()
|
||||
{
|
||||
// left=4 (stretch ⇒ Left), top=1 (near-pin ⇒ Top), right=4 (stretch ⇒ Right), bottom=1 (near-pin of bottom axis ⇒ not Bottom)
|
||||
var a = ElementReader.ToAnchors(left: 4, top: 1, right: 4, bottom: 1);
|
||||
var a = ElementReader.ToAnchors(left: 1, top: 1, right: 1, bottom: 2);
|
||||
Assert.True(a.HasFlag(AnchorEdges.Left));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Top));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Right));
|
||||
Assert.False(a.HasFlag(AnchorEdges.Bottom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edge value 1 = pinned to the NEAR edge of that axis.
|
||||
/// For LeftEdge: near = Left. For TopEdge: near = Top.
|
||||
/// For RightEdge: value 1 means near-pin of the right axis → does NOT map to Right anchor.
|
||||
/// For BottomEdge: value 1 means near-pin of the bottom axis → does NOT map to Bottom anchor.
|
||||
/// TL corner (L=1,T=1,R=2,B=2): LeftEdge==1 → Left; RightEdge==2 (not 1/4), left≠2 → no Right;
|
||||
/// TopEdge==1 → Top; BottomEdge==2, top≠2 → no Bottom. Fixed size, pinned top-left.
|
||||
/// Real vitals values from format doc §11 (0x10000633).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EdgeFlagsToAnchors_AllOnes_PinsTopLeftOnly()
|
||||
public void ToAnchors_TlCorner_PinsTopLeftFixed()
|
||||
{
|
||||
// 1 everywhere: only Left and Top anchors set (near-pins). Right/Bottom are far edges and value 1 is near-pin.
|
||||
var a = ElementReader.ToAnchors(left: 1, top: 1, right: 1, bottom: 1);
|
||||
var a = ElementReader.ToAnchors(left: 1, top: 1, right: 2, bottom: 2);
|
||||
Assert.True(a.HasFlag(AnchorEdges.Left));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Top));
|
||||
Assert.False(a.HasFlag(AnchorEdges.Right));
|
||||
|
|
@ -39,18 +38,46 @@ public class ElementReaderTests
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edge value 2 = pinned to the FAR edge of that axis.
|
||||
/// For RightEdge: far = Right anchor. For BottomEdge: far = Bottom anchor.
|
||||
/// For LeftEdge: value 2 means far-pin of the left axis → does NOT map to Left anchor.
|
||||
/// For TopEdge: value 2 means far-pin of the top axis → does NOT map to Top anchor.
|
||||
/// TR corner (L=2,T=1,R=1,B=2): LeftEdge==2 → triggers Right (track-right); RightEdge==1 → Right;
|
||||
/// left≠1 → no Left; TopEdge==1 → Top; BottomEdge==2, top≠2 → no Bottom.
|
||||
/// Fixed-width element whose left and right both track the parent's right edge.
|
||||
/// Real vitals values from format doc §11 (0x10000635).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EdgeFlagsToAnchors_AllTwos_PinsRightBottomOnly()
|
||||
public void ToAnchors_TrCorner_TracksRight()
|
||||
{
|
||||
// 2 everywhere: only Right and Bottom anchors set (far-pins).
|
||||
var a = ElementReader.ToAnchors(left: 2, top: 2, right: 2, bottom: 2);
|
||||
var a = ElementReader.ToAnchors(left: 2, top: 1, right: 1, bottom: 2);
|
||||
Assert.False(a.HasFlag(AnchorEdges.Left));
|
||||
Assert.False(a.HasFlag(AnchorEdges.Top));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Top));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Right));
|
||||
Assert.False(a.HasFlag(AnchorEdges.Bottom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Left edge (L=1,T=1,R=2,B=1): LeftEdge==1 → Left; RightEdge==2, left≠2 → no Right;
|
||||
/// TopEdge==1 → Top; BottomEdge==1 → Bottom. Pins left+top+bottom, fixed width, stretches height.
|
||||
/// Real vitals values from format doc §11 (0x10000636).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ToAnchors_LeftEdge_StretchesHeight()
|
||||
{
|
||||
var a = ElementReader.ToAnchors(left: 1, top: 1, right: 2, bottom: 1);
|
||||
Assert.True(a.HasFlag(AnchorEdges.Left));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Top));
|
||||
Assert.False(a.HasFlag(AnchorEdges.Right));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Bottom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All-ones (L=1,T=1,R=1,B=1): all four flags fire — Left, Right, Top, Bottom.
|
||||
/// A piece pinned to all four sides stretches both horizontally and vertically.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ToAnchors_Meter_StretchesBoth()
|
||||
{
|
||||
var a = ElementReader.ToAnchors(left: 1, top: 1, right: 1, bottom: 1);
|
||||
Assert.True(a.HasFlag(AnchorEdges.Left));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Top));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Right));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Bottom));
|
||||
}
|
||||
|
|
@ -66,19 +93,19 @@ public class ElementReaderTests
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Value 3 = floating/centered between both far edges on that axis (format doc §4).
|
||||
/// The anchor mapping fires on near-pin (1) and stretch (4) for Left/Top, and on
|
||||
/// far-pin (2) and stretch (4) for Right/Bottom — value 3 matches none of these rules.
|
||||
/// Therefore all-3 edge flags contribute no anchor bits and fall through to the
|
||||
/// Left|Top default (pin top-left, fixed size).
|
||||
/// This test covers that corner case (element 0x100004A9 — expand-detail overlay).
|
||||
/// Value 3 on left and right axes contributes no Left/Right anchor;
|
||||
/// TopEdge==1 → Top; BottomEdge==1 → Bottom.
|
||||
/// left=3 (not 1/4) → no Left; right=3 (not 1/4), left≠2 → no Right;
|
||||
/// top=1 → Top; bottom=1 → Bottom. Result: Top|Bottom.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EdgeFlagsToAnchors_ValueThree_FallsBackToTopLeft()
|
||||
public void EdgeFlagsToAnchors_ValueThree_HorizAxes_YieldsTopBottom()
|
||||
{
|
||||
// value 3 doesn't match any anchor rule; falls back to Left|Top default.
|
||||
var a = ElementReader.ToAnchors(left: 3, top: 3, right: 3, bottom: 3);
|
||||
Assert.Equal(AnchorEdges.Left | AnchorEdges.Top, a);
|
||||
var a = ElementReader.ToAnchors(left: 3, top: 1, right: 3, bottom: 1);
|
||||
Assert.False(a.HasFlag(AnchorEdges.Left));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Top));
|
||||
Assert.False(a.HasFlag(AnchorEdges.Right));
|
||||
Assert.True(a.HasFlag(AnchorEdges.Bottom));
|
||||
}
|
||||
|
||||
// ── Merge ────────────────────────────────────────────────────────────────
|
||||
|
|
|
|||
|
|
@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue