From 03fea7ac47339fda990a1fcaf2f0dd48592be0ea Mon Sep 17 00:00:00 2001 From: bflatastic Date: Wed, 25 Nov 2026 14:34:45 +0700 Subject: [PATCH] ui-contract, ui-widgets menu: a menu row stands size.row.menu high (StyleCx::menu_row_height, grown as a control's height is; a small row stays a small control high); a compact row keeps its text line's height. Every size set gives size.row.menu the control's height, so no app's menus change. Trial --- crates/ui-contract/src/style/cx.rs | 9 +++++++++ crates/ui-widgets/src/menu/item.rs | 6 ++---- crates/ui-widgets/tests/it/menu/rows.rs | 25 +++++++++++++++++++++++++ docs/craft-framework.md | 1 + 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/ui-contract/src/style/cx.rs b/crates/ui-contract/src/style/cx.rs index 30d36336f3..db676d7180 100644 --- a/crates/ui-contract/src/style/cx.rs +++ b/crates/ui-contract/src/style/cx.rs @@ -405,6 +405,15 @@ impl<'a> StyleCx<'a> { } } + /// The height of a menu row at the ambient size: `size.row.menu` at the medium size, grown as a control's height + /// is; a small row stands a small control high. + pub fn menu_row_height(&self) -> f32 { + match self.size { + ControlSize::Sm => self.control().height, + ControlSize::Md => grown(self.tokens, self.tokens.size.row.menu, self.line_ratio), + } + } + /// How the icon-only buttons of the scope show their glyph. pub fn glyph_role(&self) -> GlyphRole { self.glyphs diff --git a/crates/ui-widgets/src/menu/item.rs b/crates/ui-widgets/src/menu/item.rs index 1bcab388df..61f23d735b 100644 --- a/crates/ui-widgets/src/menu/item.rs +++ b/crates/ui-widgets/src/menu/item.rs @@ -487,10 +487,8 @@ impl Component for MenuItem<'_> { // A row's content sits `space.pad.regular` in from the popup's own padding, so a label starts clear of the edge. let mut metrics = control.metrics(); metrics.padding = Insets::new(tokens.space.pad.regular, tokens.space.pad.regular, metrics.padding.top, metrics.padding.bottom); - if key.compact { - // The text line sets the height, as in a classic menu: no control height floor. - metrics.min_size.y = 0.0; - } + // The text line sets a compact row's height, as in a classic menu; any other row stands a menu row high. + metrics.min_size.y = if key.compact { 0.0 } else { cx.menu_row_height() }; MenuItemStyle { surface, metrics, diff --git a/crates/ui-widgets/tests/it/menu/rows.rs b/crates/ui-widgets/tests/it/menu/rows.rs index b411d063fa..68e7984eec 100644 --- a/crates/ui-widgets/tests/it/menu/rows.rs +++ b/crates/ui-widgets/tests/it/menu/rows.rs @@ -398,3 +398,28 @@ fn the_open_submenu_parent_keeps_the_accent_when_the_pointer_enters_its_child() assert_eq!(fills_in(&shapes, parent), accent, "the parent keeps its accent while its child is active at {scale}×"); } } + +/// A menu row stands `size.row.menu` high (VectorCraft's 29-point rows), and an app that sets only the control height +/// keeps its rows a control high. +#[trial] +fn a_menu_row_stands_a_menu_row_high() { + let row = |overrides: &[(&str, f32)]| { + let mut sizes = craft_theme::AppSizes::default(); + for (path, value) in overrides { + sizes.all.insert((*path).to_owned(), craft_theme::SizeValue::Number(*value)); + } + let mut root = craft_ui::runtime::env::RootEnv::default(); + root.sizes = Arc::new(sizes); + let mut fixture = Fixture::new(|ui| { + Menu::inline("File").show(ui, |ui, _| { + MenuItem::new("Open").show(ui); + MenuItem::new("Save").show(ui); + }); + }); + fixture.root(root).settle(); + fixture.by_label("Save").expect("the row is shown").rect.height() + }; + let (standard, menu, control) = (row(&[]), row(&[("size.row.menu", 44.0)]), row(&[("size.control.md", 44.0)])); + assert!(menu > standard + 10.0, "a taller menu row raises the row: {standard} then {menu}"); + assert!((control - menu).abs() < 0.5, "a row follows the control height when the app sets no menu row: {control} and {menu}"); +} diff --git a/docs/craft-framework.md b/docs/craft-framework.md index ca71e4532e..0b56e6d904 100644 --- a/docs/craft-framework.md +++ b/docs/craft-framework.md @@ -1006,6 +1006,7 @@ A theme with its own shape replaces the radii or adds an offset to control, surf | `size.length.number.sm`, `size.length.number.md` | Number field and the number cell over a slider, one width per control size | | `size.length.track`, `size.length.short` | Value track, short field | | `size.row.text` | A row that shows text only: one body line and `space.gap.tight`; read-only display tables take it, lists the user picks from keep control-high rows | +| `size.row.menu` | A menu row's height at the medium control size (`MenuItem`); follows an app's `size.control.md` unless the app sets it | | `size.dialog.least`, `size.dialog.wrap` | A dialog's content: the least width it opens at, and the line length its paragraphs wrap at (`LeastWidth::Dialog`, `WrapWidth::Dialog`); content that cannot wrap widens it past that | | `size.dialog.button`, `size.dialog.side_button` | Least width of a dialog's footer button and of a button in its column beside the body | | `size.hit.edge` | The band inside the edge of a canvas's view in which a tool that autoscrolls on hover scrolls the view (a Polygonal Lasso's rubber band), at most a quarter of the view's shorter side |