Merge branch 'master' into navigation

This commit is contained in:
omar
2017-09-27 17:25:50 +02:00
13 changed files with 60 additions and 67 deletions

View File

@ -2160,7 +2160,6 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_ar
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 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_ar
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 @@ bool ImGui::IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when
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 @@ void ImGui::CaptureMouseFromApp(bool capture)
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 @@ void ImGui::EndGroup()
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();