Skip to content

Commit

Permalink
ButtonBehavior: Fixed ImGuiButtonFlags_AllowOverlapMode to avoid temp…
Browse files Browse the repository at this point in the history
…orarily activating widgets on click before they have been correctly double-hovered. (#319, #600)
  • Loading branch information
ocornut committed Nov 9, 2017
1 parent 2df8fa9 commit 8451855
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5821,6 +5821,10 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
if ((flags & ImGuiButtonFlags_FlattenChilds) && g.HoveredRootWindow == window)
g.HoveredWindow = backup_hovered_window;

// AllowOverlap mode (rarely used) requires previous frame HoveredId to be null or to match. This allows using patterns where a later submitted widget overlaps a previous one.
if (hovered && (flags & ImGuiButtonFlags_AllowOverlapMode) && (g.HoveredIdPreviousFrame != id && g.HoveredIdPreviousFrame != 0))
hovered = false;

if (hovered)
{
if (!(flags & ImGuiButtonFlags_NoKeyModifiers) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt))
Expand Down Expand Up @@ -5880,10 +5884,6 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
}
}

// AllowOverlap mode (rarely used) requires previous frame HoveredId to be null or to match. This allows using patterns where a later submitted widget overlaps a previous one.
if (hovered && (flags & ImGuiButtonFlags_AllowOverlapMode) && (g.HoveredIdPreviousFrame != id && g.HoveredIdPreviousFrame != 0))
hovered = pressed = held = false;

if (out_hovered) *out_hovered = hovered;
if (out_held) *out_held = held;

Expand Down

0 comments on commit 8451855

Please sign in to comment.