emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
22.06k stars 1.59k forks source link

Allow showing tooltips with a slight time delay #3232

Closed stfnp closed 1 year ago

stfnp commented 1 year ago

The current way to show a tooltip, as far as I can tell, is to use on_hover_text and friends.

These methods show a custom tooltip almost immediately when an item is hovered. This might be desired in some cases, but it can also be distracting because the tooltip is shown even when the mouse just quickly crosses an item. That's why tooltips are usually shown after a small time delay so that they only show up when actually needed.

I have no idea about the implementation, but I think it would be nice to have some methods like on_hover_text_delayed or similar that show a tooltip only after a certain time of continuous hovering. The time delay could be part of the style.

YgorSouza commented 1 year ago

It could have a field in Style like animation_time, or even just use animation_time itself, if it seems more consistent. Then it would be a matter of keeping track of when the last pointer movement occurred, and only showing the tooltip if it's been longer than the specified time. One thing to note is that when the pointer is not moving, normally the UI does not repaint, so egui has to treat this delayed tooltip like it treats the other animations for it to work properly.

Another feature that other UI frameworks have is that the tooltip disappears when you press a key, and doesn't reappear until you move the pointer again. But that could probably be a separate issue, if egui users are interested in it.

emilk commented 1 year ago

I think it makes most sense with a global tootlip_delay option in Style.

You can follow the bread-crumbs of the similar show_tooltips_only_when_still options. We'll need to add a last_move_time: f64 to PointerState to implement this