diff --git a/CHANGELOG.md b/CHANGELOG.md index d61fda0..0e2c675 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/widgets/layers.rs b/src/widgets/layers.rs index a6051a4..395e606 100644 --- a/src/widgets/layers.rs +++ b/src/widgets/layers.rs @@ -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::>(); + 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 {