Repository navigation
feat(ui): submenus open at least 100 px wide, their rows as tall as the menu's (#2398) #2400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
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 | ||
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scope not stated (AGENTS.md: "Reach every surface"). |
||
| 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 { | ||
|
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() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.