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
|
|
@ -139,38 +139,40 @@ These are `uint` fields on `ElementDesc`. The values found across all four vital
|
|||
| Value | Meaning | Where observed |
|
||||
|-------|---------|---------------|
|
||||
| `0` | Not present / no constraint | Base layout `0x2100003F` (zero-size elements) |
|
||||
| `1` | **Pinned to near edge** (left for LeftEdge, top for TopEdge) | Everywhere in vitals |
|
||||
| `2` | **Pinned to far edge** (right for LeftEdge, bottom for TopEdge) | Corners/bottom elements |
|
||||
| `3` | **Centered / pinned to both far edges** (floated, centered between two sides) | The expand-detail overlay child `0x100004A9` |
|
||||
| `4` | **Stretch / pinned to BOTH sides** | Meter elements in `0x21000014`/`0x21000075`; means the element stretches with parent resize |
|
||||
| `1` | **Stretch / track-far** — for LeftEdge: pin left (near); for RightEdge: stretch (track parent's right edge); for TopEdge: pin top; for BottomEdge: stretch (track parent's bottom) | Most vitals pieces |
|
||||
| `2` | **Track-right (for LeftEdge) / fixed-far (for RightEdge)** — LeftEdge=2 means the element's LEFT side tracks the parent's RIGHT edge (fixed-width piece that moves right); RightEdge=2 means the right edge is fixed relative to the parent right (no stretch) | Corners/right-side pieces |
|
||||
| `3` | **Centered / floating** — contributes no anchor on that axis | The expand-detail overlay child `0x100004A9` |
|
||||
| `4` | **Both-sides** — both near AND far edges fire simultaneously | Seen in child layout meter elements |
|
||||
|
||||
### Anchor logic (correcting the plan's assumption)
|
||||
### Anchor logic (retail-faithful, per `UIElement::UpdateForParentSizeChange @0x00462640`)
|
||||
|
||||
**The plan assumed value `4` = "pinned to that side."** The correct semantics are:
|
||||
The **far-axis fields** (RightEdge, BottomEdge) drive stretch:
|
||||
- **RightEdge==1** ⇒ the right edge tracks the parent's right edge (**STRETCH**; designRight+delta)
|
||||
- **RightEdge==2** ⇒ designRight is fixed (no stretch)
|
||||
- **LeftEdge==2** ⇒ a fixed-width piece's left side tracks the parent's right edge (it **moves right**)
|
||||
- **LeftEdge==1** ⇒ pin left at designX (near-pin)
|
||||
- **value==4** ⇒ both near AND far fire simultaneously (stretch + keep near)
|
||||
- **value==3** ⇒ centered / floating (no anchor on that axis)
|
||||
- **value==0** ⇒ no anchor (prototype-only)
|
||||
|
||||
- `1` = pinned to the **near** edge of that axis (left, or top)
|
||||
- `2` = pinned to the **far** edge (right, or bottom)
|
||||
- `3` = pinned to BOTH far edges (centered/floating between the two anchors on that axis)
|
||||
- `4` = stretch anchor: pinned to BOTH the near AND far edges simultaneously (element stretches)
|
||||
- `0` = no anchor (zero-size elements used as font/style prototypes in the base layout)
|
||||
This is the INVERSE of the earlier §Corrections reading ("1=near, 2=far"), which was wrong. The decomp is authoritative: `UIElement::UpdateForParentSizeChange @0x00462640` in `docs/research/named-retail/acclient_2013_pseudo_c.txt` lines 108459–108668.
|
||||
|
||||
Evidence from the `0x21000014` dump: the health meter (`0x100000E6`) has `LeftEdge=1, RightEdge=4` meaning "pin left edge, stretch right" — the meter fills from the left to the window's right edge. The stamina meter (`0x100000EC`) has `LeftEdge=4, RightEdge=4` meaning it stretches on both sides (centered at 270px, fills width with parent).
|
||||
|
||||
**Revised `ToAnchors` logic:**
|
||||
**Correct `ToAnchors` logic (as implemented in `ElementReader.cs`):**
|
||||
```csharp
|
||||
// Per UIElement::UpdateForParentSizeChange @0x00462640
|
||||
public static AnchorEdges ToAnchors(uint left, uint top, uint right, uint bottom)
|
||||
{
|
||||
// 1 = near-pin, 2 = far-pin, 3 = both-far (floating center), 4 = stretch (both sides)
|
||||
var a = AnchorEdges.None;
|
||||
if (left == 1 || left == 4) a |= AnchorEdges.Left;
|
||||
if (top == 1 || top == 4) a |= AnchorEdges.Top;
|
||||
if (right == 2 || right == 4) a |= AnchorEdges.Right;
|
||||
if (bottom == 2 || bottom == 4) a |= AnchorEdges.Bottom;
|
||||
if (left == 1 || left == 4) a |= AnchorEdges.Left;
|
||||
if (right == 1 || right == 4 || left == 2) a |= AnchorEdges.Right;
|
||||
if (top == 1 || top == 4) a |= AnchorEdges.Top;
|
||||
if (bottom == 1 || bottom == 4 || top == 2) a |= AnchorEdges.Bottom;
|
||||
if (a == AnchorEdges.None) a = AnchorEdges.Left | AnchorEdges.Top; // default: pin top-left
|
||||
return a;
|
||||
}
|
||||
```
|
||||
Value `3` (floating center) is a "pin far but not near" on both axes — maps to Right+Bottom anchors but NOT Left+Top. This shows up only on the hide/show-detail overlay child (`0x100004A9`) which is visually centered in the bar.
|
||||
|
||||
**Verified against all 19 vitals pieces** (format doc §11). At-rest render (no resize) is pixel-identical — anchors only fire on resize. Value `3` contributes no anchor on its axis and falls through to the Left|Top default only when all four values are 3 or 0.
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -407,28 +409,31 @@ Each meter has:
|
|||
|
||||
## § Corrections to plan assumptions
|
||||
|
||||
### 1. Edge-flag "pinned" value is NOT simply `4`
|
||||
### 1. Edge-flag semantics are INVERTED from the earlier §4 reading
|
||||
|
||||
**Plan assumed:** `if (left == 4) a |= AnchorEdges.Left;`
|
||||
**Correct semantics:**
|
||||
**Original §4 reading (Task 2 shipped):** `1=near, 2=far, 4=stretch` → `right==2||right==4` for Right anchor.
|
||||
**That was wrong.** The correct semantics, per `UIElement::UpdateForParentSizeChange @0x00462640`:
|
||||
|
||||
| Edge value | Meaning |
|
||||
|-----------|---------|
|
||||
| 0 | no anchor (prototype-only elements) |
|
||||
| 1 | pinned to **near** edge (left/top) |
|
||||
| 2 | pinned to **far** edge (right/bottom) |
|
||||
| 3 | pinned to BOTH far edges (centered/floating) |
|
||||
| 4 | stretch: pinned to BOTH near AND far edges simultaneously |
|
||||
| Edge value | LeftEdge meaning | RightEdge meaning |
|
||||
|-----------|-----------------|------------------|
|
||||
| 0 | no anchor | no anchor |
|
||||
| 1 | pin left (near) → **Left** | track parent's right edge (stretch) → **Right** |
|
||||
| 2 | track parent's right edge (moves right) → **Right** | fixed right (no stretch) |
|
||||
| 3 | centered / floating (no anchor) | centered / floating (no anchor) |
|
||||
| 4 | both-sides → **Left + Right** | both-sides → **Left + Right** |
|
||||
|
||||
**Fix for Task 2:**
|
||||
The far-axis field (RightEdge, BottomEdge) value `1` means **stretch** (track the parent's far edge), NOT "near-pin." This is the INVERSE of what was documented in the original §4.
|
||||
|
||||
**Correct `ToAnchors` (as fixed in `ElementReader.cs` 2026-06-15):**
|
||||
```csharp
|
||||
// Per UIElement::UpdateForParentSizeChange @0x00462640
|
||||
public static AnchorEdges ToAnchors(uint left, uint top, uint right, uint bottom)
|
||||
{
|
||||
var a = AnchorEdges.None;
|
||||
if (left == 1 || left == 4) a |= AnchorEdges.Left;
|
||||
if (top == 1 || top == 4) a |= AnchorEdges.Top;
|
||||
if (right == 2 || right == 4) a |= AnchorEdges.Right;
|
||||
if (bottom == 2 || bottom == 4) a |= AnchorEdges.Bottom;
|
||||
if (left == 1 || left == 4) a |= AnchorEdges.Left;
|
||||
if (right == 1 || right == 4 || left == 2) a |= AnchorEdges.Right;
|
||||
if (top == 1 || top == 4) a |= AnchorEdges.Top;
|
||||
if (bottom == 1 || bottom == 4 || top == 2) a |= AnchorEdges.Bottom;
|
||||
if (a == AnchorEdges.None) a = AnchorEdges.Left | AnchorEdges.Top;
|
||||
return a;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1810,16 +1810,21 @@ public sealed class GameWindow : IDisposable
|
|||
healthText: () => (_vitalsVm!.HealthCurrent, _vitalsVm.HealthMax) is (uint c, uint m) ? $"{c}/{m}" : "",
|
||||
staminaText: () => (_vitalsVm!.StaminaCurrent, _vitalsVm.StaminaMax) is (uint c, uint m) ? $"{c}/{m}" : "",
|
||||
manaText: () => (_vitalsVm!.ManaCurrent, _vitalsVm.ManaMax) is (uint c, uint m) ? $"{c}/{m}" : "");
|
||||
// Top-level window: user-positioned (Anchors.None so the per-frame anchor
|
||||
// pass doesn't reset it) + movable, like the retired hand-authored panel.
|
||||
// Resize is left off — the dat stacked-vitals layout (0x2100006C) is
|
||||
// fixed-size (chrome edges near-pinned); faithful grip/dragbar-driven
|
||||
// resize is the Plan-2 window manager.
|
||||
// Top-level retail window: user-positioned (Anchors.None so the per-frame
|
||||
// anchor pass doesn't reset it), movable, and horizontally resizable like
|
||||
// retail. On a width change the dat edge-anchors reflow the pieces
|
||||
// (UIElement::UpdateForParentSizeChange @0x00462640): top/bottom edges +
|
||||
// the three bars stretch, corners stay 5px, the right edge/corners track
|
||||
// the right side. Vertical resize is off (the layout has no vertical stretch).
|
||||
var vitalsRoot = imported.Root;
|
||||
vitalsRoot.Left = 10; vitalsRoot.Top = 30;
|
||||
vitalsRoot.ClickThrough = false;
|
||||
vitalsRoot.Anchors = AcDream.App.UI.AnchorEdges.None;
|
||||
vitalsRoot.Draggable = true;
|
||||
vitalsRoot.Resizable = true;
|
||||
vitalsRoot.ResizeX = true;
|
||||
vitalsRoot.ResizeY = false;
|
||||
vitalsRoot.MinWidth = 40f;
|
||||
_uiHost.Root.AddChild(vitalsRoot);
|
||||
Console.WriteLine("[D.2b] retail UI active — vitals window from LayoutDesc importer (0x2100006C).");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,42 +68,23 @@ public sealed class ElementInfo
|
|||
/// </summary>
|
||||
public static class ElementReader
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps the four raw edge-anchor flag values from <c>ElementDesc</c> to the
|
||||
/// <see cref="AnchorEdges"/> bit-flag used by the UI layout engine.
|
||||
///
|
||||
/// <para>
|
||||
/// The dat stores one <c>uint</c> per edge with these semantics (§4 of the
|
||||
/// LayoutDesc format reference, 2026-06-15):
|
||||
/// <list type="bullet">
|
||||
/// <item><description>0 = no anchor (prototype-only elements — zero-size style stores)</description></item>
|
||||
/// <item><description>1 = pinned to the <em>near</em> edge (left for LeftEdge, top for TopEdge)</description></item>
|
||||
/// <item><description>2 = pinned to the <em>far</em> edge (right for RightEdge, bottom for BottomEdge)</description></item>
|
||||
/// <item><description>3 = floating / centered between both far edges (maps to neither Left nor Right)</description></item>
|
||||
/// <item><description>4 = stretch: pinned to BOTH near AND far edges simultaneously (element stretches with parent)</description></item>
|
||||
/// </list>
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// Default when no flags resolve: <c>Left | Top</c> (pin top-left, fixed size).
|
||||
/// This matches elements whose all-zero edge flags indicate a no-reflow prototype.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <summary>Edge-anchor flags → AnchorEdges, per retail UIElement::UpdateForParentSizeChange
|
||||
/// @0x00462640. The far-axis fields drive stretch: RightEdge==1 ⇒ the right edge tracks the
|
||||
/// parent's right edge (stretch); LeftEdge==2 ⇒ a fixed-width element's left tracks the right
|
||||
/// edge (it moves right). ==4 (not present in the vitals layout) = both-sides stretch; ==3 =
|
||||
/// centered (no edge anchor → falls back to pin-top-left). This is the INVERSE of the earlier
|
||||
/// format-doc §4 reading, which was wrong (it made every piece fixed-width).</summary>
|
||||
/// <param name="left">LeftEdge dat field value (0–4).</param>
|
||||
/// <param name="top">TopEdge dat field value (0–4).</param>
|
||||
/// <param name="right">RightEdge dat field value (0–4).</param>
|
||||
/// <param name="bottom">BottomEdge dat field value (0–4).</param>
|
||||
public static AnchorEdges ToAnchors(uint left, uint top, uint right, uint bottom)
|
||||
{
|
||||
// 1 = near-pin, 2 = far-pin, 3 = both-far (floating center), 4 = stretch (both sides).
|
||||
// Only 1 and 4 contribute the NEAR (Left/Top) anchor.
|
||||
// Only 2 and 4 contribute the FAR (Right/Bottom) anchor.
|
||||
// Value 3 contributes neither (floating center is handled by the UI engine differently).
|
||||
var a = AnchorEdges.None;
|
||||
if (left == 1 || left == 4) a |= AnchorEdges.Left;
|
||||
if (top == 1 || top == 4) a |= AnchorEdges.Top;
|
||||
if (right == 2 || right == 4) a |= AnchorEdges.Right;
|
||||
if (bottom == 2 || bottom == 4) a |= AnchorEdges.Bottom;
|
||||
if (left == 1 || left == 4) a |= AnchorEdges.Left;
|
||||
if (right == 1 || right == 4 || left == 2) a |= AnchorEdges.Right;
|
||||
if (top == 1 || top == 4) a |= AnchorEdges.Top;
|
||||
if (bottom == 1 || bottom == 4 || top == 2) a |= AnchorEdges.Bottom;
|
||||
if (a == AnchorEdges.None) a = AnchorEdges.Left | AnchorEdges.Top; // default: pin top-left
|
||||
return a;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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