From 5a5235dab0681a8bdb1fa45f9746cd65d663b50a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 18 Jun 2025 19:24:24 -0700 Subject: [PATCH] Add `UiBuilder::with_closable` --- crates/egui/src/ui_builder.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/egui/src/ui_builder.rs b/crates/egui/src/ui_builder.rs index fcb389fd9..1e1b4d4f7 100644 --- a/crates/egui/src/ui_builder.rs +++ b/crates/egui/src/ui_builder.rs @@ -145,10 +145,24 @@ impl UiBuilder { /// /// This works by adding a [`ClosableTag`] to the [`UiStackInfo`]. #[inline] - pub fn closable(mut self) -> Self { - self.ui_stack_info - .tags - .insert(ClosableTag::NAME, Some(Arc::new(ClosableTag::default()))); + pub fn closable(self) -> Self { + self.with_closable(true) + } + + /// Make this [`Ui`] closable? + /// + /// Calling [`Ui::close`] in a child [`Ui`] will mark this [`Ui`] for closing. + /// After [`Ui::close`] was called, [`Ui::should_close`] and [`crate::Response::should_close`] will + /// return `true` (for this frame). + /// + /// This works by adding a [`ClosableTag`] to the [`UiStackInfo`]. + #[inline] + pub fn with_closable(mut self, closable: bool) -> Self { + if closable { + self.ui_stack_info + .tags + .insert(ClosableTag::NAME, Some(Arc::new(ClosableTag::default()))); + } self } }