Add more docs to menu (#7331)

Improves the docs a bit
This commit is contained in:
Lucas Meurer 2025-07-10 15:35:04 +02:00 committed by GitHub
parent 14c2e5d3d5
commit c0325e9be2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 4 deletions

View File

@ -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,

View File

@ -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<Id>,
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<MenuConfig>,

View File

@ -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,

View File

@ -162,6 +162,7 @@ impl From<PopupKind> for UiKind {
}
}
/// A popup container.
#[must_use = "Call `.show()` to actually display the popup"]
pub struct Popup<'a> {
id: Id,

View File

@ -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,

View File

@ -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`].