diff --git a/crates/egui/src/menu.rs b/crates/egui/src/menu.rs index 36d12497de6..607b9495a77 100644 --- a/crates/egui/src/menu.rs +++ b/crates/egui/src/menu.rs @@ -151,20 +151,22 @@ pub(crate) fn menu_ui<'c, R>( .constrain_to(ctx.screen_rect()) .interactable(true); - area.show(ctx, |ui| { + let area_response = area.show(ctx, |ui| { set_menu_style(ui.style_mut()); - let frame = Frame::menu(ui.style()).show(ui, |ui| { - ui.set_max_width(ui.spacing().menu_width); - ui.set_menu_state(Some(menu_state_arc.clone())); - ui.with_layout(Layout::top_down_justified(Align::LEFT), add_contents) - .inner - }); + Frame::menu(ui.style()) + .show(ui, |ui| { + ui.set_max_width(ui.spacing().menu_width); + ui.set_menu_state(Some(menu_state_arc.clone())); + ui.with_layout(Layout::top_down_justified(Align::LEFT), add_contents) + .inner + }) + .inner + }); - menu_state_arc.write().rect = frame.response.rect; + menu_state_arc.write().rect = area_response.response.rect; - frame.inner - }) + area_response } /// Build a top level menu with a button. @@ -549,7 +551,8 @@ pub(crate) struct MenuState { /// The opened sub-menu and its [`Id`] sub_menu: Option<(Id, Arc>)>, - /// Bounding box of this menu (without the sub-menu) + /// Bounding box of this menu (without the sub-menu), + /// including the frame and everything. pub rect: Rect, /// Used to check if any menu in the tree wants to close @@ -620,7 +623,8 @@ impl MenuState { // ensure to repaint once even when pointer is not moving ui.ctx().request_repaint(); } else if !open && button.hovered() { - let pos = button.rect.right_top(); + let mut pos = button.rect.right_top(); + pos.x = self.rect.right() + ui.spacing().menu_spacing; self.open_submenu(sub_id, pos); } else if open && ui.interact_bg(Sense::hover()).contains_pointer() diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 54e6ab26feb..651ad26930c 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -311,6 +311,9 @@ pub struct Spacing { /// The default width of a menu. pub menu_width: f32, + /// Horizontal distance between a menu and a submenu. + pub menu_spacing: f32, + /// End indented regions with a horizontal line pub indent_ends_with_horizontal_line: bool, @@ -1239,6 +1242,7 @@ impl Default for Spacing { icon_spacing: 4.0, tooltip_width: 600.0, menu_width: 150.0, + menu_spacing: 3.0, combo_height: 200.0, scroll: Default::default(), indent_ends_with_horizontal_line: false, @@ -1592,6 +1596,7 @@ impl Spacing { icon_spacing, tooltip_width, menu_width, + menu_spacing, indent_ends_with_horizontal_line, combo_height, scroll, @@ -1659,6 +1664,11 @@ impl Spacing { ui.label("Default width of a menu"); }); + ui.horizontal(|ui| { + ui.add(DragValue::new(menu_spacing).clamp_range(0.0..=10.0)); + ui.label("Horizontal spacing between menus"); + }); + ui.checkbox( indent_ends_with_horizontal_line, "End indented regions with a horizontal separator",