Merge branch 'master' into navigation
diff --git a/examples/allegro5_example/main.cpp b/examples/allegro5_example/main.cpp
index 9f8a6c3..2b161d3 100644
--- a/examples/allegro5_example/main.cpp
+++ b/examples/allegro5_example/main.cpp
@@ -37,7 +37,7 @@
bool show_test_window = true;
bool show_another_window = false;
- ImVec4 clear_color = ImColor(114, 144, 154);
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
bool running = true;
diff --git a/examples/directx10_example/main.cpp b/examples/directx10_example/main.cpp
index 90add03..88472e5 100644
--- a/examples/directx10_example/main.cpp
+++ b/examples/directx10_example/main.cpp
@@ -137,7 +137,7 @@
bool show_test_window = true;
bool show_another_window = false;
- ImVec4 clear_col = ImColor(114, 144, 154);
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
MSG msg;
@@ -158,7 +158,7 @@
static float f = 0.0f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
- ImGui::ColorEdit3("clear color", (float*)&clear_col);
+ ImGui::ColorEdit3("clear color", (float*)&clear_color);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
@@ -180,7 +180,7 @@
}
// Rendering
- g_pd3dDevice->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
+ g_pd3dDevice->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color);
ImGui::Render();
g_pSwapChain->Present(1, 0); // Present with vsync
diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp
index 76bab95..ab56340 100644
--- a/examples/directx11_example/main.cpp
+++ b/examples/directx11_example/main.cpp
@@ -140,7 +140,7 @@
bool show_test_window = true;
bool show_another_window = false;
- ImVec4 clear_col = ImColor(114, 144, 154);
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
MSG msg;
@@ -161,7 +161,7 @@
static float f = 0.0f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
- ImGui::ColorEdit3("clear color", (float*)&clear_col);
+ ImGui::ColorEdit3("clear color", (float*)&clear_color);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
@@ -183,7 +183,7 @@
}
// Rendering
- g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
+ g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color);
ImGui::Render();
g_pSwapChain->Present(1, 0); // Present with vsync
diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp
index f9791b7..85f34ee 100644
--- a/examples/directx9_example/main.cpp
+++ b/examples/directx9_example/main.cpp
@@ -89,7 +89,7 @@
bool show_test_window = true;
bool show_another_window = false;
- ImVec4 clear_col = ImColor(114, 144, 154);
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
MSG msg;
@@ -112,7 +112,7 @@
static float f = 0.0f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
- ImGui::ColorEdit3("clear color", (float*)&clear_col);
+ ImGui::ColorEdit3("clear color", (float*)&clear_color);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
@@ -137,7 +137,7 @@
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
- D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_col.x*255.0f), (int)(clear_col.y*255.0f), (int)(clear_col.z*255.0f), (int)(clear_col.w*255.0f));
+ D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_color.x*255.0f), (int)(clear_color.y*255.0f), (int)(clear_color.z*255.0f), (int)(clear_color.w*255.0f));
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0);
if (g_pd3dDevice->BeginScene() >= 0)
{
diff --git a/examples/marmalade_example/main.cpp b/examples/marmalade_example/main.cpp
index 57b7f0b..ebc812f 100644
--- a/examples/marmalade_example/main.cpp
+++ b/examples/marmalade_example/main.cpp
@@ -29,7 +29,7 @@
bool show_test_window = true;
bool show_another_window = false;
- ImVec4 clear_color = ImColor(114, 144, 154);
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
while (true)
diff --git a/examples/opengl2_example/main.cpp b/examples/opengl2_example/main.cpp
index 5674a4b..c676953 100644
--- a/examples/opengl2_example/main.cpp
+++ b/examples/opengl2_example/main.cpp
@@ -36,7 +36,7 @@
bool show_test_window = true;
bool show_another_window = false;
- ImVec4 clear_color = ImColor(114, 144, 154);
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
while (!glfwWindowShouldClose(window))
diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp
index 0de9b0a..d3ac2cc 100644
--- a/examples/opengl3_example/main.cpp
+++ b/examples/opengl3_example/main.cpp
@@ -44,7 +44,7 @@
bool show_test_window = true;
bool show_another_window = false;
- ImVec4 clear_color = ImColor(114, 144, 154);
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
while (!glfwWindowShouldClose(window))
diff --git a/examples/sdl_opengl2_example/main.cpp b/examples/sdl_opengl2_example/main.cpp
index 4db6f0f..fb5f3fb 100644
--- a/examples/sdl_opengl2_example/main.cpp
+++ b/examples/sdl_opengl2_example/main.cpp
@@ -42,7 +42,7 @@
bool show_test_window = true;
bool show_another_window = false;
- ImVec4 clear_color = ImColor(114, 144, 154);
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
bool done = false;
diff --git a/examples/sdl_opengl3_example/main.cpp b/examples/sdl_opengl3_example/main.cpp
index 30b14e7..19e3f86 100644
--- a/examples/sdl_opengl3_example/main.cpp
+++ b/examples/sdl_opengl3_example/main.cpp
@@ -45,7 +45,7 @@
bool show_test_window = true;
bool show_another_window = false;
- ImVec4 clear_color = ImColor(114, 144, 154);
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
bool done = false;
diff --git a/examples/vulkan_example/main.cpp b/examples/vulkan_example/main.cpp
index 7ed9ea1..64c0f08 100644
--- a/examples/vulkan_example/main.cpp
+++ b/examples/vulkan_example/main.cpp
@@ -664,7 +664,7 @@
bool show_test_window = true;
bool show_another_window = false;
- ImVec4 clear_color = ImColor(114, 144, 154);
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// When IMGUI_UNLIMITED_FRAME_RATE is defined we render into latest image acquired from the swapchain but we display the image which was rendered before.
// Hence we must render once and increase the g_FrameIndex without presenting, which we do before entering the render loop.
diff --git a/imgui.cpp b/imgui.cpp
index 01606b1..0e33fc4 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -2160,7 +2160,6 @@
ImGuiWindow* window = g.CurrentWindow;
window->DC.LastItemId = id ? *id : 0;
window->DC.LastItemRect = bb;
- window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false;
const bool is_clipped = IsClippedEx(bb, id, false);
if (id != NULL)
window->DC.NavLayerActiveFlagsNext |= (1 << window->DC.NavLayerCurrent);
@@ -2212,21 +2211,49 @@
return false;
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]
- // Setting LastItemHoveredAndUsable for IsItemHovered(). This is a sensible default, but widgets are free to override it.
- if (IsMouseHoveringRect(bb.Min, bb.Max))
- {
- // Matching the behavior of IsHovered() but allow if ActiveId==window->MoveID (we clicked on the window background)
- // So that clicking on items with no active id such as Text() still returns true with IsItemHovered()
- window->DC.LastItemHoveredRect = true;
- if (g.HoveredRootWindow == window->RootWindow)
- if (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdAllowOverlap || (g.ActiveId == window->MoveId))
- if (!g.NavDisableMouseHover && IsWindowContentHoverable(window))
- window->DC.LastItemHoveredAndUsable = true;
- }
-
return true;
}
+// This is roughly matching the behavior of internal-facing IsHovered()
+// - we allow hovering to be true when ActiveId==window->MoveID, so that clicking on non-interactive items such as a Text() item still returns true with IsItemHovered())
+// - we don't expose the flatten_child feature that IsHovered() has, which is only used by the window resizing widget (may rework this)
+bool ImGui::IsItemHovered()
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+ if (g.NavDisableMouseHover)
+ return IsItemFocused();
+ if (g.HoveredWindow == window)
+ if (g.ActiveId == 0 || g.ActiveId == window->DC.LastItemId || g.ActiveIdAllowOverlap || g.ActiveId == window->MoveId)
+ if (IsMouseHoveringRect(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max))
+ if (IsWindowContentHoverable(window))
+ return true;
+
+ return false;
+}
+
+bool ImGui::IsItemRectHovered()
+{
+ ImGuiWindow* window = GetCurrentWindowRead();
+ return IsMouseHoveringRect(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max);
+}
+
+// Internal facing IsHovered() differs slightly from IsItemHovered().
+bool ImGui::IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs)
+{
+ ImGuiContext& g = *GImGui;
+ if (g.HoveredId == 0 || g.HoveredId == id || g.HoveredIdAllowOverlap)
+ {
+ ImGuiWindow* window = g.CurrentWindow;
+ if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow))
+ if (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap)
+ if (IsMouseHoveringRect(bb.Min, bb.Max))
+ if (!g.NavDisableMouseHover && IsWindowContentHoverable(g.HoveredRootWindow))
+ return true;
+ }
+ return false;
+}
+
bool ImGui::IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged)
{
ImGuiContext& g = *GImGui;
@@ -2238,21 +2265,6 @@
return false;
}
-// NB: This is an internal helper. The user-facing IsItemHovered() is using data emitted from ItemAdd(), with a slightly different logic.
-bool ImGui::IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs)
-{
- ImGuiContext& g = *GImGui;
- if (g.HoveredId == 0 || g.HoveredId == id || g.HoveredIdAllowOverlap)
- {
- ImGuiWindow* window = GetCurrentWindowRead();
- if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow))
- if ((g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap) && IsMouseHoveringRect(bb.Min, bb.Max))
- if (!g.NavDisableMouseHover && IsWindowContentHoverable(g.HoveredRootWindow))
- return true;
- }
- return false;
-}
-
bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop)
{
ImGuiContext& g = *GImGui;
@@ -4020,21 +4032,6 @@
GImGui->WantCaptureMouseNextFrame = capture ? 1 : 0;
}
-bool ImGui::IsItemHovered()
-{
- ImGuiWindow* window = GetCurrentWindowRead();
- ImGuiContext& g = *GImGui;
- if (g.NavDisableMouseHover)
- return IsItemFocused();
- return window->DC.LastItemHoveredAndUsable;
-}
-
-bool ImGui::IsItemRectHovered()
-{
- ImGuiWindow* window = GetCurrentWindowRead();
- return window->DC.LastItemHoveredRect;
-}
-
bool ImGui::IsItemActive()
{
ImGuiContext& g = *GImGui;
@@ -10959,13 +10956,12 @@
ItemAdd(group_bb, NULL);
}
- // If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive() will function on the entire group.
+ // If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive() will be functional on the entire group.
// It would be be neater if we replaced window.DC.LastItemId by e.g. 'bool LastItemIsActive', but if you search for LastItemId you'll notice it is only used in that context.
const bool active_id_within_group = (!group_data.BackupActiveIdIsAlive && g.ActiveIdIsAlive && g.ActiveId && g.ActiveIdWindow->RootWindow == window->RootWindow);
if (active_id_within_group)
window->DC.LastItemId = g.ActiveId;
- if (active_id_within_group && g.HoveredId == g.ActiveId)
- window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = true;
+ window->DC.LastItemRect = group_bb;
window->DC.GroupStack.pop_back();
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 90a39e7..4800c3b 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -1129,11 +1129,11 @@
ImGui::Button("CCC");
ImGui::Button("DDD");
ImGui::EndGroup();
- if (ImGui::IsItemHovered())
- ImGui::SetTooltip("Group hovered");
ImGui::SameLine();
ImGui::Button("EEE");
ImGui::EndGroup();
+ if (ImGui::IsItemHovered())
+ ImGui::SetTooltip("First group hovered");
}
// Capture the group size and create widgets using the same size
ImVec2 size = ImGui::GetItemRectSize();
diff --git a/imgui_internal.h b/imgui_internal.h
index 8753b10..b8dda04 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -658,8 +658,6 @@
int TreeDepth;
ImGuiID LastItemId;
ImRect LastItemRect;
- bool LastItemHoveredAndUsable; // Item rectangle is hovered, and its window is currently interactable with (not blocked by a popup preventing access to the window)
- bool LastItemHoveredRect; // Item rectangle is hovered, but its window may or not be currently interactable with (might be blocked by a popup preventing access to the window)
bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f)
int NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1)
int NavLayerActiveFlags, NavLayerActiveFlagsNext; // Which layer have been written to.
@@ -703,7 +701,6 @@
TreeDepth = 0;
LastItemId = 0;
LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f);
- LastItemHoveredAndUsable = LastItemHoveredRect = false;
NavHasScroll = false;
NavLayerActiveFlags = NavLayerActiveFlagsNext = 0x00;
NavLayerCurrent = 0;