egui/containers/close_tag.rs
1#[expect(unused_imports)]
2use crate::{Ui, UiBuilder};
3use std::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.store(true, std::sync::atomic::Ordering::Relaxed);
22 }
23
24 /// Returns `true` if [`ClosableTag::set_close`] has been called.
25 pub fn should_close(&self) -> bool {
26 self.close.load(std::sync::atomic::Ordering::Relaxed)
27 }
28}