From 74034760ce60e291eb80e0f9002835712fd8ae0f Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Wed, 20 Mar 2024 11:40:20 -0700 Subject: [PATCH] OverlayLayer::dismiss_all --- CHANGELOG.md | 1 + src/widgets/layers.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) 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 {