Skip to content

Commit 947255c

Browse files
committed
Tooltips: made it possible to use ImGuiHoveredFlags_ForTooltip + a ImGuiHoveredFlags_DelayXXXX override. (ocornut#1485)
1 parent 0b8c6b9 commit 947255c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Other changes:
7070
- Tooltips: made using SetItemTooltip()/IsItemHovered(ImGuiHoveredFlags_ForTooltip) defaults to
7171
activate tooltips on disabled items. This is done by adding ImGuiHoveredFlags_AllowWhenDisabled
7272
to the default value of style.HoverFlagsForTooltipMouse/HoverFlagsForTooltipNav. (#1485)
73+
- Tooltips: made is possible to combine ImGuiHoveredFlags_ForTooltip with a ImGuiHoveredFlags_DelayXXX
74+
override. (#1485)
7375
- Nav: Tabbing always enable nav highlight when ImGuiConfigFlags_NavEnableKeyboard is set.
7476
Previously was inconsistent and only enabled when stepping through a non-input item.
7577
(#6802, #3092, #5759, #787)

imgui.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,13 +4001,21 @@ bool ImGui::IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFlags flag
40014001
static inline float CalcDelayFromHoveredFlags(ImGuiHoveredFlags flags)
40024002
{
40034003
ImGuiContext& g = *GImGui;
4004-
if (flags & ImGuiHoveredFlags_DelayShort)
4005-
return g.Style.HoverDelayShort;
40064004
if (flags & ImGuiHoveredFlags_DelayNormal)
40074005
return g.Style.HoverDelayNormal;
4006+
if (flags & ImGuiHoveredFlags_DelayShort)
4007+
return g.Style.HoverDelayShort;
40084008
return 0.0f;
40094009
}
40104010

4011+
static ImGuiHoveredFlags ApplyHoverFlagsForTooltip(ImGuiHoveredFlags user_flags, ImGuiHoveredFlags shared_flags)
4012+
{
4013+
// Allow instance flags to override shared flags
4014+
if (user_flags & (ImGuiHoveredFlags_DelayNone | ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_DelayNormal))
4015+
shared_flags &= ~(ImGuiHoveredFlags_DelayNone | ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_DelayNormal);
4016+
return user_flags | shared_flags;
4017+
}
4018+
40114019
// This is roughly matching the behavior of internal-facing ItemHoverable()
40124020
// - 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()
40134021
// - this should work even for non-interactive items that have no ID, so we cannot use LastItemId
@@ -4025,7 +4033,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
40254033
return false;
40264034

40274035
if (flags & ImGuiHoveredFlags_ForTooltip)
4028-
flags |= g.Style.HoverFlagsForTooltipNav;
4036+
flags = ApplyHoverFlagsForTooltip(flags, g.Style.HoverFlagsForTooltipNav);
40294037
}
40304038
else
40314039
{
@@ -4035,7 +4043,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
40354043
return false;
40364044

40374045
if (flags & ImGuiHoveredFlags_ForTooltip)
4038-
flags |= g.Style.HoverFlagsForTooltipMouse;
4046+
flags = ApplyHoverFlagsForTooltip(flags, g.Style.HoverFlagsForTooltipMouse);
40394047

40404048
IM_ASSERT((flags & (ImGuiHoveredFlags_AnyWindow | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy)) == 0); // Flags not supported by this function
40414049

@@ -5423,7 +5431,6 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b
54235431
// Size
54245432
const ImVec2 content_avail = GetContentRegionAvail();
54255433
ImVec2 size = ImTrunc(size_arg);
5426-
const int auto_fit_axises = ((size.x == 0.0f) ? (1 << ImGuiAxis_X) : 0x00) | ((size.y == 0.0f) ? (1 << ImGuiAxis_Y) : 0x00);
54275434
if (size.x <= 0.0f)
54285435
size.x = ImMax(content_avail.x + size.x, 4.0f); // Arbitrary minimum child size (0.0f causing too many issues)
54295436
if (size.y <= 0.0f)
@@ -7371,7 +7378,7 @@ bool ImGui::IsWindowHovered(ImGuiHoveredFlags flags)
73717378
// for different windows of the hierarchy. Possibly need a Hash(Current+Flags) ==> (Timer) cache.
73727379
// We can implement this for _Stationary because the data is linked to HoveredWindow rather than CurrentWindow.
73737380
if (flags & ImGuiHoveredFlags_ForTooltip)
7374-
flags |= g.Style.HoverFlagsForTooltipMouse;
7381+
flags = ApplyHoverFlagsForTooltip(flags, g.Style.HoverFlagsForTooltipMouse);
73757382
if ((flags & ImGuiHoveredFlags_Stationary) != 0 && g.HoverWindowUnlockedStationaryId != ref_window->ID)
73767383
return false;
73777384

0 commit comments

Comments
 (0)