Menu State rect now uses menu frame rect instead of contents rect, as their position goes out of bounds. (#2886)

This commit is contained in:
hats-np 2023-04-18 15:07:24 +01:00 committed by GitHub
parent 33aa4d698f
commit 77df9cb982
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 15 deletions

View File

@ -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));