Repository navigation
Closed
Labels
Description
Version/Branch of Dear ImGui:
Version 1.91.8
Back-ends:
Any (imgui_impl_sdl2.cpp + imgui_impl_sdlrenderer2.cpp)
Compiler, OS:
Any
Full config/build information:
No response
Details:
I find it hard to emulate regular buttons accurately using ImGui::InVisibleButton + ImGui::IsItemHovered.
The main problem is that, when the window is immovable and the user drag from background (of the same window) to button, regular buttons will not light up, but ImGui::IsItemHovered will return true in this case (will still be false it dragged from another immovable window). I find it very tricky to emulate regular button behavior in this case (see is_button_hovered).
- Is this difference intentional design? (Should
ImGui::IsItemHoveredreturn true when dragged from background of the same window?) - If it's intentional, can you provide a way to emulate accurate behavior more easily? (It can be an overload of
ImGui::InVisibleButtonlike below, or an additionalImGuiHoveredFlagsforImGui::IsItemHovered.)
// render_state <- ImGuiCol_ButtonActive/ImGuiCol_ButtonHovered/ImGuiCol_Button
bool InvisibleButton(const char* str_id, const ImVec2& size, ImGuiButtonFlags flags, ImGuiCol& render_state);Screenshots/Video:
(Using ImGui::IsItemHovered alone for hover test.)

Minimal, Complete and Verifiable Example code:
static bool is_button_hovered(bool accurate) {
if (!accurate) {
return ImGui::IsItemHovered();
} else {
// Trying to emulate the same condition for regular buttons to light up.
return ImGui::IsItemHovered() &&
(/*1:*/ (ImGui::IsItemActive() || !ImGui::IsAnyItemActive()) || /*2:*/ ImGui::GetIO().WantTextInput);
// 1: when users drag from background (of the same window) to the button, regular buttons will not light up, but ImGui::IsItemHovered will return true.
// 2: however, 1 will disable the hover when an input field is active (but not held), thus the exemption.
}
}
static void issue() {
static bool movable = true;
static bool accurate = false;
ImGui::SetNextWindowSize({0, 200});
const ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoResize |
(movable ? ImGuiWindowFlags_None : ImGuiWindowFlags_NoMove);
if (ImGui::Begin("Example", 0, window_flags)) {
ImGui::TextUnformatted("1. Turn off 'movable', and drag from background to both buttons.\n"
"2. Activate the input filed but not hold it, and hover on both buttons.");
ImGui::Button("Regular button");
// Trying to implement custom buttons using `ImGui::InVisibleButton()`.
// Since `hovered` and `held` (gotten by `ImGui::ButtonBehavior()`) are discarded inside the function, use publicly available functions.
ImGui::InvisibleButton("Invisible", ImGui::GetItemRectSize());
{
const ImGuiCol col = ImGui::IsItemActive() && ImGui::IsItemHovered() ? ImGuiCol_ButtonActive
: is_button_hovered(accurate) ? ImGuiCol_ButtonHovered
: ImGuiCol_Button;
ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(),
ImGui::GetColorU32(col));
}
ImGui::SetNextItemWidth(ImGui::GetItemRectSize().x);
char buf[100]{};
ImGui::InputText("InputText", buf, 10);
ImGui::Checkbox("Movable", &movable);
ImGui::Checkbox("Accurate emulation", &accurate);
}
ImGui::End();
}
Activity
achabense commentedon Aug 11, 2025
As to 1, I find the background id is intentionally checked in
IsItemHovered, what does this exemption do? (Sorry but both github and my ide cannot git-blame onimgui.cpp)imgui/imgui.cpp
Lines 4700 to 4702 in 5011559
So at least, it seems an accurate emulation can be simplified to
ocornut commentedon Aug 11, 2025
This seems like a bug to me.
For reference, the initial logic was added in pre-jurassic era (7d26e85) but most interestingly the matching TabID logic in docking branch was added later (8eb8689).
If I comment that check and run the imgui_test_suite very surprisingly I get no failing tests, which is quite encouraging. I'm going to investigate this further...
What's the problem?
Fixed an inconsistency between IsItemHovered() and internal hovering …
ocornut commentedon Aug 11, 2025
I missed that there was a comment (essentially added in that older commit), which now says:
Honestly it doesn't make sense to me, but it also puzzle me a little that this went undetected for so long.
(Presumably because it is only really noticeable nowadays when clicking on the background of a _NoMove window).
I am aggressively pushing that change in 5a6fa33, with good changelog visibility + bumping version number.
There is a possibility that some old code may be accidentally relying on this, but it seems unlikely and I am not too worried as it won't be too hard to diagnose and people can use
ImGuiHoveredFlags_AllowWhenBlockedByActiveItemto bypass it and re-emulate the behavior.Thanks a lot for the good repro and explanation by the way.!!
achabense commentedon Aug 11, 2025
Thanks for the quick fix!
(As to the git-blame problem, GitHub says "Your blame took too long to complete.", and my IDE (visual studio) also becomes unresponsive for a long time due to large git history. This isn't a problem with the library.)
TestSuite: amend 'widgets_disabled_2"
Fixed IsItemHovered() failing on disabled items and items that have n…
Revert IsItemHovered() change for TabId. (#8877, #8883)
TestSuite: amend "widgets_status_common", "widgets_disabled_2" to tes…