Skip to content

Commit

Permalink
Overlap: moved ImGuiItemflags_AllowOverlap handling from ButtoBehavio…
Browse files Browse the repository at this point in the history
…r() to ItemHoverable() now that it is possible. (#6512, #3909, #517)

This allows DragXXX, SliderXXX, PlotXXX etc to honor SetNextItemAllowOverlap().
  • Loading branch information
ocornut committed Jun 28, 2023
1 parent 4dee919 commit 6137443
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Breaking changes:
- Renamed 'ImGuiSelectableFlags_AllowItemOverlap' to 'ImGuiSelectableFlags_AllowOverlap'
- IsItemHovered: Changed behavior to return false when querying an item using AllowOverlap mode
which is being overlapped. Added ImGuiHoveredFlags_AllowWhenOverlappedByItem. (#6512, #3909, #517)
- Selectable, TreeNode: When using ImGuiSelectableFlags_AllowOverlap/ImGuiTreeNodeFlags_AllowOverlap
and holding item held, overlapping widgets won't appear as hovered. (#6512, #3909)
- Most item types should now work with SetNextItemAllowOverlap(). (#6512, #3909, #517)
- Fixed first frame of an overlap highlighting underlying item if previous frame didn't hover anything.
- Kept redirecting enums (will obsolete).

Other changes:
Expand Down Expand Up @@ -77,10 +81,6 @@ Other changes:
- IsItemHovered: Added _AllowWhenOverlappedByWindow to ignore window-overlap only.
Option ImGuiHoveredFlags_AllowWhenOverlapped now expand into a combination of both
_AllowWhenOverlappedByWindow + _AllowWhenOverlappedByItem, matching old behavior.
- Overlapping items: (#6512, #3909, #517)
- Selectable, TreeNode: When using ImGuiSelectableFlags_AllowOverlap/ImGuiTreeNodeFlags_AllowOverlap
and holding item held, overlapping widgets won't appear as hovered. (#6512, #3909)
- Fixed first frame of an overlap highlighting underlying item if previous frame didn't hover anything.
- IsWindowHovered: Added support for ImGuiHoveredFlags_Stationary.
- IsWindowHovered, IsItemHovered: Assert when passed any unsupported flags.
- Tables: Fixed a regression in 1.89.6 leading to the first column of tables with either
Expand Down
9 changes: 9 additions & 0 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4069,6 +4069,15 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id, ImGuiItemFlags item_flag
return false;

SetHoveredID(id);

// 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. Generally perceived as a front-to-back hit-test.
if (item_flags & ImGuiItemflags_AllowOverlap)
{
g.HoveredIdAllowOverlap = true;
if (g.HoveredIdPreviousFrame != id)
return false;
}
}

// When disabled we'll return false but still set HoveredId
Expand Down
9 changes: 0 additions & 9 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,6 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
if (flatten_hovered_children)
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 (item_flags & ImGuiItemflags_AllowOverlap)
{
if (hovered && g.HoveredIdPreviousFrame != id)
hovered = false;
if (g.HoveredId == id) // FIXME: Added this to match legacy SetItemAllowOverlap(). Investigate precise side-effects of using (hovered==true) instead?
g.HoveredIdAllowOverlap = true;
}

// Mouse handling
const ImGuiID test_owner_id = (flags & ImGuiButtonFlags_NoTestKeyOwner) ? ImGuiKeyOwner_Any : id;
if (hovered)
Expand Down

0 comments on commit 6137443

Please sign in to comment.