From 9f5c7be33b309e95570368db09229fa474953965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 18 Nov 2026 06:47:33 -0500 Subject: [PATCH 1/2] feat(ui): submenus open at least 100 px wide, their rows as tall as the menu's (#2398) A submenu of one-word rows (New Layout > Publication Layout > a page size's styles) opened as a narrow strip. Submenus now open at least SUBMENU_MIN_W (100) wide, half a ribbon menu's MENU_MIN_W (200). widgets::submenu opens one from a menu of plain buttons; submenu_row, from a menu of menu_item rows, so the row is as tall as the rows beside it (the report's Report Section and Data menus now use it). --- crates/ui-egui/src/panes.rs | 14 ++++---- crates/ui-egui/src/ribbon.rs | 64 +++++++++++++++++++++++++++-------- crates/ui-egui/src/widgets.rs | 33 ++++++++++++++---- 3 files changed, 83 insertions(+), 28 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index fecbe87fc..2889fc1af 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -1700,7 +1700,7 @@ fn tile_row(app: &mut RustGisApp, ui: &mut Ui, i: usize, moves: [bool; 2], reord action = Some(("map.setTiles", json!({"index": i, "opacity": o / 100.0}))); } }); - ui.menu_button(crate::i18n::fmt("Blend: {mode}", &[("mode", tl_raw!(tile.blend.label()))]), |ui| { + crate::widgets::submenu(ui, &crate::i18n::fmt("Blend: {mode}", &[("mode", tl_raw!(tile.blend.label()))]), |ui| { for b in rustgis_engine::map::effects::Blend::ALL { if ui.radio(tile.blend == b, tl!(b.label())).clicked() { action = Some(("map.setTiles", json!({"index": i, "blend": b.code()}))); @@ -1708,7 +1708,6 @@ fn tile_row(app: &mut RustGisApp, ui: &mut Ui, i: usize, moves: [bool; 2], reord } } }) - .response .on_hover_text(tl!("How the layer's colours combine with the tile layers and basemap beneath.")); // A layer its service draws on request: one picture of the view, or tiles (#1162). if tile.on_request() { @@ -1719,7 +1718,7 @@ fn tile_row(app: &mut RustGisApp, ui: &mut Ui, i: usize, moves: [bool; 2], reord } else { tl!("Tiles").to_string() }; - ui.menu_button(crate::i18n::fmt("Draw as: {how}", &[("how", &shown)]), |ui| { + crate::widgets::submenu(ui, &crate::i18n::fmt("Draw as: {how}", &[("how", &shown)]), |ui| { if ui.radio(tile.single_image, tl!("Single image")).on_hover_text(tl!("One picture of the view: symbols and labels aren't cut at tile edges, and the service is asked once a view. Drawn in tiles on the globe, on a tilted map, or in a projection the service doesn't offer.")).clicked() { action = Some(("map.setTiles", json!({"index": i, "singleImage": true}))); ui.close(); @@ -1737,7 +1736,6 @@ fn tile_row(app: &mut RustGisApp, ui: &mut Ui, i: usize, moves: [bool; 2], reord ui.close(); } }) - .response .on_hover_text(tl!("Whether the service is asked for one picture of the view or for tiles.")); } ui.separator(); @@ -2209,7 +2207,7 @@ fn extrusion_menu(app: &mut RustGisApp, ui: &mut Ui, picked: &[u32]) { }; let by = |f: &str| crate::i18n::fmt("By {field}", &[("field", f)]); let no_field = tl!("These layers share no numeric field."); - ui.menu_button(tl!("Extrusion"), |ui| { + crate::widgets::submenu(ui, tl!("Extrusion"), |ui| { head(ui); if ui.button(tl!("None")).clicked() { run(app, ui, "layer.extrusion", json!({"type": "none"})); @@ -2228,7 +2226,7 @@ fn extrusion_menu(app: &mut RustGisApp, ui: &mut Ui, picked: &[u32]) { .on_disabled_hover_text(tl!("Extrude them all first: the base is what their walls stand on.")); return; } - ui.menu_button(tl!("Extrusion Base"), |ui| { + crate::widgets::submenu(ui, tl!("Extrusion Base"), |ui| { head(ui); if ui.button(tl!("Ground")).clicked() { run(app, ui, "layer.extrusionBase", json!({"field": null, "base": 0})); @@ -2295,7 +2293,7 @@ fn layers_menu(app: &mut RustGisApp, ui: &mut Ui, picked: &[u32], reorder: bool) .and_then(|id| m.group_of(*id)) .map(|g| g.id) .filter(|g| picked.iter().all(|id| m.group_of(*id).map(|x| x.id) == Some(*g))); - ui.menu_button(tl!("Group"), |ui| { + crate::widgets::submenu(ui, tl!("Group"), |ui| { if ui.button(tl!("New Group")).clicked() { new_group(app, json!({"layers": picked, "parent": shared})); ui.close(); @@ -2490,7 +2488,7 @@ fn layer_menu(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, reorder: bool) { let m = app.session.map(); let groups: Vec<(u32, String)> = m.groups.iter().map(|g| (g.id, group_path(m, g.id))).collect(); let current = m.group_of(l.id).map(|g| g.id); - ui.menu_button(tl!("Group"), |ui| { + crate::widgets::submenu(ui, tl!("Group"), |ui| { // In the layer's group, if it has one (#836). if ui.button(tl!("New Group")).clicked() { new_group(app, json!({"layers": [l.id], "parent": current})); diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 8d60c3131..b17cfe6e2 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -12,7 +12,7 @@ use serde_json::{Value, json}; use crate::theme::{Tokens, regular, semibold}; use crate::widgets::{ CONTENT_H, Dragged, LABEL_H, big, big_form_menu, big_menu, big_split_form_menu, big_split_menu, col, group, menu_item, small, - small_form_menu, small_menu, submenu_row, text_w, + small_form_menu, small_menu, submenu, submenu_row, text_w, }; use crate::{RightPane, RustGisApp, icons}; @@ -1191,11 +1191,11 @@ fn project_group(app: &mut RustGisApp, ui: &mut Ui) { } } // A finished sheet or figure of the map view, its texts to fill in on the page. - ui.menu_button(tl!("Publication Layout"), |ui| { + submenu(ui, tl!("Publication Layout"), |ui| { // A sheet on each page size, as listed above; its styles under each orientation, so // the list stays as short as the sizes (a figure leaves the style to its caption). for (id, label, w, h) in rustgis_engine::map::layout::PAGES { - ui.menu_button(page_label(label, *w, *h), |ui| { + submenu(ui, &page_label(label, *w, *h), |ui| { if let Some(portrait) = publication_sheet(id, "portrait") { ui.label(egui::RichText::new(tl!("Portrait")).small().weak()); publication_style_buttons(app, ui, portrait); @@ -1259,7 +1259,7 @@ fn report_group(app: &mut RustGisApp, ui: &mut Ui) { ); menu_item(ui, app, "new_layout", "New Template (a layout page)", "report.newTemplate", Value::Null); let layouts: Vec = app.session.project.layouts.iter().map(|l| l.name.clone()).collect(); - ui.menu_button(tl!("Existing Template"), |ui| { + submenu_row(ui, "", tl!("Existing Template"), |ui| { for l in layouts { menu_item(ui, app, "", &l, "report.existingTemplate", json!({"layout": l})); } @@ -1275,7 +1275,7 @@ fn report_group(app: &mut RustGisApp, ui: &mut Ui) { .filter(|(j, _)| Some(*j) != active) .map(|(_, r)| r.name.clone()) .collect(); - ui.menu_button(tl!("Related Report"), |ui| { + submenu_row(ui, "", tl!("Related Report"), |ui| { if others.is_empty() { ui.label(egui::RichText::new(tl!("No other reports")).weak()); } @@ -1285,7 +1285,7 @@ fn report_group(app: &mut RustGisApp, ui: &mut Ui) { }); let rels: Vec = app.session.project.maps.iter().flat_map(|m| m.editing.relationships.iter().map(|r| r.name.clone())).collect(); - ui.menu_button(tl!("Subreport"), |ui| { + submenu_row(ui, "", tl!("Subreport"), |ui| { if rels.is_empty() { ui.label(egui::RichText::new(tl!("No relationships (Data Design › Relationships)")).weak()); } @@ -1308,7 +1308,7 @@ fn report_group(app: &mut RustGisApp, ui: &mut Ui) { .map(|l| l.dataset.fields.iter().map(|f| f.name.clone()).collect()) .unwrap_or_default(); let field_menu = |ui: &mut Ui, app: &mut RustGisApp, label: &str, id: &str, key: &str| { - ui.menu_button(tl!(label), |ui| { + submenu_row(ui, "", tl!(label), |ui| { for f in &fields { menu_item(ui, app, "", f, id, json!({key: f})); } @@ -1316,9 +1316,9 @@ fn report_group(app: &mut RustGisApp, ui: &mut Ui) { }; field_menu(ui, app, "Field", "report.field", "field"); menu_item(ui, app, "field", "Autofill Fields", "report.autofill", Value::Null); - ui.menu_button(tl!("Statistics"), |ui| { + submenu_row(ui, "", tl!("Statistics"), |ui| { for f in &fields { - ui.menu_button(f.as_str(), |ui| { + submenu_row(ui, "", f.as_str(), |ui| { for k in ["count", "sum", "mean", "min", "max"] { menu_item(ui, app, "", k, "report.statistics", json!({"field": f, "kind": k})); } @@ -1533,7 +1533,7 @@ fn graphics_and_text_group(app: &mut RustGisApp, ui: &mut Ui) { true, ); egui::Popup::menu(&resp).show(|ui| { - ui.set_min_width(200.0); + ui.set_min_width(crate::widgets::MENU_MIN_W); for &(token, what) in rustgis_engine::map::graphics::TOKENS { if ui.button(format!("{} {token}", tl!(what))).clicked() { app.map.cancel_sketch(); @@ -4712,7 +4712,7 @@ fn drawing_group(app: &mut RustGisApp, ui: &mut Ui, layer: &rustgis_engine::map: let _ = app.run("layer.symbology", json!({"type": "single"})); ui.close(); } - ui.menu_button(tl!("Unique Values"), |ui| { + submenu(ui, tl!("Unique Values"), |ui| { for f in &text_f { if ui.button(f).clicked() { let _ = app.run("layer.symbology", json!({"type": "unique", "field": f})); @@ -4720,7 +4720,7 @@ fn drawing_group(app: &mut RustGisApp, ui: &mut Ui, layer: &rustgis_engine::map: } } }); - ui.menu_button(tl!("Graduated Colors"), |ui| { + submenu(ui, tl!("Graduated Colors"), |ui| { for f in &numeric { if ui.button(f).clicked() { let _ = app.run("layer.symbology", json!({"type": "graduated", "field": f})); @@ -4729,7 +4729,7 @@ fn drawing_group(app: &mut RustGisApp, ui: &mut Ui, layer: &rustgis_engine::map: } }); if is_point { - ui.menu_button(tl!("Proportional Symbols"), |ui| { + submenu(ui, tl!("Proportional Symbols"), |ui| { for f in &numeric { if ui.button(f).clicked() { let _ = app.run("layer.symbology", json!({"type": "proportional", "field": f})); @@ -4953,7 +4953,7 @@ fn raster_style_groups(app: &mut RustGisApp, ui: &mut Ui) { } ui.separator(); for (key, label, slot) in [("red", "Red", 0usize), ("green", "Green", 1), ("blue", "Blue", 2)] { - ui.menu_button(tl!(label), |ui| { + submenu(ui, tl!(label), |ui| { for (i, b) in bands.iter().enumerate() { if ui .add(egui::Button::selectable( @@ -6502,6 +6502,42 @@ mod tests { assert!(l.elements.iter().all(|e| e.name != "Panel Box" && e.name != "Title"), "a figure, its title left to the caption"); } + /// A submenu of short rows (a sheet's styles) opens at least SUBMENU_MIN_W wide, not as a + /// strip, and the row opening it is as tall as the menu's other rows (#2398). + #[test] + fn a_submenu_of_short_rows_is_not_a_strip() { + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + ui.horizontal(|ui| project_group(app, ui)); + }, + cities(), + ); + h.run(); + h.get_by_label("New Layout").click(); + h.run(); + // A size is listed twice, New Layout's page and Publication Layout's sheet: the latter. + for row in ["Publication Layout", "Letter (216 × 279 mm)"] { + h.query_all_by_label(row).last().unwrap_or_else(|| panic!("{row}")).hover(); + h.run(); + } + // A menu's rows fill its width, so a style's row is as wide as the submenu: the least a + // submenu is, its styles being shorter. + let style = h.query_all_by_label("Panel").next().expect("the sheet's styles").rect(); + let least = crate::widgets::SUBMENU_MIN_W; + assert!((least - 1.0..least + 1.0).contains(&style.width()), "a style's row is {} px wide", style.width()); + // A row opening a submenu is as tall as the plain rows beside it. + let sheet = h.query_all_by_label("Letter (216 × 279 mm)").last().unwrap().rect(); + let figure = h.get_by_label("Journal figure, 1 column (90 mm)").rect(); + let (sheet, figure) = (sheet.height(), figure.height()); + assert!((sheet - figure).abs() < 0.5, "a sheet's row is {sheet} px tall, a figure's {figure}"); + } + #[test] fn saved_hidden_tabs_never_hide_the_fixed_tabs() { let saved = ["Settings", "Help", "Edit", "Share", "Edit"].iter().map(|t| t.to_string()).collect(); diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index ded2d2ea3..ac026d341 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -11,6 +11,13 @@ use crate::{RustGisApp, icons}; pub const CONTENT_H: f32 = 72.0; pub const LABEL_H: f32 = 18.0; +/// The least width of a ribbon button's menu. +pub const MENU_MIN_W: f32 = 200.0; + +/// The least width of a submenu, so one of short rows (a page size's styles) doesn't open as a +/// strip; narrower than a menu, whose rows have room for an icon and a shortcut (#2398). +pub const SUBMENU_MIN_W: f32 = 100.0; + /// A number its caller lends saved each frame and saves only once it is settled, kept across a /// drag (#597, #607). egui's `DragValue` keeps the value dragged so far in its own memory and /// forgets it when the pointer is released, a frame on which `dragged()` is false: lent the saved @@ -450,7 +457,7 @@ fn big_split_menu_with( let _ = app.run_by_user(id, params); } egui::Popup::menu(&arrow).close_behavior(close).show(|ui| { - ui.set_min_width(200.0); + ui.set_min_width(MENU_MIN_W); menu(ui, app); }); (primary, arrow) @@ -523,7 +530,7 @@ fn small_button( pub fn big_menu(ui: &mut Ui, app: &mut RustGisApp, icon: &str, label: &str, desc: &str, menu: impl FnOnce(&mut Ui, &mut RustGisApp)) { let resp = big(ui, app, icon, label, desc, "ui.menu", Value::Null, false, true); egui::Popup::menu(&resp).show(|ui| { - ui.set_min_width(200.0); + ui.set_min_width(MENU_MIN_W); menu(ui, app); }); } @@ -533,7 +540,7 @@ pub fn big_menu(ui: &mut Ui, app: &mut RustGisApp, icon: &str, label: &str, desc pub fn big_form_menu(ui: &mut Ui, app: &mut RustGisApp, icon: &str, label: &str, desc: &str, menu: impl FnOnce(&mut Ui, &mut RustGisApp)) { let resp = big(ui, app, icon, label, desc, "ui.menu", Value::Null, false, true); egui::Popup::menu(&resp).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { - ui.set_min_width(200.0); + ui.set_min_width(MENU_MIN_W); menu(ui, app); }); } @@ -576,7 +583,7 @@ fn small_menu_with( caret(ui.painter(), pos2(r.max.x - 9.0, r.center().y), t.text); let resp = tooltip(app, resp, label, desc, "ui.menu", &Value::Null); egui::Popup::menu(&resp).close_behavior(close).show(|ui| { - ui.set_min_width(200.0); + ui.set_min_width(MENU_MIN_W); menu(ui, app); }); } @@ -620,15 +627,29 @@ pub fn menu_row(ui: &mut Ui, icon: &str, label: &str, shortcut: &str, on: bool) resp } -/// A menu row with an icon that opens a submenu of `add`'s rows. +/// A menu row with an icon that opens a submenu of `add`'s rows, at least [`SUBMENU_MIN_W`] +/// wide: in a menu of [`menu_item`] rows, as tall as they are. pub fn submenu_row(ui: &mut Ui, icon: &str, label: &str, add: impl FnOnce(&mut Ui)) { let button = egui::Button::new(menu_text(ui, icon, label)) .min_size(vec2(0.0, 24.0)) .right_text(egui::containers::menu::SubMenuButton::arrow_atom(None)); - let (resp, _) = egui::containers::menu::SubMenuButton::from_button(button).ui(ui, add); + let (resp, _) = egui::containers::menu::SubMenuButton::from_button(button).ui(ui, |ui| { + ui.set_min_width(SUBMENU_MIN_W); + add(ui); + }); menu_icon(ui, &resp, icon); } +/// A row that opens a submenu of `add`'s rows, at least [`SUBMENU_MIN_W`] wide: in a menu of +/// plain buttons, as tall as they are (a menu of [`menu_item`] rows uses [`submenu_row`]). +pub fn submenu(ui: &mut Ui, label: &str, add: impl FnOnce(&mut Ui)) -> Response { + ui.menu_button(label, |ui| { + ui.set_min_width(SUBMENU_MIN_W); + add(ui); + }) + .response +} + /// A menu row's label: with an icon, it starts after it, so the icon is drawn inside the row (and the menu). fn menu_text(ui: &Ui, icon: &str, label: &str) -> egui::WidgetText { if icon.is_empty() { From af03b0b5371c6ac29417bc02ce0754de2f950e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 18 Nov 2026 09:45:49 -0500 Subject: [PATCH 2/2] test(ui): submenu width against the agreed 100 pt, and Report Section row heights (#2398) The Letter styles' submenu test asserts only a lower bound, written in the test rather than read from SUBMENU_MIN_W. A new test checks that Report Section's Existing Template row (submenu_row) is as tall as the New Template menu_item row beside it. --- crates/ui-egui/src/ribbon.rs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index b17cfe6e2..1cf0b1be0 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -6526,11 +6526,10 @@ mod tests { h.query_all_by_label(row).last().unwrap_or_else(|| panic!("{row}")).hover(); h.run(); } - // A menu's rows fill its width, so a style's row is as wide as the submenu: the least a - // submenu is, its styles being shorter. + // A menu's rows fill its width, so a style's row is as wide as the submenu: at least the + // 100 pt agreed in #2398 (written here, not read from the constant), less rounding. let style = h.query_all_by_label("Panel").next().expect("the sheet's styles").rect(); - let least = crate::widgets::SUBMENU_MIN_W; - assert!((least - 1.0..least + 1.0).contains(&style.width()), "a style's row is {} px wide", style.width()); + assert!(style.width() >= 99.5, "a style's row is {} px wide", style.width()); // A row opening a submenu is as tall as the plain rows beside it. let sheet = h.query_all_by_label("Letter (216 × 279 mm)").last().unwrap().rect(); let figure = h.get_by_label("Journal figure, 1 column (90 mm)").rect(); @@ -6538,6 +6537,30 @@ mod tests { assert!((sheet - figure).abs() < 0.5, "a sheet's row is {sheet} px tall, a figure's {figure}"); } + /// In a menu of `menu_item` rows (Report Section), the row opening a submenu is as tall as + /// the rows beside it (#2398). + #[test] + fn a_submenu_row_is_as_tall_as_the_menu_items_beside_it() { + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + ui.horizontal(|ui| report_group(app, ui)); + }, + cities(), + ); + h.run(); + h.get_by_label("Report Section").click(); + h.run(); + let opener = h.get_by_label("Existing Template").rect().height(); + let item = h.get_by_label("New Template (a layout page)").rect().height(); + assert!((opener - item).abs() < 0.5, "Existing Template is {opener} px tall, New Template {item}"); + } + #[test] fn saved_hidden_tabs_never_hide_the_fixed_tabs() { let saved = ["Settings", "Help", "Edit", "Share", "Edit"].iter().map(|t| t.to_string()).collect();