menu bar: MenuTitlePad, the padding role of the titles an app sets at its root; Control sets them closer, as an app bar whose menus share the line with many controls

This commit is contained in:
bflatastic committed 2026-11-24 13:38:50 +07:00
1 parent 161c99c637
commit cb367bccf3
3 files changed
+35 -3

No files matched your search

+18 -1
View File
@@ -49,6 +49,20 @@ use egui::{Context, Pos2, Rect, Response, Ui, Vec2};
const TITLE: PartKey = PartKey::new("title");
const MORE: PartKey = PartKey::new("more");
/// How much room a menu bar's titles take on each side of their text, and so how far apart they stand. An app sets it
/// once at its root (`RootEnv::values`); the default is the regular padding.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)]
#[env(style)]
#[non_exhaustive]
pub enum MenuTitlePad {
/// The padding inside panels (`space.pad.regular`).
#[default]
Regular,
/// The padding inside controls (`space.pad.control`): titles set closer, as in an app bar whose menus share the
/// line with many controls.
Control,
}
/// The style of a title's face: a menu row's surface and ink (flat, square corners, no border), with the accent fill
/// and `text.on_accent` under the pointer and while its menu is open or the keyboard is on it.
#[derive(Clone, Debug, PartialEq, ComponentStyle)]
@@ -103,7 +117,10 @@ impl Component for TitleFace {
TitleFaceStyle {
surface,
metrics: Metrics::new()
.padding(craft_behavior::Insets::horizontal(tokens.space.pad.regular))
.padding(craft_behavior::Insets::horizontal(match cx.env::<MenuTitlePad>() {
MenuTitlePad::Regular => tokens.space.pad.regular,
MenuTitlePad::Control => tokens.space.pad.control,
}))
.min_size(Vec2::new(0.0, control.height))
.gap(control.gap),
focus: cx.focus_look(),
+16 -1
View File
@@ -1,11 +1,12 @@
//! Stories of the menu bar, the edit menu and the panel menu.
use super::{MenuBar, MenuHelp, MenuTitle};
use super::{MenuBar, MenuHelp, MenuTitle, MenuTitlePad};
use crate::buttons::{IconButton, PopupMark};
use crate::contract::{Entry, PopupKind, Props as _, Show as _, ShowContainer as _, Trigger};
use crate::display::Divider;
use crate::menu::{EditMenu, GroupItem, HelpEntry, Menu, MenuItem, PanelMenu, PanelRow};
use crate::runtime::commands::EditCommands;
use crate::runtime::env::with_env;
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story};
use craft_behavior::IconId;
use craft_theme::ControlSize;
@@ -87,6 +88,20 @@ fn menu_bar_open(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
MenuBar::new("Main menu", titles()).show(ui).into()
}
/// Titles set closer (`MenuTitlePad::Control`), as an app sets it at its root for a bar whose menus share the line with
/// many controls.
#[story(MenuBar<'static>, covers = [], drive = Drive::Never)]
fn menu_bar_close_titles(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
with_env(
ui,
|overrides| {
overrides.values.set(MenuTitlePad::Control);
},
|ui| MenuBar::new("Main menu", titles()).show(ui),
)
.into()
}
#[story(MenuBar<'static>, covers = [], drive = Drive::Never)]
fn menu_bar_with_help_search(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let entries = || HELP.clone();
+1 -1
View File
@@ -15,7 +15,7 @@ pub(crate) mod stories;
mod words;
pub use alternate::Alternate;
pub use bar::{MenuBar, MenuBarOutput, MenuBarStyle, MenuHelp, MenuTitle};
pub use bar::{MenuBar, MenuBarOutput, MenuBarStyle, MenuHelp, MenuTitle, MenuTitlePad};
pub(crate) use edit::text_menu;
pub use edit::{EditMenu, EditMenuOutput};
pub use icon_row::{MenuIcon, MenuIconRow, MenuIconRowOutput};