OverlayLayer::dismiss_all

This commit is contained in:
Jonathan Johnson 2024-03-20 11:40:20 -07:00
parent a63af0f9de
commit 74034760ce
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
2 changed files with 15 additions and 0 deletions

View file

@ -237,6 +237,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `ModifiersExt` is an extension trait for winit's `Modifiers` and
`ModifiersState` types. This trait adds helpers for dealing with
platform-specific meanings for keyboard modifiers.
- `OverlayLayer::dismiss_all()` dismisses all overlays immediately.
[plotters]: https://github.com/plotters-rs/plotters

View file

@ -171,6 +171,20 @@ impl OverlayLayer {
show_animation: None,
}
}
/// Dismisses all currently presented overlays.
pub fn dismiss_all(&self) {
let mut state = self.state.lock();
state.hovering = None;
let removed = state.overlays.drain().collect::<Vec<_>>();
state.new_overlays = 0;
drop(state);
// Since overlays contain references back to this structure, we need to
// ensure their drop implementations happen after we've dropped our
// lock.
drop(removed);
}
}
impl Widget for OverlayLayer {