fix(ui): OP5 review fixes — thumb sync, batched opacity writes, cull register row, tests

Fixes the OP5 (Chat tab) dual-lens review findings against e71e5a96:

- M1 (MUST-FIX): each opacity row's own apply closure now pushes its OWN
  slider's thumb from the post-link truth (bindings.Current*Opacity()),
  mirroring the OP4 binding pattern. Before this, a single-slider drag
  followed by Reset reverted the live value/link but left that slider's
  own thumb stuck at the dragged position.

- S1 (SHOULD-FIX): the Chat tab's two opacity sliders no longer round-trip
  the whole settings.json on every drag MouseMove tick. UiScrollbar gains
  IsDragging + a DragCompleted callback (fires once, at the MouseUp that
  ends an actual thumb drag); the opacity apply closures flush immediately
  when not mid-drag (Reset/Defaults/discrete edits, same as before) and
  defer to DragCompleted otherwise, collapsing dozens of per-tick writes
  into exactly one per drag gesture. Live opacity still applies every tick.

- S2 (SHOULD-FIX): filed register row AP-201 and issue #371 for the
  UiScrollablePanel whole-row-cull-vs-clip divergence the review found
  (predates OP5, made user-visible by OP5's 240-260px filter blocks). Not
  fixed in this round (a renderer-level scissor stack is out of scope
  here) — corrected the OP5 connected-gate script instead so a straddling
  block's disappear-then-reappear-whole is no longer reported as a
  self-sizing regression.

- S3 (SHOULD-FIX): the chatWindowMainFilter round-trip test already
  existed in e71e5a96 (the review missed it scrolling past line 330);
  added the genuinely missing coverage instead — a composed test pinning
  RetailUiRuntime.MountChat's window-0 SettingsStore -> ChatWindowState
  seed (MountChat itself needs live DAT access and isn't unit-testable
  directly).

- N11: ScrollbarLinkage_ModelPointsAtTheChatListBoxScroll now asserts
  through the scoped page-slot lookup (UiElement.FindDescendant) instead
  of the flat layout.FindElement, which passed for the wrong reason given
  the shared scrollbar id 0x10000201 — matches OP6's own scrollbar-linkage
  test pattern.

Also updated ConfigOptionsPageControllerTests' local ChatOptionsPageController
Bindings fake for the new FlushOpacity parameter.

Full Release suite: 13,117 passed / 4 skipped / 0 failed (baseline 13,107/4/0
post-OP6 — 10 tests added, zero skips added, zero failures).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-11 07:36:54 +02:00
parent e318e8628d
commit 6d0b0f9285
10 changed files with 501 additions and 20 deletions

View file

@ -154,6 +154,7 @@ public sealed class ChatOptionsPageControllerTests
public float ActiveOpacityDatDefault = 1.0f;
public List<float> DefaultOpacitySets { get; } = new();
public List<float> ActiveOpacitySets { get; } = new();
public int OpacityFlushes { get; private set; }
public Dictionary<int, ulong> Filters { get; } = new()
{
@ -178,6 +179,7 @@ public sealed class ChatOptionsPageControllerTests
(DefaultOpacity, ActiveOpacity) = ChatOpacityLinkFor(DefaultOpacity, value, isDefault: false);
ActiveOpacitySets.Add(value);
},
FlushOpacity: () => OpacityFlushes++,
DefaultOpacityDatDefault: DefaultOpacityDatDefault,
ActiveOpacityDatDefault: ActiveOpacityDatDefault,
CurrentFilter: windowId => Filters[windowId],
@ -338,6 +340,27 @@ public sealed class ChatOptionsPageControllerTests
}
}
/// <summary>The two opacity-slider widgets, in build order (slider1 =
/// Default, slider2 = Active) — both are <see cref="UiScrollbar"/>s built
/// with <c>Horizontal = true</c> (import-time from the authored template's
/// own wide-vs-tall extent, <c>DatWidgetFactory.cs:214</c>) driven through
/// <see cref="UiScrollbar.ScalarChanged"/> rather than <c>Model</c>. Scoped
/// to the ListBox's own subtree, so the page-level vertical list scrollbar
/// (a DIFFERENT, non-horizontal, sibling-not-descendant element) is never
/// collected.</summary>
private static List<UiScrollbar> CollectScalarSliders(UiElement listBoxRoot)
{
var found = new List<UiScrollbar>();
Walk(listBoxRoot, found);
return found;
static void Walk(UiElement node, List<UiScrollbar> acc)
{
if (node is UiScrollbar { Horizontal: true } bar) acc.Add(bar);
foreach (UiElement child in node.Children) Walk(child, acc);
}
}
[Fact]
public void Bind_SeedsSlidersFromCurrentOpacity_NotTheDatDefault()
{
@ -446,6 +469,170 @@ public sealed class ChatOptionsPageControllerTests
Assert.Equal(1.0f, bindings.ActiveOpacity);
}
// ── OP5 review fix M1: single-row Reset must revert that row's OWN thumb ─
[Fact]
public void Reset_AfterOnlyDefaultSliderChanged_RevertsTheThumbToo()
{
// MUST-FIX M1 (OP5 review, 2026-08-11): defaultRow's own apply closure
// must push slider1's OWN thumb (mirroring the OP4 binding pattern),
// not just the LINKED slider2 via RefreshFromLink. Drag Default DOWN
// only, well below Active, so the link never raises Active and
// activeRow.Changed stays false — the exact single-row-changed
// scenario the review names as reachable and previously uncovered.
var fakeBindings = new FakeBindings { DefaultOpacity = 0.3f, ActiveOpacity = 0.9f };
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
OptionsPanelController controller = OptionsPanelController.Bind(
layout,
new OptionsPanelController.Callbacks(
Toggle: () => { },
RequestExitToCharacterSelection: () => { },
ExitGame: () => { },
UseMouseTurningSettings: () => { },
DisplaySystemMessage: _ => { }))!;
bool bound = ChatOptionsPageController.Bind(
layout, controller.ChatPage, MakeTemplateResolver(), (_, _) => null,
fakeBindings.ToBindings());
Assert.True(bound);
var listBox = Assert.IsType<UiTemplateListBox>(
layout.FindElement(ChatOptionsPageController.ListBoxElementId));
List<UiScrollbar> sliders = CollectScalarSliders(listBox);
Assert.Equal(2, sliders.Count);
UiScrollbar slider1 = sliders[0];
var defaultRow = Assert.IsType<FloatOptionRow>(controller.ChatPage.Rows[0]);
var activeRow = Assert.IsType<FloatOptionRow>(controller.ChatPage.Rows[1]);
defaultRow.SetCurrentValue(0.1f);
Assert.Equal(0.1f, slider1.ScalarPosition, 3);
Assert.True(defaultRow.Changed);
Assert.False(activeRow.Changed); // link never touched Active
controller.ChatPage.Reset();
Assert.Equal(0.3f, defaultRow.Current);
Assert.Equal(0.3f, fakeBindings.DefaultOpacity);
Assert.Equal(0.3f, slider1.ScalarPosition, 3); // the thumb reverted too, not just the value
}
[Fact]
public void Reset_AfterOnlyActiveSliderChanged_RevertsTheThumbToo()
{
// Symmetric case the review also names: drag Active UP only, Reset.
var fakeBindings = new FakeBindings { DefaultOpacity = 0.3f, ActiveOpacity = 0.6f };
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
OptionsPanelController controller = OptionsPanelController.Bind(
layout,
new OptionsPanelController.Callbacks(
Toggle: () => { },
RequestExitToCharacterSelection: () => { },
ExitGame: () => { },
UseMouseTurningSettings: () => { },
DisplaySystemMessage: _ => { }))!;
bool bound = ChatOptionsPageController.Bind(
layout, controller.ChatPage, MakeTemplateResolver(), (_, _) => null,
fakeBindings.ToBindings());
Assert.True(bound);
var listBox = Assert.IsType<UiTemplateListBox>(
layout.FindElement(ChatOptionsPageController.ListBoxElementId));
List<UiScrollbar> sliders = CollectScalarSliders(listBox);
Assert.Equal(2, sliders.Count);
UiScrollbar slider2 = sliders[1];
var defaultRow = Assert.IsType<FloatOptionRow>(controller.ChatPage.Rows[0]);
var activeRow = Assert.IsType<FloatOptionRow>(controller.ChatPage.Rows[1]);
activeRow.SetCurrentValue(0.95f);
Assert.Equal(0.95f, slider2.ScalarPosition, 3);
Assert.True(activeRow.Changed);
Assert.False(defaultRow.Changed); // link never touched Default (0.6 < 0.95)
controller.ChatPage.Reset();
Assert.Equal(0.6f, activeRow.Current);
Assert.Equal(0.6f, fakeBindings.ActiveOpacity);
Assert.Equal(0.6f, slider2.ScalarPosition, 3); // the thumb reverted too, not just the value
}
// ── OP5 review fix S1: settings write batches to drag-end, not per tick ─
[Fact]
public void DraggingDefaultSlider_DefersTheSettingsWriteUntilDragEnd()
{
// SHOULD-FIX S1 (OP5 review, 2026-08-11): N MouseMove ticks inside one
// thumb-drag gesture must flush the settings write ZERO times (only
// the LIVE opacity applies per tick); the matching MouseUp flushes
// exactly once. Drives the REAL UiScrollbar event pipeline (not
// FloatOptionRow.SetCurrentValue directly) so UiScrollbar.IsDragging
// is genuinely true for the duration, exactly like a real mouse drag.
var fakeBindings = new FakeBindings { DefaultOpacity = 0.2f, ActiveOpacity = 1.0f };
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
OptionsPanelController controller = OptionsPanelController.Bind(
layout,
new OptionsPanelController.Callbacks(
Toggle: () => { },
RequestExitToCharacterSelection: () => { },
ExitGame: () => { },
UseMouseTurningSettings: () => { },
DisplaySystemMessage: _ => { }))!;
bool bound = ChatOptionsPageController.Bind(
layout, controller.ChatPage, MakeTemplateResolver(), (_, _) => null,
fakeBindings.ToBindings());
Assert.True(bound);
var listBox = Assert.IsType<UiTemplateListBox>(
layout.FindElement(ChatOptionsPageController.ListBoxElementId));
List<UiScrollbar> sliders = CollectScalarSliders(listBox);
UiScrollbar slider1 = sliders[0];
Assert.True(slider1.Width > 16f, $"fixture slider1.Width={slider1.Width} too narrow for this test's thumb math");
// Click INSIDE the current thumb (no "jump to click position" branch)
// so this is a clean drag start with no incidental extra flush.
float thumbWidth = MathF.Min(16f, slider1.Width);
float travel = MathF.Max(1f, slider1.Width - thumbWidth);
float thumbX = travel * slider1.ScalarPosition;
int clickX = (int)(thumbX + thumbWidth * 0.5f);
Assert.True(slider1.OnEvent(new UiEvent(0u, slider1, UiEventType.MouseDown, Data1: clickX)));
Assert.True(slider1.IsDragging);
Assert.Equal(0, fakeBindings.OpacityFlushes);
for (int i = 1; i <= 10; i++)
{
Assert.True(slider1.OnEvent(new UiEvent(0u, slider1, UiEventType.MouseMove, Data1: clickX + i)));
Assert.Equal(0, fakeBindings.OpacityFlushes); // N drag ticks = 0 saves
}
// Live opacity DID apply on every tick even though nothing flushed.
Assert.NotEqual(0.2f, fakeBindings.DefaultOpacity);
Assert.True(slider1.OnEvent(new UiEvent(0u, slider1, UiEventType.MouseUp, Data1: clickX + 10)));
Assert.False(slider1.IsDragging);
Assert.Equal(1, fakeBindings.OpacityFlushes); // drag end = 1 save
}
[Fact]
public void ResetClick_FlushesImmediately_NotMidDrag()
{
// A discrete Reset click (never mid-drag) keeps writing immediately —
// the SAME single-write-per-discrete-edit shape the pre-fix code had
// for every call, matching the review's "the filter checkboxes are
// discrete clicks and are fine as written" characterization applied
// to Reset/Defaults on the opacity rows too.
var fakeBindings = new FakeBindings { DefaultOpacity = 0.3f, ActiveOpacity = 0.9f };
(OptionsPanelController controller, FakeBindings bindings, bool bound) = BindRealWith(fakeBindings);
Assert.True(bound);
var defaultRow = Assert.IsType<FloatOptionRow>(controller.ChatPage.Rows[0]);
defaultRow.SetCurrentValue(0.1f); // not mid-drag either — flushes immediately
Assert.Equal(1, bindings.OpacityFlushes);
controller.ChatPage.Reset();
Assert.Equal(2, bindings.OpacityFlushes);
}
[Fact]
public void CheckingAFilterRow_PublishesSetFilter_ForItsOwnCompactWindowId()
{
@ -562,9 +749,28 @@ public sealed class ChatOptionsPageControllerTests
Assert.Empty(page.Rows);
}
// The tab host's own private per-page SLOT id (OptionsPanelController's
// ChatPageId) — the id that actually survives base-merge in the
// host-mounted tree (see ChatOptionsPageController.PageSlotElementId's
// own doc for why the standalone layout's root id does not survive).
// OptionsPanelController keeps its own copy private; this test-local
// literal mirrors it for a scoped lookup exactly the way the controller
// itself scopes its scrollbar linkage (ConfigOptionsPageControllerTests
// uses the identical pattern for its own scrollbar-linkage tests).
private const uint ChatPageSlotId = 0x1000050Cu;
[Fact]
public void ScrollbarLinkage_ModelPointsAtTheChatListBoxScroll()
{
// OP5 review fix N11 (2026-08-11): 0x10000201 is authored in BOTH the
// Chat and Config page slots (research doc §10.1); ImportedLayout's
// flat FindElement is last-write-wins across the whole tree, so a
// flat lookup here would pass even if the controller's OWN scoped
// lookup (ChatOptionsPageController.Bind) regressed to a flat one —
// it happens to resolve the same instance today only because Chat is
// built last. Assert through the SAME scoped path the controller
// itself uses (UiElement.FindDescendant from the page's own slot),
// matching OP6's ScrollbarLinkage_ModelPointsAtTheConfigListBoxScroll.
ImportedLayout layout = FixtureLoader.LoadOptionsPanelHost();
OptionsPanelController controller = OptionsPanelController.Bind(
layout,
@ -579,10 +785,11 @@ public sealed class ChatOptionsPageControllerTests
layout, controller.ChatPage, MakeTemplateResolver(), (_, _) => null,
fakeBindings.ToBindings());
var chatSlot = UiElement.FindDescendant(controller.TabPanel, ChatPageSlotId)!;
var listBox = Assert.IsType<UiTemplateListBox>(
layout.FindElement(ChatOptionsPageController.ListBoxElementId));
UiElement.FindDescendant(chatSlot, ChatOptionsPageController.ListBoxElementId));
var scrollbar = Assert.IsType<UiScrollbar>(
layout.FindElement(ChatOptionsPageController.ScrollbarElementId));
UiElement.FindDescendant(chatSlot, ChatOptionsPageController.ScrollbarElementId));
Assert.Same(listBox.Scroll, scrollbar.Model);
}