@@ -7,26 +7,31 @@ use emath::Vec2;
7
7
8
8
pub struct Tooltip < ' a > {
9
9
pub popup : Popup < ' a > ,
10
- layer_id : LayerId ,
11
- widget_id : Id ,
10
+
11
+ /// The layer of the parent widget.
12
+ parent_layer : LayerId ,
13
+
14
+ /// The id of the widget that owns this tooltip.
15
+ parent_widget : Id ,
12
16
}
13
17
14
18
impl Tooltip < ' _ > {
15
- /// Show a tooltip that is always open
19
+ /// Show a tooltip that is always open.
16
20
pub fn new (
17
- widget_id : Id ,
18
21
ctx : Context ,
22
+ parent_layer : LayerId ,
23
+ parent_widget : Id ,
19
24
anchor : impl Into < PopupAnchor > ,
20
- layer_id : LayerId ,
21
25
) -> Self {
26
+ let width = ctx. style ( ) . spacing . tooltip_width ;
22
27
Self {
23
- // TODO(lucasmerlin): Set width somehow (we're missing context here)
24
- popup : Popup :: new ( widget_id, ctx, anchor. into ( ) , layer_id)
28
+ popup : Popup :: new ( parent_widget, ctx, anchor. into ( ) , parent_layer)
25
29
. kind ( PopupKind :: Tooltip )
26
30
. gap ( 4.0 )
31
+ . width ( width)
27
32
. sense ( Sense :: hover ( ) ) ,
28
- layer_id ,
29
- widget_id ,
33
+ parent_layer ,
34
+ parent_widget ,
30
35
}
31
36
}
32
37
@@ -39,8 +44,8 @@ impl Tooltip<'_> {
39
44
. sense ( Sense :: hover ( ) ) ;
40
45
Self {
41
46
popup,
42
- layer_id : response. layer_id ,
43
- widget_id : response. id ,
47
+ parent_layer : response. layer_id ,
48
+ parent_widget : response. id ,
44
49
}
45
50
}
46
51
@@ -96,8 +101,8 @@ impl Tooltip<'_> {
96
101
pub fn show < R > ( self , content : impl FnOnce ( & mut crate :: Ui ) -> R ) -> Option < InnerResponse < R > > {
97
102
let Self {
98
103
mut popup,
99
- layer_id : parent_layer,
100
- widget_id ,
104
+ parent_layer,
105
+ parent_widget ,
101
106
} = self ;
102
107
103
108
if !popup. is_open ( ) {
@@ -111,19 +116,19 @@ impl Tooltip<'_> {
111
116
fs. layers
112
117
. entry ( parent_layer)
113
118
. or_default ( )
114
- . widget_with_tooltip = Some ( widget_id ) ;
119
+ . widget_with_tooltip = Some ( parent_widget ) ;
115
120
116
121
fs. tooltips
117
122
. widget_tooltips
118
- . get ( & widget_id )
123
+ . get ( & parent_widget )
119
124
. copied ( )
120
125
. unwrap_or ( PerWidgetTooltipState {
121
126
bounding_rect : rect,
122
127
tooltip_count : 0 ,
123
128
} )
124
129
} ) ;
125
130
126
- let tooltip_area_id = Self :: tooltip_id ( widget_id , state. tooltip_count ) ;
131
+ let tooltip_area_id = Self :: tooltip_id ( parent_widget , state. tooltip_count ) ;
127
132
popup = popup. anchor ( state. bounding_rect ) . id ( tooltip_area_id) ;
128
133
129
134
let response = popup. show ( |ui| {
@@ -144,7 +149,7 @@ impl Tooltip<'_> {
144
149
response
145
150
. response
146
151
. ctx
147
- . pass_state_mut ( |fs| fs. tooltips . widget_tooltips . insert ( widget_id , state) ) ;
152
+ . pass_state_mut ( |fs| fs. tooltips . widget_tooltips . insert ( parent_widget , state) ) ;
148
153
Self :: remember_that_tooltip_was_shown ( & response. response . ctx ) ;
149
154
}
150
155
0 commit comments