@@ -254,17 +254,6 @@ impl WidgetRects {
254
254
255
255
let layer_widgets = self . by_layer . entry ( layer_id) . or_default ( ) ;
256
256
257
- if let Some ( last) = layer_widgets. last_mut ( ) {
258
- if last. id == widget_rect. id {
259
- // e.g. calling `response.interact(…)` right after interacting.
260
- last. sense |= widget_rect. sense ;
261
- last. interact_rect = last. interact_rect . union ( widget_rect. interact_rect ) ;
262
- return ;
263
- }
264
- }
265
-
266
- layer_widgets. push ( widget_rect) ;
267
-
268
257
match self . by_id . entry ( widget_rect. id ) {
269
258
std:: collections:: hash_map:: Entry :: Vacant ( entry) => {
270
259
entry. insert ( widget_rect) ;
@@ -276,6 +265,17 @@ impl WidgetRects {
276
265
existing. interact_rect = existing. interact_rect . union ( widget_rect. interact_rect ) ;
277
266
}
278
267
}
268
+
269
+ if let Some ( last) = layer_widgets. last_mut ( ) {
270
+ if last. id == widget_rect. id {
271
+ // e.g. calling `response.interact(…)` right after interacting.
272
+ last. sense |= widget_rect. sense ;
273
+ last. interact_rect = last. interact_rect . union ( widget_rect. interact_rect ) ;
274
+ return ;
275
+ }
276
+ }
277
+
278
+ layer_widgets. push ( widget_rect) ;
279
279
}
280
280
}
281
281
@@ -1105,9 +1105,14 @@ impl Context {
1105
1105
layer_id : LayerId ,
1106
1106
id : Id ,
1107
1107
rect : Rect ,
1108
- sense : Sense ,
1108
+ mut sense : Sense ,
1109
1109
enabled : bool ,
1110
1110
) -> Response {
1111
+ if !enabled {
1112
+ sense. click = false ;
1113
+ sense. drag = false ;
1114
+ }
1115
+
1111
1116
// Respect clip rectangle when interacting:
1112
1117
let interact_rect = clip_rect. intersect ( rect) ;
1113
1118
@@ -1126,7 +1131,7 @@ impl Context {
1126
1131
) ;
1127
1132
}
1128
1133
1129
- self . interact_with_hovered (
1134
+ self . interact_with_existing (
1130
1135
layer_id,
1131
1136
id,
1132
1137
rect,
@@ -1139,16 +1144,21 @@ impl Context {
1139
1144
1140
1145
/// You specify if a thing is hovered, and the function gives a [`Response`].
1141
1146
#[ allow( clippy:: too_many_arguments) ]
1142
- pub ( crate ) fn interact_with_hovered (
1147
+ pub ( crate ) fn interact_with_existing (
1143
1148
& self ,
1144
1149
layer_id : LayerId ,
1145
1150
id : Id ,
1146
1151
rect : Rect ,
1147
1152
interact_rect : Rect ,
1148
- sense : Sense ,
1153
+ mut sense : Sense ,
1149
1154
enabled : bool ,
1150
1155
contains_pointer : bool ,
1151
1156
) -> Response {
1157
+ if !enabled {
1158
+ sense. click = false ;
1159
+ sense. drag = false ;
1160
+ }
1161
+
1152
1162
// This is the start - we'll fill in the fields below:
1153
1163
let mut res = Response {
1154
1164
ctx : self . clone ( ) ,
@@ -1159,7 +1169,7 @@ impl Context {
1159
1169
sense,
1160
1170
enabled,
1161
1171
contains_pointer,
1162
- hovered : contains_pointer && enabled ,
1172
+ hovered : false ,
1163
1173
highlighted : self . frame_state ( |fs| fs. highlight_this_frame . contains ( & id) ) ,
1164
1174
clicked : Default :: default ( ) ,
1165
1175
double_clicked : Default :: default ( ) ,
@@ -1235,11 +1245,14 @@ impl Context {
1235
1245
res. is_pointer_button_down_on =
1236
1246
interaction. click_id == Some ( id) || interaction. drag_id == Some ( id) ;
1237
1247
1238
- res. dragged = Some ( id) == viewport. interact_widgets . dragged . map ( |w| w. id ) ;
1239
- res. drag_started = Some ( id) == viewport. interact_widgets . drag_started . map ( |w| w. id ) ;
1240
- res. drag_released = Some ( id) == viewport. interact_widgets . drag_ended . map ( |w| w. id ) ;
1248
+ if enabled {
1249
+ res. hovered = viewport. interact_widgets . hovered . contains_key ( & id) ;
1250
+ res. dragged = Some ( id) == viewport. interact_widgets . dragged . map ( |w| w. id ) ;
1251
+ res. drag_started = Some ( id) == viewport. interact_widgets . drag_started . map ( |w| w. id ) ;
1252
+ res. drag_released = Some ( id) == viewport. interact_widgets . drag_ended . map ( |w| w. id ) ;
1253
+ }
1241
1254
1242
- let clicked = viewport. interact_widgets . clicked . iter ( ) . any ( |w| w. id == id) ;
1255
+ let clicked = Some ( id ) == viewport. interact_widgets . clicked . map ( |w| w. id ) ;
1243
1256
1244
1257
if sense. click && clicked {
1245
1258
// We were clicked - what kind of click?
@@ -1922,10 +1935,13 @@ impl Context {
1922
1935
top,
1923
1936
click,
1924
1937
drag,
1938
+ closest_interactive : _,
1925
1939
} = hits;
1926
1940
1927
- for widget in & contains_pointer {
1928
- paint ( widget, "contains_pointer" , Color32 :: BLUE ) ;
1941
+ if false {
1942
+ for widget in & contains_pointer {
1943
+ paint ( widget, "contains_pointer" , Color32 :: BLUE ) ;
1944
+ }
1929
1945
}
1930
1946
for widget in & top {
1931
1947
paint ( widget, "top" , Color32 :: WHITE ) ;
@@ -1949,11 +1965,15 @@ impl Context {
1949
1965
hovered,
1950
1966
} = interact_widgets;
1951
1967
1952
- for widget in contains_pointer. values ( ) {
1953
- paint ( widget, "contains_pointer" , Color32 :: BLUE ) ;
1968
+ if false {
1969
+ for widget in contains_pointer. values ( ) {
1970
+ paint ( widget, "contains_pointer" , Color32 :: BLUE ) ;
1971
+ }
1954
1972
}
1955
- for widget in hovered. values ( ) {
1956
- paint ( widget, "hovered" , Color32 :: WHITE ) ;
1973
+ if true {
1974
+ for widget in hovered. values ( ) {
1975
+ paint ( widget, "hovered" , Color32 :: WHITE ) ;
1976
+ }
1957
1977
}
1958
1978
for widget in & clicked {
1959
1979
paint ( widget, "clicked" , Color32 :: RED ) ;
0 commit comments