mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-28 08:49:02 +08:00
Tooltips: made it possible to use ImGuiHoveredFlags_ForTooltip + a ImGuiHoveredFlags_DelayXXXX override. (#1485)
This commit is contained in:
parent
0b8c6b9bce
commit
947255c3da
@ -70,6 +70,8 @@ Other changes:
|
||||
- Tooltips: made using SetItemTooltip()/IsItemHovered(ImGuiHoveredFlags_ForTooltip) defaults to
|
||||
activate tooltips on disabled items. This is done by adding ImGuiHoveredFlags_AllowWhenDisabled
|
||||
to the default value of style.HoverFlagsForTooltipMouse/HoverFlagsForTooltipNav. (#1485)
|
||||
- Tooltips: made is possible to combine ImGuiHoveredFlags_ForTooltip with a ImGuiHoveredFlags_DelayXXX
|
||||
override. (#1485)
|
||||
- Nav: Tabbing always enable nav highlight when ImGuiConfigFlags_NavEnableKeyboard is set.
|
||||
Previously was inconsistent and only enabled when stepping through a non-input item.
|
||||
(#6802, #3092, #5759, #787)
|
||||
|
19
imgui.cpp
19
imgui.cpp
@ -4001,13 +4001,21 @@ bool ImGui::IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFlags flag
|
||||
static inline float CalcDelayFromHoveredFlags(ImGuiHoveredFlags flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (flags & ImGuiHoveredFlags_DelayShort)
|
||||
return g.Style.HoverDelayShort;
|
||||
if (flags & ImGuiHoveredFlags_DelayNormal)
|
||||
return g.Style.HoverDelayNormal;
|
||||
if (flags & ImGuiHoveredFlags_DelayShort)
|
||||
return g.Style.HoverDelayShort;
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
static ImGuiHoveredFlags ApplyHoverFlagsForTooltip(ImGuiHoveredFlags user_flags, ImGuiHoveredFlags shared_flags)
|
||||
{
|
||||
// Allow instance flags to override shared flags
|
||||
if (user_flags & (ImGuiHoveredFlags_DelayNone | ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_DelayNormal))
|
||||
shared_flags &= ~(ImGuiHoveredFlags_DelayNone | ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_DelayNormal);
|
||||
return user_flags | shared_flags;
|
||||
}
|
||||
|
||||
// This is roughly matching the behavior of internal-facing ItemHoverable()
|
||||
// - 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()
|
||||
// - 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)
|
||||
return false;
|
||||
|
||||
if (flags & ImGuiHoveredFlags_ForTooltip)
|
||||
flags |= g.Style.HoverFlagsForTooltipNav;
|
||||
flags = ApplyHoverFlagsForTooltip(flags, g.Style.HoverFlagsForTooltipNav);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4035,7 +4043,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
|
||||
return false;
|
||||
|
||||
if (flags & ImGuiHoveredFlags_ForTooltip)
|
||||
flags |= g.Style.HoverFlagsForTooltipMouse;
|
||||
flags = ApplyHoverFlagsForTooltip(flags, g.Style.HoverFlagsForTooltipMouse);
|
||||
|
||||
IM_ASSERT((flags & (ImGuiHoveredFlags_AnyWindow | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy)) == 0); // Flags not supported by this function
|
||||
|
||||
@ -5423,7 +5431,6 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b
|
||||
// Size
|
||||
const ImVec2 content_avail = GetContentRegionAvail();
|
||||
ImVec2 size = ImTrunc(size_arg);
|
||||
const int auto_fit_axises = ((size.x == 0.0f) ? (1 << ImGuiAxis_X) : 0x00) | ((size.y == 0.0f) ? (1 << ImGuiAxis_Y) : 0x00);
|
||||
if (size.x <= 0.0f)
|
||||
size.x = ImMax(content_avail.x + size.x, 4.0f); // Arbitrary minimum child size (0.0f causing too many issues)
|
||||
if (size.y <= 0.0f)
|
||||
@ -7371,7 +7378,7 @@ bool ImGui::IsWindowHovered(ImGuiHoveredFlags flags)
|
||||
// for different windows of the hierarchy. Possibly need a Hash(Current+Flags) ==> (Timer) cache.
|
||||
// We can implement this for _Stationary because the data is linked to HoveredWindow rather than CurrentWindow.
|
||||
if (flags & ImGuiHoveredFlags_ForTooltip)
|
||||
flags |= g.Style.HoverFlagsForTooltipMouse;
|
||||
flags = ApplyHoverFlagsForTooltip(flags, g.Style.HoverFlagsForTooltipMouse);
|
||||
if ((flags & ImGuiHoveredFlags_Stationary) != 0 && g.HoverWindowUnlockedStationaryId != ref_window->ID)
|
||||
return false;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user