Skip to content
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

Menu State rect now uses menu frame rect instead of contents rect. #2886

Merged
merged 1 commit into from
Apr 18, 2023
Merged
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
30 changes: 15 additions & 15 deletions crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
Expand Down