Overlapped item gets click - even with SetItemAllowOverlap #6512

Closed
opened 2023-06-12 11:56:38 +00:00 by abau · 4 comments
abau commented 2023-06-12 11:56:38 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version: 1.89.7 WIP
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl2.cpp + imgui_impl_sdl2.cpp
Compiler: gcc 13.1.1
Operating System: Linux

My Issue/Question:

I tried the example given in https://github.com/ocornut/imgui/issues/3909#issuecomment-799328231 with SetItemAllowOverlap after button 1, but unlike stated in the comment, when clicking into the intersection of both buttons, button 1 registers the click - not button 2. Did I miss anything?

**Version/Branch of Dear ImGui:** Version: 1.89.7 WIP Branch: master **Back-end/Renderer/Compiler/OS** Back-ends: imgui_impl_opengl2.cpp + imgui_impl_sdl2.cpp Compiler: gcc 13.1.1 Operating System: Linux **My Issue/Question:** I tried the example given in https://github.com/ocornut/imgui/issues/3909#issuecomment-799328231 with `SetItemAllowOverlap` after button 1, but unlike stated in the comment, when clicking into the intersection of both buttons, button 1 registers the click - not button 2. Did I miss anything?
ocornut commented 2023-06-12 12:06:39 +00:00 (Migrated from github.com)

I believe my example in the linked comment is incorrect.

Low-level ImGuiButtonFlags_AllowItemOverlap needs to be set on the potentially overlapped item:

ImGui::ButtonEx("11111", ImVec2(50, 50), ImGuiButtonFlags_AllowItemOverlap)

As designed, I believe SetItemAllowOverlap() API is a little useless.

I believe this needs to be redesigned into, e.g. at minimum a SetNextItemAllowOverlap() variant.

I believe my example in the linked comment is incorrect. Low-level `ImGuiButtonFlags_AllowItemOverlap` needs to be set on the potentially overlapped item: `ImGui::ButtonEx("11111", ImVec2(50, 50), ImGuiButtonFlags_AllowItemOverlap)` As designed, I believe `SetItemAllowOverlap()` API is a little useless. I believe this needs to be redesigned into, e.g. at minimum a `SetNextItemAllowOverlap()` variant.
ocornut commented 2023-06-12 12:14:40 +00:00 (Migrated from github.com)

I believe my example in the linked comment is incorrect.

Sorry it was too hasty to me to say that when it's not that simple.

Prior to 1.89 the code in https://github.com/ocornut/imgui/issues/3909#issuecomment-799328231 + all descriptions of behavior were fully accurate.

In 1.89 we internally started using a system for input-ownership (which wasn't really publicly advertised as a whole, but part of it was used in answers to specific problem). The way this system work broke the behavior of said snippet.
I am investigating and will post more details soon.

> I believe my example in the linked comment is incorrect. Sorry it was too hasty to me to say that when it's not that simple. Prior to 1.89 the code in https://github.com/ocornut/imgui/issues/3909#issuecomment-799328231 + all descriptions of behavior were fully accurate. In 1.89 we internally started using a system for input-ownership (which wasn't really publicly advertised as a whole, but part of it was used in answers to specific problem). The way this system work broke the behavior of said snippet. I am investigating and will post more details soon.
abau commented 2023-06-12 12:18:15 +00:00 (Migrated from github.com)

ImGuiButtonFlags_AllowItemOverlap works. Thanks.

I believe this needs to be redesigned

From my point-of-view as a new Imgui-user, I expected that - by default - all subsequent widgets would take precedence when it comes to handling events. And in case this is not what the user wants, some kind of ImGuiButtonFlags_Passthrough flag could be set for subsequent widgets.

Anyways, thanks for your help.

`ImGuiButtonFlags_AllowItemOverlap` works. Thanks. > I believe this needs to be redesigned From my point-of-view as a new Imgui-user, I expected that - by default - all subsequent widgets would take precedence when it comes to handling events. And in case this is not what the user wants, some kind of `ImGuiButtonFlags_Passthrough` flag could be set for subsequent widgets. Anyways, thanks for your help.
ocornut commented 2023-06-28 13:05:40 +00:00 (Migrated from github.com)

Following the recent discovery that an underlying major change in 1.89 broke use of SetItemAllowOverlap() I have worked on this topic. The resulting changes being:

Changelog:

  • Added SetNextItemAllowOverlap() (called before an item) as a replacement for using SetItemAllowOverlap() (called after an item). This is roughly equivalent to using the legacy SetItemAllowOverlap() call (public API) + ImGuiButtonFlags_AllowOverlap (internal).
  • Obsoleted SetItemAllowOverlap(): it didn't and couldn't work reliably since 1.89 (2022-11-15), and relied on ambiguously defined design. Use SetNextItemAllowOverlap() before item instead.
  • Renamed ImGuiTreeNodeFlags_AllowItemOverlap to ImGuiTreeNodeFlags_AllowOverlap.
  • 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.
  • Selectable, TreeNode: When using ImGuiSelectableFlags_AllowOverlap/ImGuiTreeNodeFlags_AllowOverlap and holding item held, overlapping widgets won't appear as hovered.
  • Most item types should now work with SetNextItemAllowOverlap() (previously only a fraction of widgets did).
  • Fixed first frame of an overlap highlighting underlying item if previous frame didn't hover anything.
  • Kept redirecting enums (will obsolete).
  • IsItemHovered: Added ImGuiHoveredFlags_AllowWhenOverlappedByWindow to ignore window-overlap only. Option ImGuiHoveredFlags_AllowWhenOverlapped now expand into a combination of both ImGuiHoveredFlags_AllowWhenOverlappedByWindow + ImGuiHoveredFlags_AllowWhenOverlappedByItem, matching old behavior.

