From 690c3ba883efe6e3890f59f4ea40a25e7a9e963b Mon Sep 17 00:00:00 2001 From: Alexander Parlett Date: Sun, 21 Apr 2024 10:44:44 +0100 Subject: [PATCH] Use parent `Ui`s style for popups (#4325) * Closes --------- Co-authored-by: Alex Parlett --- .gitignore | 1 + crates/egui/src/containers/popup.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index c43b95594..7db0b9d06 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /.*.json /.vscode /media/* +.idea/ diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 99165149f..9643a8eee 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -333,13 +333,13 @@ pub fn popup_below_widget( /// # }); /// ``` pub fn popup_above_or_below_widget( - ui: &Ui, + parent_ui: &Ui, popup_id: Id, widget_response: &Response, above_or_below: AboveOrBelow, add_contents: impl FnOnce(&mut Ui) -> R, ) -> Option { - if ui.memory(|mem| mem.is_popup_open(popup_id)) { + if parent_ui.memory(|mem| mem.is_popup_open(popup_id)) { let (pos, pivot) = match above_or_below { AboveOrBelow::Above => (widget_response.rect.left_top(), Align2::LEFT_BOTTOM), AboveOrBelow::Below => (widget_response.rect.left_bottom(), Align2::LEFT_TOP), @@ -350,8 +350,8 @@ pub fn popup_above_or_below_widget( .constrain(true) .fixed_pos(pos) .pivot(pivot) - .show(ui.ctx(), |ui| { - let frame = Frame::popup(ui.style()); + .show(parent_ui.ctx(), |ui| { + let frame = Frame::popup(parent_ui.style()); let frame_margin = frame.total_margin(); frame .show(ui, |ui| { @@ -365,8 +365,8 @@ pub fn popup_above_or_below_widget( }) .inner; - if ui.input(|i| i.key_pressed(Key::Escape)) || widget_response.clicked_elsewhere() { - ui.memory_mut(|mem| mem.close_popup()); + if parent_ui.input(|i| i.key_pressed(Key::Escape)) || widget_response.clicked_elsewhere() { + parent_ui.memory_mut(|mem| mem.close_popup()); } Some(inner) } else {