Skip to content

Commit 44c0d75

Browse files
committed
fix: drop remaining component overlay events if closed during event batch processing
1 parent 042a294 commit 44c0d75

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

lazy/src/component.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,11 @@ struct Overlay<'a, 'b, Message, Renderer, Event> {
258258
impl<'a, 'b, Message, Renderer, Event>
259259
Overlay<'a, 'b, Message, Renderer, Event>
260260
{
261-
fn with_overlay<T>(
261+
fn with_overlay_maybe<T>(
262262
&self,
263263
f: impl FnOnce(&overlay::Element<'_, Event, Renderer>) -> T,
264-
) -> T {
265-
f(self
266-
.instance
264+
) -> Option<T> {
265+
self.instance
267266
.state
268267
.borrow()
269268
.as_ref()
@@ -273,13 +272,13 @@ impl<'a, 'b, Message, Renderer, Event>
273272
.unwrap()
274273
.borrow_overlay()
275274
.as_ref()
276-
.unwrap())
275+
.map(f)
277276
}
278277

279-
fn with_overlay_mut<T>(
278+
fn with_overlay_mut_maybe<T>(
280279
&self,
281280
f: impl FnOnce(&mut overlay::Element<'_, Event, Renderer>) -> T,
282-
) -> T {
281+
) -> Option<T> {
283282
self.instance
284283
.state
285284
.borrow_mut()
@@ -289,7 +288,7 @@ impl<'a, 'b, Message, Renderer, Event>
289288
cache
290289
.as_mut()
291290
.unwrap()
292-
.with_overlay_mut(|overlay| f(overlay.as_mut().unwrap()))
291+
.with_overlay_mut(|overlay| overlay.as_mut().map(f))
293292
})
294293
}
295294
}
@@ -305,11 +304,12 @@ where
305304
bounds: Size,
306305
position: Point,
307306
) -> layout::Node {
308-
self.with_overlay(|overlay| {
307+
self.with_overlay_maybe(|overlay| {
309308
let vector = position - overlay.position();
310309

311310
overlay.layout(renderer, bounds).translate(vector)
312311
})
312+
.unwrap_or_default()
313313
}
314314

315315
fn draw(
@@ -319,9 +319,9 @@ where
319319
layout: Layout<'_>,
320320
cursor_position: Point,
321321
) {
322-
self.with_overlay(|overlay| {
322+
self.with_overlay_maybe(|overlay| {
323323
overlay.draw(renderer, style, layout, cursor_position);
324-
})
324+
});
325325
}
326326

327327
fn mouse_interaction(
@@ -330,9 +330,10 @@ where
330330
cursor_position: Point,
331331
viewport: &Rectangle,
332332
) -> mouse::Interaction {
333-
self.with_overlay(|overlay| {
333+
self.with_overlay_maybe(|overlay| {
334334
overlay.mouse_interaction(layout, cursor_position, viewport)
335335
})
336+
.unwrap_or_default()
336337
}
337338

338339
fn hash_layout(&self, state: &mut Hasher, position: Point) {
@@ -342,7 +343,7 @@ where
342343
(position.x as u32).hash(state);
343344
(position.y as u32).hash(state);
344345

345-
self.with_overlay(|overlay| {
346+
self.with_overlay_maybe(|overlay| {
346347
overlay.hash_layout(state);
347348
});
348349
}
@@ -359,16 +360,18 @@ where
359360
let mut local_messages = Vec::new();
360361
let mut local_shell = Shell::new(&mut local_messages);
361362

362-
let event_status = self.with_overlay_mut(|overlay| {
363-
overlay.on_event(
364-
event,
365-
layout,
366-
cursor_position,
367-
renderer,
368-
clipboard,
369-
&mut local_shell,
370-
)
371-
});
363+
let event_status = self
364+
.with_overlay_mut_maybe(|overlay| {
365+
overlay.on_event(
366+
event,
367+
layout,
368+
cursor_position,
369+
renderer,
370+
clipboard,
371+
&mut local_shell,
372+
)
373+
})
374+
.unwrap_or_else(|| iced_native::event::Status::Ignored);
372375

373376
if !local_messages.is_empty() {
374377
let mut component =

0 commit comments

Comments
 (0)