@@ -54,7 +54,8 @@ impl FromWorld for TooltipRoot {
54
54
font : FONT_HANDLE ,
55
55
..default ( )
56
56
} ,
57
- ) ,
57
+ )
58
+ . with_text_justify ( JustifyText :: Center ) ,
58
59
// TODO: Adjustable font sizes in ThemeConfig
59
60
DynamicFontSize :: new ( Px ( 16.0 ) ) ,
60
61
ThemeColorForText ( vec ! [ ThemeColor :: BodyText ] ) ,
@@ -85,7 +86,7 @@ pub struct Tooltip {
85
86
impl Configure for Tooltip {
86
87
fn configure ( app : & mut App ) {
87
88
app. register_type :: < Self > ( ) ;
88
- app. add_systems ( Update , show_tooltip_on_hover. in_set ( UpdateSet :: SyncLate ) ) ;
89
+ app. add_systems ( Update , show_tooltip_on_hover. in_set ( UpdateSet :: RecordInput ) ) ;
89
90
}
90
91
}
91
92
@@ -97,35 +98,41 @@ fn show_tooltip_on_hover(
97
98
mut text_query : Query < & mut Text > ,
98
99
interaction_query : Query < ( & Interaction , & Tooltip , & GlobalTransform , & Node ) > ,
99
100
) {
100
- let window = r ! ( window_query. get( window_root. primary) ) ;
101
101
let ( mut visibility, mut style) = r ! ( container_query. get_mut( tooltip_root. container) ) ;
102
102
let mut text = r ! ( text_query. get_mut( tooltip_root. text) ) ;
103
+ let window = r ! ( window_query. get( window_root. primary) ) ;
104
+ let width = window. width ( ) ;
105
+ let height = window. height ( ) ;
103
106
104
107
for ( interaction, tooltip, gt, node) in & interaction_query {
108
+ // Skip nodes that are not hovered.
105
109
if matches ! ( interaction, Interaction :: None ) {
106
110
* visibility = Visibility :: Hidden ;
107
111
continue ;
108
112
}
109
113
110
- let rect = node. logical_rect ( gt) ;
114
+ // Set the tooltip text and make it visible.
115
+ * visibility = Visibility :: Inherited ;
116
+ text. sections [ 0 ] . value . clone_from ( & tooltip. text ) ;
111
117
112
- let width = window . width ( ) ;
113
- let height = window . height ( ) ;
118
+ // Get the left, right, top, bottom of the target node.
119
+ let rect = node . logical_rect ( gt ) ;
114
120
let ( left, right, top, bottom) = (
115
121
rect. min . x + tooltip. offset . x ,
116
122
rect. max . x + tooltip. offset . x ,
117
123
rect. min . y + tooltip. offset . y ,
118
124
rect. max . y + tooltip. offset . y ,
119
125
) ;
120
126
121
- * visibility = Visibility :: Inherited ;
122
- text. sections [ 0 ] . value . clone_from ( & tooltip. text ) ;
127
+ // Set the left, right, top, bottom of the tooltip node.
123
128
( style. left , style. right , style. top , style. bottom ) = match tooltip. side {
124
129
TooltipSide :: Left => ( Auto , Px ( width - left) , Auto , Px ( height - bottom) ) ,
125
130
TooltipSide :: Right => ( Px ( right) , Auto , Auto , Px ( height - bottom) ) ,
126
131
TooltipSide :: Top => ( Px ( left) , Auto , Auto , Px ( height - top) ) ,
127
132
TooltipSide :: Bottom => ( Px ( left) , Auto , Px ( bottom) , Auto ) ,
128
133
} ;
134
+
135
+ // Exit early (because there's only one tooltip).
129
136
return ;
130
137
}
131
138
}
0 commit comments