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
|
|
@ -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 ────────────────────────────────────────────────────────────────
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue