diff --git a/src/AcDream.UI.ImGui/ImGuiPanelRenderer.cs b/src/AcDream.UI.ImGui/ImGuiPanelRenderer.cs index 4396874..94f09d4 100644 --- a/src/AcDream.UI.ImGui/ImGuiPanelRenderer.cs +++ b/src/AcDream.UI.ImGui/ImGuiPanelRenderer.cs @@ -14,7 +14,30 @@ namespace AcDream.UI.ImGui; public sealed class ImGuiPanelRenderer : IPanelRenderer { /// - public bool Begin(string title) => ImGuiNET.ImGui.Begin(title); + public bool Begin(string title) + { + bool open = ImGuiNET.ImGui.Begin(title); + if (open) + { + // Title-bar-only drag: ImGui's default lets the user drag the + // window by clicking on the empty body background (because a + // window-drag is initiated whenever a body click lands without + // any widget being "active"). Filling the body with an + // InvisibleButton absorbs those stray clicks — real widgets + // drawn afterwards still claim their own clicks because click + // priority is "last drawn, first checked", so the button + // catches only empty-space clicks. Net effect: title bar + // still drags (ImGui default), body never does. + var avail = ImGuiNET.ImGui.GetContentRegionAvail(); + if (avail.X > 0f && avail.Y > 0f) + { + var savedCursor = ImGuiNET.ImGui.GetCursorPos(); + ImGuiNET.ImGui.InvisibleButton("##bodydragabsorb", avail); + ImGuiNET.ImGui.SetCursorPos(savedCursor); + } + } + return open; + } /// public void End() => ImGuiNET.ImGui.End();