Merge branch 'master' into navigation

# Conflicts:
#	imgui.cpp
#	imgui_internal.h
This commit is contained in:
omar 2017-09-28 15:45:35 +02:00
commit d394c7ad0b
3 changed files with 14 additions and 7 deletions

View File

@ -2170,9 +2170,10 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_ar
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* window = g.CurrentWindow;
const bool is_clipped = IsClippedEx(bb, id, false);
window->DC.LastItemId = id ? *id : 0; window->DC.LastItemId = id ? *id : 0;
window->DC.LastItemRect = bb; window->DC.LastItemRect = bb;
const bool is_clipped = IsClippedEx(bb, id, false); window->DC.LastItemRectHoveredRect = false;
if (id != NULL) if (id != NULL)
window->DC.NavLayerActiveFlagsNext |= (1 << window->DC.NavLayerCurrent); window->DC.NavLayerActiveFlagsNext |= (1 << window->DC.NavLayerCurrent);
@ -2223,6 +2224,8 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_ar
return false; return false;
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG] //if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]
// We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them)
window->DC.LastItemRectHoveredRect = IsMouseHoveringRect(bb.Min, bb.Max);
return true; return true;
} }
@ -2235,12 +2238,13 @@ bool ImGui::IsItemHovered()
ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* window = g.CurrentWindow;
if (g.NavDisableMouseHover) if (g.NavDisableMouseHover)
return IsItemFocused(); return IsItemFocused();
if (!window->DC.LastItemRectHoveredRect)
return false;
if (g.HoveredWindow != window) if (g.HoveredWindow != window)
return false; return false;
if (g.ActiveId != 0 && g.ActiveId != window->DC.LastItemId && !g.ActiveIdAllowOverlap && g.ActiveId != window->MoveId) if (g.ActiveId != 0 && g.ActiveId != window->DC.LastItemId && !g.ActiveIdAllowOverlap && g.ActiveId != window->MoveId)
return false; return false;
if (!IsMouseHoveringRect(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max))
return false;
if (g.NavDisableMouseHover || !IsWindowContentHoverable(window)) if (g.NavDisableMouseHover || !IsWindowContentHoverable(window))
return false; return false;
return true; return true;
@ -2249,7 +2253,7 @@ bool ImGui::IsItemHovered()
bool ImGui::IsItemRectHovered() bool ImGui::IsItemRectHovered()
{ {
ImGuiWindow* window = GetCurrentWindowRead(); ImGuiWindow* window = GetCurrentWindowRead();
return IsMouseHoveringRect(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max); return window->DC.LastItemRectHoveredRect;
} }
// Internal facing ItemHoverable() used when submitting widgets. Differs slightly from IsItemHovered(). // Internal facing ItemHoverable() used when submitting widgets. Differs slightly from IsItemHovered().

View File

@ -1509,7 +1509,7 @@ void ImGui::ShowTestWindow(bool* p_open)
ImGui::Text("ID"); ImGui::NextColumn(); ImGui::Text("ID"); ImGui::NextColumn();
ImGui::Text("Name"); ImGui::NextColumn(); ImGui::Text("Name"); ImGui::NextColumn();
ImGui::Text("Path"); ImGui::NextColumn(); ImGui::Text("Path"); ImGui::NextColumn();
ImGui::Text("Flags"); ImGui::NextColumn(); ImGui::Text("Hovered"); ImGui::NextColumn();
ImGui::Separator(); ImGui::Separator();
const char* names[3] = { "One", "Two", "Three" }; const char* names[3] = { "One", "Two", "Three" };
const char* paths[3] = { "/path/one", "/path/two", "/path/three" }; const char* paths[3] = { "/path/one", "/path/two", "/path/three" };
@ -1520,10 +1520,11 @@ void ImGui::ShowTestWindow(bool* p_open)
sprintf(label, "%04d", i); sprintf(label, "%04d", i);
if (ImGui::Selectable(label, selected == i, ImGuiSelectableFlags_SpanAllColumns)) if (ImGui::Selectable(label, selected == i, ImGuiSelectableFlags_SpanAllColumns))
selected = i; selected = i;
bool hovered = ImGui::IsItemHovered();
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::Text(names[i]); ImGui::NextColumn(); ImGui::Text(names[i]); ImGui::NextColumn();
ImGui::Text(paths[i]); ImGui::NextColumn(); ImGui::Text(paths[i]); ImGui::NextColumn();
ImGui::Text("...."); ImGui::NextColumn(); ImGui::Text("%d", hovered); ImGui::NextColumn();
} }
ImGui::Columns(1); ImGui::Columns(1);
ImGui::Separator(); ImGui::Separator();

View File

@ -658,6 +658,7 @@ struct IMGUI_API ImGuiDrawContext
int TreeDepth; int TreeDepth;
ImGuiID LastItemId; ImGuiID LastItemId;
ImRect LastItemRect; ImRect LastItemRect;
bool LastItemRectHoveredRect;
bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f) bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f)
int NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1) int NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1)
int NavLayerActiveFlags, NavLayerActiveFlagsNext; // Which layer have been written to. int NavLayerActiveFlags, NavLayerActiveFlagsNext; // Which layer have been written to.
@ -700,7 +701,8 @@ struct IMGUI_API ImGuiDrawContext
LogLinePosY = -1.0f; LogLinePosY = -1.0f;
TreeDepth = 0; TreeDepth = 0;
LastItemId = 0; LastItemId = 0;
LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f); LastItemRect = ImRect();
LastItemRectHoveredRect = false;
NavHasScroll = false; NavHasScroll = false;
NavLayerActiveFlags = NavLayerActiveFlagsNext = 0x00; NavLayerActiveFlags = NavLayerActiveFlagsNext = 0x00;
NavLayerCurrent = 0; NavLayerCurrent = 0;