feat(CT-GF1): port retail ancestor-clip to the retained UI tree

Fixes the CT7 gate finding: on the Titles tab, the authored divider
0x10000530 escapes the Character window above its top edge at the
CT6-correct 372px mounted default (computed Y ~ -178, matching the
owner's screenshot). Retail clips child rendering to the intersected
ancestor clip-rect chain -- UIRegion::DrawHere @0x0069FA30 takes the
element's screen Box2D plus a SmartArray<Box2D> of inherited clip
rects, intersects them (the min/max clamp loop @0x0069FAA7..0x0069FB82),
and draws EraseSelf/DrawChildren/DrawSelf with the intersected rect
only when non-empty (the var_24 gate @0x0069FB8E). Our UiElement draw
walk rendered children unclipped by default, so any authored element
relying on clipping -- this divider, and the chat input row at small
window sizes (the owner's earlier "text input sticks out on resize"
report) -- became a visible artifact.

Mechanism (element-level, reusing the existing clip-rect-stack
infrastructure in UiRenderContext.PushClip/PopClip):

- UiElement.ClipsChildren now defaults to TRUE for every element
  (was an opt-in used only by UiScrollablePanel/UiItemList). Each
  element's children draw AND hit-test clipped to the intersection
  of its own rect with the inherited ancestor clip; an element
  positioned outside its parent's box silently disappears, matching
  retail's non-empty-intersection gate. HitTest's existing early
  bounds check already implemented this shape for ClipsChildren=true
  elements -- flipping the default aligns hit-testing with the new
  draw-clip default in one property, per the plan's own point 4.

- UiElement.ExpandsClipForPopup (default false) is the one opt-out:
  retail spawns a menu popup as a SEPARATE top-level region
  (UIElement_Menu::MakePopup), clipped only by the screen; acdream
  draws UiMenu's popup inline from the owning button in a second
  traversal (OnDrawOverlay, pre-existing -- its own doc comment
  already says "regardless of this element's position in the tree").
  DrawOverlays now resets the accumulated clip to unbounded
  (UiRenderContext.PushClipUnbounded, sharing the existing clip
  stack) for exactly the OnDrawOverlay call of an opted-in element.
  UiMenu overrides ExpandsClipForPopup=>true, paired with
  ClipsChildren=>false so its own out-of-bounds OnHitTest union (the
  popup occupies ly<0 or ly>=Height depending on open direction)
  stays reachable through the same early-bounds gate that now
  defaults on for every other element.

Opt-out audit (grep for OnDrawOverlay overrides + negative/overflow
OnDraw coordinates across src/AcDream.App/UI): UiMenu's popup is the
ONLY OnDrawOverlay override client-wide, so it is the only element
needing ExpandsClipForPopup. RetailTooltipPresenter's popup and
UiRoot's drag ghost both already escape structurally -- the tooltip
mounts as an ordinary UiRoot CHILD (sibling of every window, clipped
only by the canvas), and the drag ghost is drawn directly by UiRoot
outside the tree entirely -- neither needed a code change, both are
covered by new tests proving the invariant. UiResizeGrip and
UiNineSlicePanel's frame/bevel draw entirely within their own
[0,Width]x[0,Height] (grip flush at the window's own edges; the
window's own Width/Height already represents the OUTER frame
including its 5px bevel, so its ClipsChildren push already covers
the frame's own content children correctly -- no negative insets
found). UiScrollbar draws entirely within its own bounds (confirmed
by reading OnDraw).

Hit-testing: aligned with the new default via the single
ClipsChildren flip (see above); UiMenu's own opt-out override keeps
its popup hit-test union working, verified by the full UiMenuTests
suite staying green.

Divergence register: AD-113 filed for the ExpandsClipForPopup
adaptation (inline popup drawing vs retail's separate top-level
region).

Fixed two pre-existing test-harness gaps the new default surfaced
(both real bugs in the harnesses, not workarounds around the fix):
- ChatLayoutConformanceTests' bottom-right-grip grow test read a
  STALE (pre-shrink) grip screen position because it drove two resize
  gestures back-to-back with no intervening Draw pass -- the only
  place UiElement.ApplyAnchor/LayoutPolicy.Apply run. A real frame
  draws every tick, so production never hits this; the test now
  inserts a real DrawSelfAndChildren pass between the two gestures,
  matching a real frame boundary.
- VendorUiControllerTests' hand-built Items/Buying/Selling page
  containers were left at their bare 0x0 UiElement default (the
  harness never runs a real DAT-driven layout pass) -- harmless
  before ancestor clipping existed, but now hides every child of an
  unsized page. Sized them to the window's own content root, matching
  production's shape (a tab page fills the window body).

Tests (all confirmed as genuine regression pins by temporarily
reverting the relevant default/override and observing the exact
predicted failure, then reverting back):
- CharacterTitlesControllerTests.TitlesPage_Divider_ClipsAwayAtThe
  CT6Default_AndAppearsWhenTheWindowGrowsTaller: the literal gate
  repro against the real character_2100002E.json fixture through
  RetailWindowFrame.Mount at the CT6 372px default -- the divider
  renders nothing (computed Y ~ -173, matching the owner's ~-178);
  growing the window to 600px renders it at its authored spot.
- ChatLayoutConformanceTests.ResizingTheWindowSmall_NoInputRowQuad
  RendersOutsideTheWindowRect: no input-row quad escapes the chat
  window rect at three small sizes (300x100 sanity control,
  120x40/80x30 genuine pre-fix overflow -- verified failing without
  the fix at Y=38/55 past the window edge).
- UiAncestorClipTests (new file): the core mechanism against plain
  synthetic elements (culled-outside / clipped-at-the-edge / hit-test
  parity), UiMenu's popup escaping a tiny owning window (and staying
  clipped while closed), and the tooltip's structural immunity
  (mounts as a UiRoot sibling, unaffected by a tiny ancestor window).

Verification: full solution build green; hermetic suite green
(--filter "Lane!=InstalledDat&Lane!=PreparedPackage&Lane!=Live&
Lane!=Manual&Lane!=Timing&Lane!=Windows&Lane!=Linux&
Lane!=SystemFont&Purpose!=Diagnostic&Status!=KnownFailure",
14,000+ tests across every project); InstalledDat lane green
(ACDREAM_RUN_INSTALLED_DAT_TESTS=1, Status!=KnownFailure,
205+34+3+172 tests). CharacterTitlesControllerTests' existing suite
and the full UiMenuTests/UiScrollbarTests suites are unaffected.

src/AcDream.App/UI/UiRoot.cs carries an unrelated, pre-existing
uncommitted owner probe (ACDREAM_PROBE_UI_HOVER) -- untouched by
this change and deliberately left out of this commit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-25 06:29:15 +02:00
parent 6561d08fa8
commit 989f665214
8 changed files with 627 additions and 6 deletions

View file

@ -544,11 +544,51 @@ public abstract class UiElement
protected virtual void OnDrawOverlay(UiRenderContext ctx) { }
/// <summary>
/// When true, descendant drawing and hit-testing are clipped to this element's
/// local bounds. Scrollable listboxes use this so edge rows can remain visible
/// at arbitrary pixel offsets without painting or receiving input outside the viewport.
/// Whether descendant drawing and hit-testing are clipped to this element's
/// local bounds. THIS IS THE DEFAULT (true) FOR EVERY ELEMENT — CT-GF1 port
/// of retail's ancestor-clip chain: <c>UIRegion::DrawHere @0x0069FA30</c> takes
/// the element's screen <c>Box2D</c> plus a <c>SmartArray&lt;Box2D&gt;</c> of
/// inherited clip rects, intersects them (the min/max clamp loop
/// @0x0069FAA7..0x0069FB82), and draws — <c>EraseSelf</c>/<c>DrawChildren</c>/
/// <c>DrawSelf</c> all receive the intersected rect — ONLY when the intersection
/// is non-empty (the <c>var_24</c> gate @0x0069FB8E). An element positioned
/// outside its parent's box therefore silently disappears in retail, exactly
/// like <see cref="UiRenderContext.PushClip"/>/<see cref="UiRenderContext.PopClip"/>
/// (already wrapping the child-draw and child-hit-test walks below) now does for
/// every element by default, not just the scrollable listboxes that opted in
/// before this default flipped (owner gate finding: the Titles page's authored
/// divider 0x10000530 escaped the Character window at the CT6-correct 372px
/// mounted default — retail clips it away; acdream drew it floating above the
/// window).
///
/// <para>
/// Override to <see langword="false"/> ONLY for a widget that must draw or accept
/// input beyond its own bounds by deliberate design — today just
/// <see cref="UiMenu"/>, whose popup (and its own out-of-bounds
/// <c>OnHitTest</c> override) stands in for retail's separate top-level popup
/// region; see <see cref="ExpandsClipForPopup"/> for the drawing half of that
/// opt-out and the divergence register row it cites.
/// </para>
/// </summary>
protected virtual bool ClipsChildren => false;
protected virtual bool ClipsChildren => true;
/// <summary>
/// True when this element's <see cref="OnDrawOverlay"/> content must ignore the
/// standard ancestor clip chain that <see cref="ClipsChildren"/> now threads through
/// every element by default (CT-GF1). Retail spawns popups/dropdowns as SEPARATE
/// top-level regions (<c>UIElement_Menu::MakePopup</c>), so only the SCREEN clips
/// them — never an intervening window or panel's own client rect. Ours draws a
/// popup INLINE from its owning widget instead of reparenting to a new root (see
/// <see cref="OnDrawOverlay"/>'s own doc comment — that second traversal already
/// exists so popups composite "regardless of this element's position in the
/// tree"), so without this escape hatch the new default clip would wrongly cut off
/// a popup that legitimately extends outside its owning window — e.g. a dropdown
/// opened near the bottom of a short window. Default false (ordinary overlay
/// content, if any is ever added beyond <see cref="UiMenu"/>, stays clipped like
/// everything else). See the divergence register row this property's introducing
/// commit adds for the seam it stands in for.
/// </summary>
protected virtual bool ExpandsClipForPopup => false;
/// <summary>Per-frame tick (animations, timers, caret blink).</summary>
protected virtual void OnTick(double deltaSeconds) { }
@ -658,7 +698,19 @@ public abstract class UiElement
ctx.PushAlpha(Opacity);
try
{
OnDrawOverlay(ctx);
// ExpandsClipForPopup (CT-GF1): a popup drawn here must ignore whatever
// ancestor clip the walk down to this element accumulated — see the
// property's own doc comment for the retail-parity rationale.
if (ExpandsClipForPopup)
{
ctx.PushClipUnbounded();
try { OnDrawOverlay(ctx); }
finally { ctx.PopClip(); }
}
else
{
OnDrawOverlay(ctx);
}
if (_children.Count > 0)
{
bool clipsChildren = ClipsChildren;

View file

@ -396,6 +396,31 @@ public sealed class UiMenu : UiElement
/// must NOT be built (an invisible label child would intercept the button click).</summary>
public override bool ConsumesDatChildren => true;
/// <summary>
/// CT-GF1 opt-out: <see cref="UiElement.ClipsChildren"/>'s new client-wide default
/// (true) also gates <see cref="UiElement.HitTest"/>'s early "am I even inside my
/// own bounds" check — which would return null for every popup click before ever
/// reaching <see cref="OnHitTest"/>'s own out-of-bounds union below (the popup
/// occupies <c>ly &lt; 0</c> when it opens upward, or <c>ly &gt;= Height</c> when it
/// opens downward — see <see cref="PopupTop"/>'s doc). UiMenu has no real dat
/// children (<see cref="ConsumesDatChildren"/> is true), so this override changes
/// nothing about child drawing/hit-testing; it exists purely to keep this element's
/// OWN out-of-bounds popup region reachable, pairing with
/// <see cref="ExpandsClipForPopup"/> below for the drawing half of the same escape.
/// </summary>
protected override bool ClipsChildren => false;
/// <summary>
/// CT-GF1: the popup drawn in <see cref="OnDrawOverlay"/> is retail's stand-in for a
/// SEPARATE top-level region (<c>UIElement_Menu::MakePopup</c>) — see
/// <see cref="UiElement.ExpandsClipForPopup"/>'s own doc comment for the full
/// rationale and the divergence register row it cites. Without this, the new
/// default ancestor clip would cut off a popup that legitimately opens outside its
/// owning window (e.g. a short chat window's channel dropdown, which draws its rows
/// ABOVE the button and can extend past the window's own top edge).
/// </summary>
protected override bool ExpandsClipForPopup => true;
protected override void OnDraw(UiRenderContext ctx)
{
var resolve = SpriteResolve;

View file

@ -115,6 +115,21 @@ public sealed class UiRenderContext
_clipStack.RemoveAt(_clipStack.Count - 1);
}
/// <summary>
/// Discard every inherited clip rect for the duration of one overlay draw —
/// the escape hatch <see cref="UiElement.ExpandsClipForPopup"/> uses so a popup
/// drawn inline from its owning widget (see that property's doc comment for the
/// retail-parity rationale) is not wrongly clipped by the ancestor chain the
/// CT-GF1 default clip (<see cref="UiElement.ClipsChildren"/>) now threads through
/// every other element. Shares <see cref="PopClip"/>'s stack, so pair the two
/// exactly like <see cref="PushClip"/>.
/// </summary>
public void PushClipUnbounded()
{
_clipStack.Add(_clip);
_clip = null;
}
/// <summary>Route subsequent draws to the overlay layer (flushed on top of the whole
/// UI). Used by the root for the popup/overlay traversal. Pair with <see cref="EndOverlayLayer"/>.</summary>
public void BeginOverlayLayer() => TextRenderer.OverlayMode = true;