egui/containers/close_tag.rs
1#[expect(unused_imports)]
2use crate::{Ui, UiBuilder};
3use core::sync::atomic::AtomicBool;
4
5/// A tag to mark a container as closable.
6///
7/// Usually set via [`UiBuilder::closable`].
8///
9/// [`Ui::close`] will find the closest parent [`ClosableTag`] and set its `close` field to `true`.
10/// Use [`Ui::should_close`] to check if close has been called.
11#[derive(Debug, Default)]
12pub struct ClosableTag {
13 pub close: AtomicBool,
14}
15
16impl ClosableTag {
17 pub const NAME: &'static str = "egui_close_tag";
18
19 /// Set close to `true`
20 pub fn set_close(&self) {
21 self.close
22 .store(true, core::sync::atomic::Ordering::Relaxed);
23 }
24
25 /// Returns `true` if [`ClosableTag::set_close`] has been called.
26 pub fn should_close(&self) -> bool {
27 self.close.load(core::sync::atomic::Ordering::Relaxed)
28 }
29}