Commits

  • 06f5b46 Overlap: Fixed first frame of an overlap highlighting underlying item if previous frame didn't hover anything.
  • 51f564e (Breaking) Overlap: Renamed 'ImGuiTreeNodeFlags_AllowItemOverlap' to 'ImGuiTreeNodeFlags_AllowOverlap', 'ImGuiSelectableFlags_AllowItemOverlap' to 'ImGuiSelectableFlags_AllowOverlap'. Kept redirecting enums (will obsolete).
  • 07e24b4 ButtonBehavior: pull ImGuiButtonFlags_Repeat from ImGuiItemFlags_ButtonRepeat, matching ItemHoverable() logic. So more widgets can take advantage of Repeat logic.
  • a9a5cbf Overlap: Internals: add NextItemData.ItemFlags to facilitate implementation of SetNextItemAllowOverlap() + potentially remove extra_flags from ItemAdd().
  • 8439a73 Overlap: Added 'SetNextItemAllowOverlap()' as a replacement for 'SetItemAllowOverlap()'.
  • 10c7709 IsItemHovered: Changed behavior to return false when querying an item using AllowOverlap mode. Added ImGuiHoveredFlags_AllowWhenOverlappedByItem, ImGuiHoveredFlags_AllowWhenOverlappedByWindow.
  • 4dee919 (Breaking) Internals: added ImGuiItemFlags param to ItemHoverable(), so it can be called from ButtonBehavior() not following an ItemAdd().
  • 6137443 Overlap: moved ImGuiItemflags_AllowOverlap handling from ButtoBehavior() to ItemHoverable() now that it is possible. This allows DragXXX, SliderXXX, PlotXXX etc to honor SetNextItemAllowOverlap().

I have also updated ImPlot accordingly: https://github.com/epezent/implot/pull/486

Following the recent discovery that an underlying major change in 1.89 broke use of `SetItemAllowOverlap()` I have worked on this topic. The resulting changes being: **Changelog:** - Added `SetNextItemAllowOverlap()` (called before an item) as a replacement for using `SetItemAllowOverlap()` (called after an item). This is roughly equivalent to using the legacy `SetItemAllowOverlap()` call (public API) + `ImGuiButtonFlags_AllowOverlap` (internal). - Obsoleted `SetItemAllowOverlap()`: it didn't and couldn't work reliably since 1.89 (2022-11-15), and relied on ambiguously defined design. Use `SetNextItemAllowOverlap()` before item instead. - Renamed `ImGuiTreeNodeFlags_AllowItemOverlap` to `ImGuiTreeNodeFlags_AllowOverlap`. - 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`. - Selectable, TreeNode: When using `ImGuiSelectableFlags_AllowOverlap`/`ImGuiTreeNodeFlags_AllowOverlap` and holding item held, overlapping widgets won't appear as hovered. - Most item types should now work with `SetNextItemAllowOverlap()` (previously only a fraction of widgets did). - Fixed first frame of an overlap highlighting underlying item if previous frame didn't hover anything. - Kept redirecting enums (will obsolete). - IsItemHovered: Added `ImGuiHoveredFlags_AllowWhenOverlappedByWindow` to ignore window-overlap only. Option `ImGuiHoveredFlags_AllowWhenOverlapped` now expand into a combination of both `ImGuiHoveredFlags_AllowWhenOverlappedByWindow` + `ImGuiHoveredFlags_AllowWhenOverlappedByItem`, matching old behavior. **Commits** - 06f5b46 Overlap: Fixed first frame of an overlap highlighting underlying item if previous frame didn't hover anything. - 51f564e (Breaking) Overlap: Renamed 'ImGuiTreeNodeFlags_AllowItemOverlap' to 'ImGuiTreeNodeFlags_AllowOverlap', 'ImGuiSelectableFlags_AllowItemOverlap' to 'ImGuiSelectableFlags_AllowOverlap'. Kept redirecting enums (will obsolete). - 07e24b4 ButtonBehavior: pull ImGuiButtonFlags_Repeat from ImGuiItemFlags_ButtonRepeat, matching ItemHoverable() logic. So more widgets can take advantage of Repeat logic. - a9a5cbf Overlap: Internals: add NextItemData.ItemFlags to facilitate implementation of SetNextItemAllowOverlap() + potentially remove extra_flags from ItemAdd(). - 8439a73 Overlap: Added 'SetNextItemAllowOverlap()' as a replacement for 'SetItemAllowOverlap()'. - 10c7709 IsItemHovered: Changed behavior to return false when querying an item using AllowOverlap mode. Added ImGuiHoveredFlags_AllowWhenOverlappedByItem, ImGuiHoveredFlags_AllowWhenOverlappedByWindow. - 4dee919 (Breaking) Internals: added ImGuiItemFlags param to ItemHoverable(), so it can be called from ButtonBehavior() not following an ItemAdd(). - 6137443 Overlap: moved ImGuiItemflags_AllowOverlap handling from ButtoBehavior() to ItemHoverable() now that it is possible. This allows DragXXX, SliderXXX, PlotXXX etc to honor SetNextItemAllowOverlap(). I have also updated ImPlot accordingly: https://github.com/epezent/implot/pull/486
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#6512
No description provided.