-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
⚠️ Improved menu based on egui::Popup
#5716
Conversation
Preview available at https://egui-pr-preview.github.io/pr/5716-lucaspopup-based-menu |
e6cf98d
to
0109e35
Compare
0109e35
to
b9c1a1f
Compare
egui::Popup
egui::Popup
…enu and deprecate old menu
# Conflicts: # crates/egui/src/containers/popup.rs # crates/egui/src/containers/window.rs # crates/egui/src/response.rs # crates/egui/src/ui.rs # crates/egui/src/ui_builder.rs # crates/egui_demo_lib/src/demo/context_menu.rs # crates/egui_demo_lib/src/demo/demo_app_windows.rs # crates/egui_demo_lib/src/demo/popups.rs
@@ -374,6 +374,7 @@ fn combo_box_dyn<'c, R>( | |||
|
|||
let inner = Popup::menu(&button_response) | |||
.id(popup_id) | |||
.style(None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we set the menu styles for the ComboBox? I'm overwriting this here since this is how it was before, but I think the menu styles would look nice here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question 🤔 If so I think we save it for another PR
ui.hyperlink_to( | ||
egui::RichText::new("🦋").size(font_size), | ||
"https://bsky.app/profile/ernerfeldt.bsky.social", | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You just have to wait for🐛...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this would be a fun way to display the options, but it seems like the readability suffers a bit. Should I change it?
…as/popup-based-menu
What happens if you also call |
Add reset button to demo |
Add some note that ui.close doesnt bubble up across areas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the default behavior is CloseOnClick
, then we can remove the calls to ui.close()
from
egui/crates/egui_demo_lib/src/demo/demo_app_windows.rs
Lines 308 to 363 in ab0f83d
fn file_menu_button(ui: &mut Ui) { | |
let organize_shortcut = | |
egui::KeyboardShortcut::new(Modifiers::CTRL | Modifiers::SHIFT, egui::Key::O); | |
let reset_shortcut = | |
egui::KeyboardShortcut::new(Modifiers::CTRL | Modifiers::SHIFT, egui::Key::R); | |
// NOTE: we must check the shortcuts OUTSIDE of the actual "File" menu, | |
// or else they would only be checked if the "File" menu was actually open! | |
if ui.input_mut(|i| i.consume_shortcut(&organize_shortcut)) { | |
ui.ctx().memory_mut(|mem| mem.reset_areas()); | |
} | |
if ui.input_mut(|i| i.consume_shortcut(&reset_shortcut)) { | |
ui.ctx().memory_mut(|mem| *mem = Default::default()); | |
} | |
ui.menu_button("File", |ui| { | |
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend); | |
// On the web the browser controls the zoom | |
#[cfg(not(target_arch = "wasm32"))] | |
{ | |
egui::gui_zoom::zoom_menu_buttons(ui); | |
ui.weak(format!( | |
"Current zoom: {:.0}%", | |
100.0 * ui.ctx().zoom_factor() | |
)) | |
.on_hover_text("The UI zoom level, on top of the operating system's default value"); | |
ui.separator(); | |
} | |
if ui | |
.add( | |
egui::Button::new("Organize Windows") | |
.shortcut_text(ui.ctx().format_shortcut(&organize_shortcut)), | |
) | |
.clicked() | |
{ | |
ui.ctx().memory_mut(|mem| mem.reset_areas()); | |
ui.close(); | |
} | |
if ui | |
.add( | |
egui::Button::new("Reset egui memory") | |
.shortcut_text(ui.ctx().format_shortcut(&reset_shortcut)), | |
) | |
.on_hover_text("Forget scroll, positions, sizes etc") | |
.clicked() | |
{ | |
ui.ctx().memory_mut(|mem| *mem = Default::default()); | |
ui.close(); | |
} | |
}); | |
} |
@@ -374,6 +374,7 @@ fn combo_box_dyn<'c, R>( | |||
|
|||
let inner = Popup::menu(&button_response) | |||
.id(popup_id) | |||
.style(None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question 🤔 If so I think we save it for another PR
/// Show some text on the right side of the button. | ||
#[inline] | ||
pub fn right_text(mut self, right_text: impl Into<WidgetText>) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this was broken out to its own PR it would get its own entry in the changelog 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioned it in the PR description, hopefully that is enough to remember to add this to the changelog during the release
… Never close menu when clicking submenu buttons. Add tests.
8c9b953
to
a312478
Compare
@crumblingstatue good catch. I want to support opening multiple/nested popups which should fix this. But I'll implement that in a separate PR, since this one is already so big. |
Continuation of #5713
Silently breaking changes:
PopupCloseBehavior
Additional additions:
Button::right_text
StyleModifier
This is a rewrite of the egui menus, with the following goals:
proper support for keyboard navigationPopupCloseBehavior