feat(D.2b): wire UiHost input + moveable windows (UiRoot window-drag + WantCapture gate)
- UiElement: add Draggable flag; left-drag on a draggable element repositions it as a floating window instead of starting a drag-drop sequence. - UiRoot: add WantsMouse/WantsKeyboard properties (mirrors ImGui's WantCaptureMouse pattern); add FindDraggable helper; inject _windowDragTarget state machine into OnMouseDown/OnMouseMove/OnMouseUp so draggable windows track the pointer offset. - UiNineSlicePanel: set Draggable=true so retail window frames are movable by default. - GameWindow: OR _uiHost?.Root.WantsMouse|WantsKeyboard into the SilkMouseSource wantCaptureMouse/wantCaptureKeyboard delegates and the direct MouseMove gate so game actions (movement, world-pick) are suppressed while the pointer is over a retail window — no double-handling with the InputDispatcher. - GameWindow: wire all Silk Mice/Keyboards to UiHost after construction so the UiRoot tree receives live input. - Tests: 3 new UiRootInputTests covering WantsMouse hit-test, window-drag reposition, and non-draggable panel immobility. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2f4520ee12
commit
4acecffcd6
5 changed files with 124 additions and 5 deletions
52
tests/AcDream.App.Tests/UI/UiRootInputTests.cs
Normal file
52
tests/AcDream.App.Tests/UI/UiRootInputTests.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using System.Numerics;
|
||||
using AcDream.App.UI;
|
||||
|
||||
namespace AcDream.App.Tests.UI;
|
||||
|
||||
public class UiRootInputTests
|
||||
{
|
||||
[Fact]
|
||||
public void WantsMouse_TrueOverWidget_FalseOverEmptySpace()
|
||||
{
|
||||
var root = new UiRoot { Width = 800, Height = 600 };
|
||||
var panel = new UiPanel { Left = 10, Top = 10, Width = 100, Height = 50 };
|
||||
root.AddChild(panel);
|
||||
|
||||
root.OnMouseMove(50, 30); // inside the panel
|
||||
Assert.True(root.WantsMouse);
|
||||
|
||||
root.OnMouseMove(500, 400); // empty space
|
||||
Assert.False(root.WantsMouse);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WindowDrag_RepositionsDraggablePanel_StopsOnRelease()
|
||||
{
|
||||
var root = new UiRoot { Width = 800, Height = 600 };
|
||||
var panel = new UiPanel { Left = 10, Top = 10, Width = 100, Height = 50, Draggable = true };
|
||||
root.AddChild(panel);
|
||||
|
||||
root.OnMouseDown(UiMouseButton.Left, 20, 20); // grab at (10,10) into the panel
|
||||
root.OnMouseMove(120, 90); // drag
|
||||
Assert.Equal(110f, panel.Left); // 120 - 10
|
||||
Assert.Equal(80f, panel.Top); // 90 - 10
|
||||
|
||||
root.OnMouseUp(UiMouseButton.Left, 120, 90);
|
||||
root.OnMouseMove(300, 300); // released — must not move
|
||||
Assert.Equal(110f, panel.Left);
|
||||
Assert.Equal(80f, panel.Top);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NonDraggablePanel_DoesNotMoveOnDrag()
|
||||
{
|
||||
var root = new UiRoot { Width = 800, Height = 600 };
|
||||
var panel = new UiPanel { Left = 10, Top = 10, Width = 100, Height = 50 }; // Draggable defaults false
|
||||
root.AddChild(panel);
|
||||
|
||||
root.OnMouseDown(UiMouseButton.Left, 20, 20);
|
||||
root.OnMouseMove(120, 90);
|
||||
Assert.Equal(10f, panel.Left);
|
||||
Assert.Equal(10f, panel.Top);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue