Skip to content

Commit

Permalink
Fix bug in context menu positioning when at bottom of the screen (#4593)
Browse files Browse the repository at this point in the history
I think this broke with the sizing pass
  • Loading branch information
emilk authored May 31, 2024
1 parent d3ea90f commit 8656055
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ fn menu_popup<'c, R>(
.default_width(ctx.style().spacing.menu_width)
.sense(Sense::hover());

let mut sizing_pass = false;

let area_response = area.show(ctx, |ui| {
sizing_pass = ui.is_sizing_pass();

set_menu_style(ui.style_mut());

Frame::menu(ui.style())
Expand All @@ -164,7 +168,16 @@ fn menu_popup<'c, R>(
.inner
});

menu_state_arc.write().rect = area_response.response.rect;
menu_state_arc.write().rect = if sizing_pass {
// During the sizing pass we didn't know the size yet,
// so we might have just constrained the position unnecessarily.
// Therefore keep the original=desired position until the next frame.
Rect::from_min_size(pos, area_response.response.rect.size())
} else {
// We knew the size, and this is where it ended up (potentially constrained to screen).
// Remember it for the future:
area_response.response.rect
};

area_response
}
Expand Down

0 comments on commit 8656055

Please sign in to comment.