From 77df9cb9820e964af055aa54114b4da1d2d31976 Mon Sep 17 00:00:00 2001 From: hats-np <124705253+hats-np@users.noreply.github.com> Date: Tue, 18 Apr 2023 15:07:24 +0100 Subject: [PATCH] Menu State rect now uses menu frame rect instead of contents rect, as their position goes out of bounds. (#2886) --- crates/egui/src/menu.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/egui/src/menu.rs b/crates/egui/src/menu.rs index 4fa2d3c2..5e27e953 100644 --- a/crates/egui/src/menu.rs +++ b/crates/egui/src/menu.rs @@ -147,21 +147,22 @@ pub(crate) fn menu_ui<'c, R>( .fixed_pos(pos) .interactable(true) .drag_bounds(ctx.screen_rect()); - let inner_response = area.show(ctx, |ui| { + + area.show(ctx, |ui| { set_menu_style(ui.style_mut()); - Frame::menu(ui.style()) - .show(ui, |ui| { - const DEFAULT_MENU_WIDTH: f32 = 150.0; // TODO(emilk): add to ui.spacing - ui.set_max_width(DEFAULT_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 = inner_response.response.rect; - inner_response + let frame = Frame::menu(ui.style()).show(ui, |ui| { + const DEFAULT_MENU_WIDTH: f32 = 150.0; // TODO(emilk): add to ui.spacing + ui.set_max_width(DEFAULT_MENU_WIDTH); + ui.set_menu_state(Some(menu_state_arc.clone())); + ui.with_layout(Layout::top_down_justified(Align::LEFT), add_contents) + .inner + }); + + menu_state_arc.write().rect = frame.response.rect; + + frame.inner + }) } /// Build a top level menu with a button. @@ -293,8 +294,7 @@ impl MenuRoot { if self.id == response.id { let inner_response = MenuState::show(&response.ctx, &self.menu_state, self.id, add_contents); - let mut menu_state = self.menu_state.write(); - menu_state.rect = inner_response.response.rect; + let menu_state = self.menu_state.read(); if menu_state.response.is_close() { return (MenuResponse::Close, Some(inner_response));