Repository navigation
Replies: 2 comments
|
One useful test is to explicitly request a repaint of the root viewport after changing the flag: if ui.button("Close").clicked() {
show_child.store(false, Ordering::Relaxed);
ui.ctx().request_repaint_of(egui::ViewportId::ROOT);
}The atomic store updates your state, but doesn't itself schedule the parent UI. In egui 0.36.2, Also, I haven't reproduced the RHEL/Wayland occlusion case, so I'd treat this as a diagnostic rather than a confirmed compositor workaround. If logging at the start of |
|
Thank you for you answer. I updated the example according to your suggestion (updated code below). Unfortunately the window still does not close. I found out that if I press the Close button quickly it seems to work. If I leave the deferred viewport open for a few seconds, then it does not close anymore. In this case the root viewport is obviously never repainted, even if requested explicitly. If the root viewport is partially visible, it always works. use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
};
use eframe::egui;
fn main() -> eframe::Result {
let native_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_title("Root Viewport")
.with_inner_size([200.0, 200.0]),
..Default::default()
};
eframe::run_native(
"egui-deferred-viewport-close",
native_options,
Box::new(|_creation_context| Ok(Box::new(MyApp::default()))),
)
}
struct MyApp {
show_child: Arc<AtomicBool>,
}
impl Default for MyApp {
fn default() -> Self {
Self {
show_child: Arc::new(AtomicBool::new(false)),
}
}
}
impl eframe::App for MyApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ui, |ui| {
ui.heading("Root Viewport");
ui.add_space(10.0);
if ui.button("Open Deferred Viewport").clicked() {
self.show_child.store(true, Ordering::Relaxed);
}
});
if self.show_child.load(Ordering::Relaxed) {
let show_child = self.show_child.clone();
ui.ctx().show_viewport_deferred(
egui::ViewportId::from_hash_of("deferred-child"),
egui::ViewportBuilder::default()
.with_title("Deferred Child Viewport")
.with_inner_size([600.0, 600.0])
.with_decorations(false)
,
move |ui, _| {
egui::CentralPanel::default().show(ui, |ui| {
ui.heading("Deferred child viewport");
ui.add_space(10.0);
if ui.button("Close").clicked() {
println!("close button clicked");
show_child.store(false, Ordering::Relaxed);
ui.ctx().request_repaint_of(egui::ViewportId::ROOT);
}
});
},
);
}
}
} |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I want to close a deferred viewport, but it does not reach the main application ui loop, because it is not redrawn when completely obscured. See minimal example below.
When wanting to close I both
but most of the times it does not work.
I am working on a native Linux application on Red Hat 10 with Wayland. Using egui 0.36.2.
Grateful for any hints,
Thanks
main.rs
All reactions