Use parent `Ui`s style for popups (#4325)
* Closes <https://github.com/emilk/egui/issues/4324> --------- Co-authored-by: Alex Parlett <alexparlett@Alexs-MacBook-Air.local>
This commit is contained in:
parent
5f9c17c855
commit
690c3ba883
|
@ -5,3 +5,4 @@
|
||||||
/.*.json
|
/.*.json
|
||||||
/.vscode
|
/.vscode
|
||||||
/media/*
|
/media/*
|
||||||
|
.idea/
|
||||||
|
|
|
@ -333,13 +333,13 @@ pub fn popup_below_widget<R>(
|
||||||
/// # });
|
/// # });
|
||||||
/// ```
|
/// ```
|
||||||
pub fn popup_above_or_below_widget<R>(
|
pub fn popup_above_or_below_widget<R>(
|
||||||
ui: &Ui,
|
parent_ui: &Ui,
|
||||||
popup_id: Id,
|
popup_id: Id,
|
||||||
widget_response: &Response,
|
widget_response: &Response,
|
||||||
above_or_below: AboveOrBelow,
|
above_or_below: AboveOrBelow,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> Option<R> {
|
) -> Option<R> {
|
||||||
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 {
|
let (pos, pivot) = match above_or_below {
|
||||||
AboveOrBelow::Above => (widget_response.rect.left_top(), Align2::LEFT_BOTTOM),
|
AboveOrBelow::Above => (widget_response.rect.left_top(), Align2::LEFT_BOTTOM),
|
||||||
AboveOrBelow::Below => (widget_response.rect.left_bottom(), Align2::LEFT_TOP),
|
AboveOrBelow::Below => (widget_response.rect.left_bottom(), Align2::LEFT_TOP),
|
||||||
|
@ -350,8 +350,8 @@ pub fn popup_above_or_below_widget<R>(
|
||||||
.constrain(true)
|
.constrain(true)
|
||||||
.fixed_pos(pos)
|
.fixed_pos(pos)
|
||||||
.pivot(pivot)
|
.pivot(pivot)
|
||||||
.show(ui.ctx(), |ui| {
|
.show(parent_ui.ctx(), |ui| {
|
||||||
let frame = Frame::popup(ui.style());
|
let frame = Frame::popup(parent_ui.style());
|
||||||
let frame_margin = frame.total_margin();
|
let frame_margin = frame.total_margin();
|
||||||
frame
|
frame
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
|
@ -365,8 +365,8 @@ pub fn popup_above_or_below_widget<R>(
|
||||||
})
|
})
|
||||||
.inner;
|
.inner;
|
||||||
|
|
||||||
if ui.input(|i| i.key_pressed(Key::Escape)) || widget_response.clicked_elsewhere() {
|
if parent_ui.input(|i| i.key_pressed(Key::Escape)) || widget_response.clicked_elsewhere() {
|
||||||
ui.memory_mut(|mem| mem.close_popup());
|
parent_ui.memory_mut(|mem| mem.close_popup());
|
||||||
}
|
}
|
||||||
Some(inner)
|
Some(inner)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue