mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 15:13:12 -04:00
Now window will be destroyed if is not rendered
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -161,6 +161,7 @@ struct ContextImpl {
|
||||
repaint: Repaint,
|
||||
|
||||
windows: HashMap<String, (WindowBuilder, u64, bool)>,
|
||||
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
|
||||
|
||||
@@ -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"));
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user