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

I think this broke with the sizing pass
This commit is contained in:
Emil Ernerfeldt 2024-05-31 15:56:52 +02:00 committed by GitHub
parent d3ea90f5ef
commit 86560554bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 1 deletions

View File

@ -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())
@ -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
}