diff --git a/crates/egui/src/containers/close_tag.rs b/crates/egui/src/containers/close_tag.rs index 3d5e3f43..3e93dbbd 100644 --- a/crates/egui/src/containers/close_tag.rs +++ b/crates/egui/src/containers/close_tag.rs @@ -1,5 +1,13 @@ +#[expect(unused_imports)] +use crate::{Ui, UiBuilder}; use std::sync::atomic::AtomicBool; +/// A tag to mark a container as closable. +/// +/// Usually set via [`UiBuilder::closable`]. +/// +/// [`Ui::close`] will find the closest parent [`ClosableTag`] and set its `close` field to `true`. +/// Use [`Ui::should_close`] to check if close has been called. #[derive(Debug, Default)] pub struct ClosableTag { pub close: AtomicBool, diff --git a/crates/egui/src/containers/menu.rs b/crates/egui/src/containers/menu.rs index 13d3ebe2..1e2cbfa2 100644 --- a/crates/egui/src/containers/menu.rs +++ b/crates/egui/src/containers/menu.rs @@ -1,4 +1,12 @@ -//! See [`MenuBar`] for an example +//! Popup menus, context menus and menu bars. +//! +//! Show menus via +//! - [`Popup::menu`] and [`Popup::context_menu`] +//! - [`Ui::menu_button`], [`MenuButton`] and [`SubMenuButton`] +//! - [`MenuBar`] +//! - [`Response::context_menu`] +//! +//! See [`MenuBar`] for an example. use crate::style::StyleModifier; use crate::{ @@ -52,6 +60,7 @@ pub fn is_in_menu(ui: &Ui) -> bool { false } +/// Configuration and style for menus. #[derive(Clone, Debug)] pub struct MenuConfig { /// Is this a menu bar? @@ -122,8 +131,10 @@ impl MenuConfig { } } +/// Holds the state of the menu. #[derive(Clone)] pub struct MenuState { + /// The currently open sub menu in this menu. pub open_item: Option, last_visible_pass: u64, } @@ -359,6 +370,10 @@ impl<'a> SubMenuButton<'a> { } } +/// Show a submenu in a menu. +/// +/// Useful if you want to make custom menu buttons. +/// Usually, just use [`MenuButton`] or [`SubMenuButton`] instead. #[derive(Clone, Debug, Default)] pub struct SubMenu { config: Option, diff --git a/crates/egui/src/containers/mod.rs b/crates/egui/src/containers/mod.rs index 31898838..4312385d 100644 --- a/crates/egui/src/containers/mod.rs +++ b/crates/egui/src/containers/mod.rs @@ -3,7 +3,7 @@ //! For instance, a [`Frame`] adds a frame and background to some contained UI. pub(crate) mod area; -pub mod close_tag; +mod close_tag; pub mod collapsing_header; mod combo_box; pub mod frame; @@ -21,6 +21,7 @@ pub(crate) mod window; pub use { area::{Area, AreaState}, + close_tag::ClosableTag, collapsing_header::{CollapsingHeader, CollapsingResponse}, combo_box::*, frame::Frame, diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 66ceddda..9c280413 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -162,6 +162,7 @@ impl From for UiKind { } } +/// A popup container. #[must_use = "Call `.show()` to actually display the popup"] pub struct Popup<'a> { id: Id, diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index c24ca211..56392156 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -5,9 +5,9 @@ use emath::GuiRounding as _; use epaint::mutex::RwLock; use std::{any::Any, hash::Hash, sync::Arc}; +use crate::ClosableTag; #[cfg(debug_assertions)] use crate::Stroke; -use crate::close_tag::ClosableTag; use crate::containers::menu; use crate::{ Align, Color32, Context, CursorIcon, DragAndDrop, Id, InnerResponse, InputState, IntoAtoms, diff --git a/crates/egui/src/ui_builder.rs b/crates/egui/src/ui_builder.rs index fcb389fd..54917018 100644 --- a/crates/egui/src/ui_builder.rs +++ b/crates/egui/src/ui_builder.rs @@ -1,8 +1,8 @@ use std::{hash::Hash, sync::Arc}; +use crate::ClosableTag; #[expect(unused_imports)] // Used for doclinks use crate::Ui; -use crate::close_tag::ClosableTag; use crate::{Id, LayerId, Layout, Rect, Sense, Style, UiStackInfo}; /// Build a [`Ui`] as the child of another [`Ui`].