Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delayed tooltips & delayed IsItemHovered() #1485

Closed
alexanderbock opened this issue Dec 7, 2017 · 5 comments
Closed

Delayed tooltips & delayed IsItemHovered() #1485

alexanderbock opened this issue Dec 7, 2017 · 5 comments
Labels

Comments

@alexanderbock
Copy link

Couldn't find a previous issue or tip on it. I want to only show the tooltip after i number of seconds, rather than immediately. Am I missing some function to do that or is there a better way rather than to keep a timer based on IsItemHovered() for each item?

@ocornut
Copy link
Owner

ocornut commented Dec 8, 2017

Hello Alexander,

I added a timer a while ago to track an internal timer along with the g.HoveredId field, however IsItemHovered() specs allow for a few more things including testing items that have no identifiers (such as Text() items).

If you want to only use it on items that have identifiers (typically items that react to clicks), as a workaround for know you may do this:

#include <imgui_internal.h>

if (IsItemHovered() && GImGui->HoveredIdTimer > MY_TIME_THRESHOLD)
{
 //..
}

Which you'd probably wrap as a custom helper e.g. IsItemHovered(flags, timer) for now.

But this won't work on Text and other items because the timer isn't tracked for them.
In ShowMetricsWindow() > Internals you can watch the HoveredIdTimer if you need to check.

I'll have to think about how we can provide a more general solution to this problem. The drag and drop branch had to solve similar issues to allow every item to be used as a drag source/target, and there are solution that may be viable for this use case as well.

@alexanderbock
Copy link
Author

alexanderbock commented Dec 8, 2017

Awesome! That workaround worked. Thanks a bunch.

If you get around to implementing a general-ish solution for this, I was originally looking for a sister function to IsItemHovered() that returns the hover timer for the current object.

@ocornut ocornut added this to the v1.86 milestone Nov 10, 2021
@ocornut ocornut removed this from the v1.88 milestone Aug 24, 2022
ocornut added a commit that referenced this issue Aug 24, 2022
…_DelayShort, ImGuiHoveredFlags_NoSharedDelay. (#1485)

IsItemHovered() can't have a non-zero default, but higher-level tooltip helpers may enable a different default later.
@ocornut
Copy link
Owner

ocornut commented Aug 24, 2022

Now added the following, long-awaited helper.

// IsItemHovered() hovering delays for tooltips
ImGuiHoveredFlags_DelayNormal                   = 1 << 11,  // Return true after io.HoverDelayNormal elapsed (~0.30 sec)
ImGuiHoveredFlags_DelayShort                    = 1 << 12,  // Return true after io.HoverDelayShort elapsed (~0.10 sec)
ImGuiHoveredFlags_NoSharedDelay                 = 1 << 13,  // Disable shared delay system where moving from one item to the next keeps the previous timer for a short time (standard for tooltips with long delays)

IO:

float HoverDelayNormal; // = 0.30 sec  // Delay on hovering before IsItemHovered(ImGuiHoveredFlags_DelayNormal) returns true.
float HoverDelayShort;  // = 0.10 sec  // Delay on hovering before IsItemHovered(ImGuiHoveredFlags_DelayShort) returns true.

It works on items that have no identifier (e.g. Text() calls).

I consider this a low-level helper.
Technically I envisioned and still want a high-level helper in the form of flags passed to Tooltip functions.
The reason is that that are more features desirable for Tooltips, some only achievable in the tooltip function: priority (for override/conflict resolution, e.g. system/lib tooltip on an item, overridden by user tooltip), and variety of behavior may want to be configurable. There are so many different applications and OS behaviors.

e.g.

  • "Tooltip appear when mouse is still" vs "Tooltip appear as long as in area"
  • "Tooltip disappear when leaving item area" vs "Tooltip disappear when making a small move"
  • "Tooltip reappear again after same timer" vs "Tooltip never reappear until leaving/reentering to item"
  • Varying rules/defaults/timer for when keyboard navigation is active and triggers IsItemHovered().

I've seen all of those. I am not yet sure what are the desirable default and desirable amount of configuration (less configuration would be good: if any, most of them should be global "style" settings and not per instance). I was tempted to use names carrying more semantic e.g. ImGuiHoveredFlags_TooltipDelay instead of ImGuiHoveredFlags_DelayNormal but this being the lower-level part it may be good as-is, and the current name can more naturally be mirrored in hypothetical Tooltip flags.

Feedback welcome!
May rework this before tagging next release, and I don't know when we'll introduce higher-level tooltip layers, probably not soon.

ocornut added a commit that referenced this issue Jun 14, 2023
…iable (and is rather complex with upcoming addition of stationary logic). (#1485)

+ Tweaked default value of io.HoverDelayNormal from 0.30 to 0.35.
ocornut added a commit that referenced this issue Jun 20, 2023
ocornut added a commit that referenced this issue Jun 20, 2023
…eredFlags_Stationary. (#1485)

Update demo accordingly.
ocornut added a commit that referenced this issue Jun 20, 2023
…eredFlagsForTooltipNav now pulled by ImGuiHoveredFlags_Tooltip. (#1485)
@ocornut
Copy link
Owner

ocornut commented Jun 20, 2023

I have amended this with new commits:

  • f09ef23 IsItemHovered, Tooltips: Tweak default delay again.
  • d4b94bd (Breaking) Moved io.HoverDelayShort/io.HoverDelayNormal to style.HoverDelayShort/style.HoverDelayNormal.
  • b3b8cbd IsItemHovered, Tooltips: Added ImGuiHoveredFlags_ForTooltip, ImGuiHoveredFlags_Stationary.
  • 0f72652 IsItemHovered, Tooltips: Added io.HoveredFlagsForTooltipMouse, io.HoveredFlagsForTooltipNav now pulled by ImGuiHoveredFlags_ForTooltip.
  • b60acfa Tooltips: Added SetItemTooltip(), BeginItemTooltip(). Improved Demo section.
  • e7a4327 IsWindowHovered: Added support for ImGuiHoveredFlags_Stationary.
  • 9214c28 IsWindowHovered, IsItemHovered: Assert when passed any unsupported flags.

TL;DR; Added Stationary test. Added an indirection so using IsItemHovered(ImGuiHoveredFlags_ForTooltip) can refer to shared config/style flags. Added SetItemTooltip(), BeginItemTooltip()` helper which simplify the common idiom of using tooltips.

I'll close this issue now.

@ocornut ocornut closed this as completed Jun 20, 2023
@ocornut ocornut changed the title Delayed tooltips Delayed tooltips & delayed IsItemHovered() Jun 28, 2023
ocornut added a commit that referenced this issue Jul 3, 2023
ocornut added a commit that referenced this issue Jul 20, 2023
ocornut added a commit that referenced this issue Sep 12, 2023
…_ForTooltip) defaults to activate tooltips on disabled items.. (#1485)
ocornut added a commit that referenced this issue Oct 16, 2023
@MBilderbeek
Copy link

For a special case, I was trying to (temporary) modify the HoverDelayNormal style variable to something even larger than the default long delay. But I found no way to do this. Although this is part of the Style struct, there is no style Id for it to set it with PushStyleVar. Or: what am I missing?

ocornut added a commit that referenced this issue Sep 3, 2024
…implicit ID using Pos only. (#7945, #1485, #143)

Perhaps a better approach would be to: store last non-zero ID + count successive zero ID and combine then.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants