Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions crates/ui-egui/src/panes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,15 +1700,14 @@ 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()})));
ui.close();
}
}
})
.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() {
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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"}));
Expand All @@ -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}));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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}));
Expand Down
87 changes: 73 additions & 14 deletions crates/ui-egui/src/ribbon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<String> = 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| {
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
for l in layouts {
menu_item(ui, app, "", &l, "report.existingTemplate", json!({"layout": l}));
}
Expand All @@ -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());
}
Expand All @@ -1285,7 +1285,7 @@ fn report_group(app: &mut RustGisApp, ui: &mut Ui) {
});
let rels: Vec<String> =
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());
}
Expand All @@ -1308,17 +1308,17 @@ 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}));
}
});
};
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}));
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -4712,15 +4712,15 @@ 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}));
ui.close();
}
}
});
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}));
Expand All @@ -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}));
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -6502,6 +6502,65 @@ 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: 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();
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();
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}");
}

/// 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();
Expand Down
33 changes: 27 additions & 6 deletions crates/ui-egui/src/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

/// 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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
});
}
Expand All @@ -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);
});
}
Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope not stated (AGENTS.md: "Reach every surface"). submenu_row is a shared helper, so this SUBMENU_MIN_W floor also reaches callers the PR description doesn't list: mapmenu.rs:173 (Quick Analysis in the map's right-click menu), ribbon.rs:518 (New Connection), ribbon.rs:685 and :688 (France, United States), and ribbon.rs:3635 (plugin submenus). Their rows are probably wider than 100 pt, so the visible effect is likely small, but the PR should say so and show one of them in the before/after screenshots. Confidence: moderate.

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 {
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
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() {
Expand Down
Loading