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

Fix bug in context menu positioning when at bottom of the screen #4593

Merged
merged 1 commit into from
May 31, 2024
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
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
Loading