Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlapped item gets click - even with SetItemAllowOverlap #6512

Closed
abau opened this issue Jun 12, 2023 · 4 comments
Closed

Overlapped item gets click - even with SetItemAllowOverlap #6512

abau opened this issue Jun 12, 2023 · 4 comments
Labels
Milestone

Comments

@abau
Copy link

abau commented Jun 12, 2023

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 #3909 (comment) 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
Copy link
Owner

ocornut commented Jun 12, 2023

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
Copy link
Owner

ocornut commented Jun 12, 2023

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 #3909 (comment) + 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
Copy link
Author

abau commented Jun 12, 2023

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.

@abau abau closed this as completed Jun 12, 2023
@ocornut ocornut reopened this Jun 12, 2023
@ocornut ocornut added this to the v1.90 milestone Jun 17, 2023
ocornut added a commit that referenced this issue Jun 26, 2023
…AllowtemOverlap in TableUpdateBorders(). (#6512, #3909)

This was copied from SplitterBehavior(). The only hypothetical value in SplitterBehavior() would be ability to manually call SetItemAllowOverlap() after the call.
Btw generally AllowOverlap is undesirable for columns as e.g. a spanning selectable would cover entire width and prevent columns from being used.

# Conflicts:
#	imgui_tables.cpp
ocornut added a commit that referenced this issue Jun 26, 2023
…GuiTreeNodeFlags_AllowOverlap and holding item held, overlapping widgets won't appear as hovered. (#6512, #3909)

Essentially we are going to remove calls to SetItemAllowOverlap() and standardize the fact that only 'HoveredId == id' test from it is performed.

# Conflicts:
#	imgui_widgets.cpp
ocornut added a commit that referenced this issue Jun 27, 2023
ocornut added a commit that referenced this issue Jun 28, 2023
…'ImGuiTreeNodeFlags_AllowOverlap', 'ImGuiSelectableFlags_AllowItemOverlap' to 'ImGuiSelectableFlags_AllowOverlap'. Kept redirecting enums (will obsolete). (#6512, #3909, #517)

+ Internals: Renamed 'ImGuiButtonFlags_AllowItemOverlap' to 'ImGuiButtonFlags_AllowOverlap' without redirection.
ocornut added a commit that referenced this issue Jun 28, 2023
…tation of SetNextItemAllowOverlap() + potentially remove extra_flags from ItemAdd(). (#6512, #3909)
ocornut added a commit that referenced this issue Jun 28, 2023
…temAllowOverlap()'. (#6512, #3909, #517)

# Conflicts:
#	imgui.cpp
#	imgui_widgets.cpp
ocornut added a commit that referenced this issue Jun 28, 2023
…g an item using AllowOverlap mode. Added ImGuiHoveredFlags_AllowWhenOverlappedByItem, ImGuiHoveredFlags_AllowWhenOverlappedByWindow., (#6512, #3909, #517)
ocornut added a commit that referenced this issue Jun 28, 2023
…so it can be called from ButtonBehavior() not following an ItemAdd().

This also allow moving AllowOverlap logic from ButtonBehavior() to ItemHoverable(), allowing other widgets to honor it. (#6512, #3909, #517)
ocornut added a commit that referenced this issue Jun 28, 2023
…r() to ItemHoverable() now that it is possible. (#6512, #3909, #517)

This allows DragXXX, SliderXXX, PlotXXX etc to honor SetNextItemAllowOverlap().
@ocornut
Copy link
Owner

ocornut commented Jun 28, 2023

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: epezent/implot#486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants