Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ImGui.Widgets/DividerContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ private void DrawDividerHandle(DividerZone z, int i, Vector2 advance, ImGuiStyle
Vector2 grabSize = grabMax - grabMin;
RectangleF handleRect = new(grabMin.X, grabMin.Y, grabSize.X, grabSize.Y);
ImGuiProbes.MarkRegion($"{Id}/divider/{z.Id}", grabMin, grabMin + grabSize);
bool handleHovered = handleRect.Contains(mousePos.X, mousePos.Y);
// The handle is hit-tested by rectangle rather than submitted as an item, so it has to ask
// whether anything is drawn over it: a popup or window opened above the divider would
// otherwise have its clicks taken by the handle underneath, which starts a resize and moves
// whatever the click was meant for. Popups opened from a zone are excluded from the
// container's hierarchy for the same reason.
bool handleHovered = handleRect.Contains(mousePos.X, mousePos.Y)
&& (DragIndex == i || ImGui.IsWindowHovered(ImGuiHoveredFlags.ChildWindows | ImGuiHoveredFlags.NoPopupHierarchy));
bool mouseClickedThisFrame = ImGui.IsMouseClicked(ImGuiMouseButton.Left);
bool handleClicked = handleHovered && mouseClickedThisFrame;
bool handleDoubleClicked = handleHovered && ImGui.IsMouseDoubleClicked(ImGuiMouseButton.Left);
Expand Down
42 changes: 42 additions & 0 deletions tests/ImGui.Widgets.UITests/DividerContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,46 @@ public void DividerContainer_RemovingAZoneDropsItsContent()
Assert.IsFalse(IsVisible("right-content"), "A removed zone was still drawn.");
Assert.IsTrue(IsVisible("left-content"), "Removing one zone stopped the other from drawing.");
}

[TestMethod]
public void DividerContainer_AClickOnAPopupOverTheHandle_DoesNotResize()
{
bool coverOpen = false;
bool coverClicked = false;
container = new ImGuiWidgets.DividerContainer(ContainerId, ImGuiWidgets.DividerLayout.Columns);
container.Add(LeftZone, 0.3f, true, _ =>
{
// A popup opened from inside a zone, as a combo's list is, laid over the divider.
if (coverOpen && !ImGui.IsPopupOpen("cover"))
{
ImGui.OpenPopup("cover");
}

Vector2 at = Harness.Probe.Rect(Handle) is Rectangle handle
? new Vector2(handle.MinX - 40f, handle.MinY + 20f)
: Vector2.Zero;
ImGui.SetNextWindowPos(at);
if (ImGui.BeginPopup("cover"))
{
coverClicked |= ImGui.Button("over the handle", new Vector2(120f, 60f));
Mark("cover-button");
ImGui.EndPopup();
}
});
container.Add(RightZone, 0.7f, false, _ => ImGui.TextUnformatted("Right content"));

Start(() => container.Tick(1f / 60f));
coverOpen = true;
Step(3);

Rectangle handleRect = RectOf(Handle);
Rectangle button = RectOf("cover-button");
Assert.IsTrue(button.MinX < handleRect.MinX && button.MaxX > handleRect.MaxX, "The popup does not cover the handle, so this tests nothing.");

Harness.Mouse.Click(handleRect.MinX + (handleRect.Width / 2f), button.MinY + (button.Height / 2f));
Step(2);

Assert.AreEqual(0.3f, container.GetSizes()[0], "A click on the popup resized the container underneath.");
Assert.IsTrue(coverClicked, "The popup's button didn't get the click.");
}
}
Loading