@@ -584,14 +584,7 @@ impl Response {
584
584
return true ;
585
585
}
586
586
587
- if self . context_menu_opened ( ) {
588
- return false ;
589
- }
590
-
591
- if ComboBox :: is_open ( & self . ctx , self . id ) {
592
- return false ; // Don't cover the open ComboBox with a tooltip
593
- }
594
-
587
+ // Fast early-outs:
595
588
if self . enabled {
596
589
if !self . hovered || !self . ctx . input ( |i| i. pointer . has_pointer ( ) ) {
597
590
return false ;
@@ -600,20 +593,44 @@ impl Response {
600
593
return false ;
601
594
}
602
595
603
- if self . ctx . style ( ) . interaction . show_tooltips_only_when_still {
604
- // We only show the tooltip when the mouse pointer is still,
605
- // but once shown we keep showing it until the mouse leaves the parent.
596
+ if self . context_menu_opened ( ) {
597
+ return false ;
598
+ }
606
599
607
- if !self . ctx . input ( |i| i. pointer . is_still ( ) ) && !self . is_tooltip_open ( ) {
608
- // wait for mouse to stop
609
- self . ctx . request_repaint ( ) ;
610
- return false ;
611
- }
600
+ if ComboBox :: is_open ( & self . ctx , self . id ) {
601
+ return false ; // Don't cover the open ComboBox with a tooltip
612
602
}
613
603
614
- if !self . is_tooltip_open ( ) {
615
- let time_til_tooltip = self . ctx . style ( ) . interaction . tooltip_delay
616
- - self . ctx . input ( |i| i. pointer . time_since_last_movement ( ) ) ;
604
+ let when_was_a_toolip_last_shown_id = Id :: new ( "when_was_a_toolip_last_shown" ) ;
605
+ let now = self . ctx . input ( |i| i. time ) ;
606
+
607
+ let when_was_a_toolip_last_shown = self
608
+ . ctx
609
+ . data ( |d| d. get_temp :: < f64 > ( when_was_a_toolip_last_shown_id) ) ;
610
+
611
+ let tooltip_delay = self . ctx . style ( ) . interaction . tooltip_delay ;
612
+ let tooltip_grace_time = self . ctx . style ( ) . interaction . tooltip_grace_time ;
613
+
614
+ // There is a tooltip_delay before showing the first tooltip,
615
+ // but once one tooltips is show, moving the mouse cursor to
616
+ // another widget should show the tooltip for that widget right away.
617
+
618
+ // Let the user quickly move over some dead space to hover the next thing
619
+ let tooltip_was_recently_shown = when_was_a_toolip_last_shown
620
+ . map_or ( false , |time| ( ( now - time) as f32 ) < tooltip_grace_time) ;
621
+
622
+ if !tooltip_was_recently_shown && !self . is_tooltip_open ( ) {
623
+ if self . ctx . style ( ) . interaction . show_tooltips_only_when_still {
624
+ // We only show the tooltip when the mouse pointer is still.
625
+ if !self . ctx . input ( |i| i. pointer . is_still ( ) ) {
626
+ // wait for mouse to stop
627
+ self . ctx . request_repaint ( ) ;
628
+ return false ;
629
+ }
630
+ }
631
+
632
+ let time_til_tooltip =
633
+ tooltip_delay - self . ctx . input ( |i| i. pointer . time_since_last_movement ( ) ) ;
617
634
618
635
if 0.0 < time_til_tooltip {
619
636
// Wait until the mouse has been still for a while
@@ -633,6 +650,12 @@ impl Response {
633
650
return false ;
634
651
}
635
652
653
+ // All checks passed: show the tooltip!
654
+
655
+ // Remember that we're showing a tooltip
656
+ self . ctx
657
+ . data_mut ( |data| data. insert_temp :: < f64 > ( when_was_a_toolip_last_shown_id, now) ) ;
658
+
636
659
true
637
660
}
638
661
0 commit comments