refactor(ui): own retained controller lifetimes

This commit is contained in:
Erik 2026-07-10 23:35:26 +02:00
parent 921c388e2c
commit 5d9e98c118
21 changed files with 373 additions and 35 deletions

View file

@ -179,6 +179,28 @@ public sealed class RetailWindowManagerTests
Assert.Equal(1, secondController.DisposeCount);
}
[Fact]
public void AttachController_AfterRegistration_DeliversVisibilityAndOwnsDisposal()
{
var root = new UiRoot { Width = 800, Height = 600 };
var frame = new UiPanel { Width = 100, Height = 100 };
root.AddChild(frame);
RetailWindowHandle handle = root.RegisterWindow("inventory", frame);
var controller = new RecordingController();
root.WindowManager.AttachController("inventory", controller);
Assert.Same(controller, handle.Controller);
Assert.Equal(1, controller.ShownCount);
Assert.Throws<InvalidOperationException>(() =>
root.WindowManager.AttachController("inventory", new RecordingController()));
root.WindowManager.Dispose();
root.WindowManager.Dispose();
Assert.Equal(1, controller.HiddenCount);
Assert.Equal(1, controller.DisposeCount);
}
private sealed class RecordingController : IRetainedPanelController
{
public int ShownCount { get; private set; }