1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Now window will be destroyed if is not rendered

This commit is contained in:
Konkitoman
2023-07-18 17:52:55 +03:00
parent 8f475ef8d8
commit 28d5c6e62c
3 changed files with 20 additions and 9 deletions

View File

@@ -998,6 +998,8 @@ mod glow_integration {
.unwrap(), .unwrap(),
); );
integration.egui_ctx.set_current_window_id(win.window_id);
let screen_size_in_pixels: [u32; 2] = window.inner_size().into(); let screen_size_in_pixels: [u32; 2] = window.inner_size().into();
egui_glow::painter::clear( egui_glow::painter::clear(

View File

@@ -161,6 +161,7 @@ struct ContextImpl {
repaint: Repaint, repaint: Repaint,
windows: HashMap<String, (WindowBuilder, u64, bool)>, windows: HashMap<String, (WindowBuilder, u64, bool)>,
window_counter: u64,
current_window_id: u64, current_window_id: u64,
/// Written to during the frame. /// Written to during the frame.
@@ -1268,11 +1269,14 @@ impl Context {
let repaint_after = self.write(|ctx| ctx.repaint.end_frame()); let repaint_after = self.write(|ctx| ctx.repaint.end_frame());
let shapes = self.drain_paint_lists(); let shapes = self.drain_paint_lists();
let windows = self.read(|ctx| { let mut windows = Vec::new();
ctx.windows self.write(|ctx| {
.iter() ctx.windows.retain(|d, (builder, id, used)| {
.map(|(_, (builder, id, _))| (*id, builder.clone())) let out = *used;
.collect() *used = false;
windows.push((*id, builder.clone()));
out
})
}); });
FullOutput { FullOutput {
@@ -1897,10 +1901,12 @@ impl Context {
pub fn create_window(&self, window_builder: WindowBuilder) -> u64 { pub fn create_window(&self, window_builder: WindowBuilder) -> u64 {
self.write(|ctx| { self.write(|ctx| {
if let Some(window) = ctx.windows.get(&window_builder.title) { if let Some(window) = ctx.windows.get_mut(&window_builder.title) {
window.2 = true;
window.1 window.1
} else { } else {
let id = ctx.windows.len() as u64 + 1; let id = ctx.window_counter + 1;
ctx.window_counter = id;
ctx.windows ctx.windows
.insert(window_builder.title.clone(), (window_builder, id, true)); .insert(window_builder.title.clone(), (window_builder, id, true));
id id

View File

@@ -27,8 +27,11 @@ fn main() -> Result<(), eframe::Error> {
age += 1; age += 1;
} }
ui.label(format!("Hello '{name}', age {age}")); ui.label(format!("Hello '{name}', age {age}"));
egui::CollapsingHeader::new("W").show(ui, |ui| { egui::CollapsingHeader::new("Show Test1").show(ui, |ui| {
egui::Window::new("Win").show(ctx, |ui| ui.label("Inside a window!")); egui::Window::new("Test1").show(ctx, |ui| ui.label("Inside a window!"));
});
egui::CollapsingHeader::new("Shout Test2").show(ui, |ui| {
egui::Window::new("Test2").show(ctx, |ui| ui.label("Inside a window! 222"));
}); });
}); });
}) })