diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 4c9589c72..c9d0012ef 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -998,6 +998,8 @@ mod glow_integration { .unwrap(), ); + integration.egui_ctx.set_current_window_id(win.window_id); + let screen_size_in_pixels: [u32; 2] = window.inner_size().into(); egui_glow::painter::clear( diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 739b672dd..de2281f89 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -161,6 +161,7 @@ struct ContextImpl { repaint: Repaint, windows: HashMap, + window_counter: u64, current_window_id: u64, /// Written to during the frame. @@ -1268,11 +1269,14 @@ impl Context { let repaint_after = self.write(|ctx| ctx.repaint.end_frame()); let shapes = self.drain_paint_lists(); - let windows = self.read(|ctx| { - ctx.windows - .iter() - .map(|(_, (builder, id, _))| (*id, builder.clone())) - .collect() + let mut windows = Vec::new(); + self.write(|ctx| { + ctx.windows.retain(|d, (builder, id, used)| { + let out = *used; + *used = false; + windows.push((*id, builder.clone())); + out + }) }); FullOutput { @@ -1897,10 +1901,12 @@ impl Context { pub fn create_window(&self, window_builder: WindowBuilder) -> u64 { 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 } else { - let id = ctx.windows.len() as u64 + 1; + let id = ctx.window_counter + 1; + ctx.window_counter = id; ctx.windows .insert(window_builder.title.clone(), (window_builder, id, true)); id diff --git a/examples/hello_world_simple/src/main.rs b/examples/hello_world_simple/src/main.rs index b2eeb94ed..fe29ed2ff 100644 --- a/examples/hello_world_simple/src/main.rs +++ b/examples/hello_world_simple/src/main.rs @@ -27,8 +27,11 @@ fn main() -> Result<(), eframe::Error> { age += 1; } ui.label(format!("Hello '{name}', age {age}")); - egui::CollapsingHeader::new("W").show(ui, |ui| { - egui::Window::new("Win").show(ctx, |ui| ui.label("Inside a window!")); + egui::CollapsingHeader::new("Show Test1").show(ui, |ui| { + 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")); }); }); })