diff --git a/crates/eframe/src/epi/mod.rs b/crates/eframe/src/epi/mod.rs index 0f6f42290..3b931ceeb 100644 --- a/crates/eframe/src/epi/mod.rs +++ b/crates/eframe/src/epi/mod.rs @@ -9,6 +9,7 @@ #[cfg(not(target_arch = "wasm32"))] mod icon_data; +use egui::ViewportRender; #[cfg(not(target_arch = "wasm32"))] pub use icon_data::IconData; @@ -112,7 +113,12 @@ pub trait App { /// The [`egui::Context`] can be cloned and saved if you like. /// /// To force a repaint, call [`egui::Context::request_repaint`] at any time (e.g. from another thread). - fn update(&mut self, ctx: &egui::Context, frame: &mut Frame); + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut Frame, + render_function: Option<&ViewportRender>, + ); /// Get a handle to the app. /// @@ -774,6 +780,22 @@ impl Frame { self.info.clone() } + /// If this is the main window will return true! + /// When is a single window mode will always return true! + pub fn is_main_window(&self) -> bool { + self.info.viewport_id == 0 + } + + /// Returns the current viewport id + pub fn viewport_id(&self) -> u64 { + self.info.viewport_id + } + + /// Returns the current viewport parent id + pub fn parent_viewport_id(&self) -> u64 { + self.info.parent_viewport + } + /// A place where you can store custom data in a way that persists when you restart the app. pub fn storage(&self) -> Option<&dyn Storage> { self.storage.as_deref() @@ -1125,6 +1147,9 @@ pub struct IntegrationInfo { /// The OS native pixels-per-point pub native_pixels_per_point: Option, + pub viewport_id: u64, + pub parent_viewport: u64, + /// The position and size of the native window. #[cfg(not(target_arch = "wasm32"))] pub window_info: WindowInfo, diff --git a/crates/eframe/src/lib.rs b/crates/eframe/src/lib.rs index afa602cc9..e682b537b 100644 --- a/crates/eframe/src/lib.rs +++ b/crates/eframe/src/lib.rs @@ -273,8 +273,17 @@ pub fn run_simple_native( update_fun: U, } impl App for SimpleApp { - fn update(&mut self, ctx: &egui::Context, frame: &mut Frame) { - (self.update_fun)(ctx, frame); + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut Frame, + render_function: Option<&(dyn Fn(&egui::Context, u64, u64) + Send + Sync)>, + ) { + if frame.is_main_window() { + (self.update_fun)(ctx, frame); + } else if let Some(render_function) = render_function { + render_function(ctx, frame.viewport_id(), frame.parent_viewport_id()) + } } } diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 0db9b7b30..dd631621e 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -369,6 +369,8 @@ impl EpiIntegration { cpu_usage: None, native_pixels_per_point: Some(native_pixels_per_point), window_info: read_window_info(window, egui_ctx.pixels_per_point(), &window_state), + viewport_id: 0, + parent_viewport: 0, }, output: epi::backend::AppOutput { visible: Some(true), @@ -509,6 +511,8 @@ impl EpiIntegration { read_window_info(window, self.egui_ctx.pixels_per_point(), &self.window_state); let mut raw_input = egui_winit.take_egui_input(window); raw_input.time = Some(self.beagining.elapsed().as_secs_f64()); + self.frame.info.viewport_id = viewport_id; + self.frame.info.parent_viewport = parent_id; // Run user code: let full_output = self.egui_ctx.run(raw_input, |egui_ctx| { @@ -516,7 +520,7 @@ impl EpiIntegration { if let Some(render) = render { (render.as_ref())(egui_ctx, viewport_id, parent_id) } else { - app.update(egui_ctx, &mut self.frame); + app.update(egui_ctx, &mut self.frame, render.as_ref().map(|r| &***r)); } }); diff --git a/crates/egui/src/lib.rs b/crates/egui/src/lib.rs index f7eef71a9..05e83fdf4 100644 --- a/crates/egui/src/lib.rs +++ b/crates/egui/src/lib.rs @@ -546,6 +546,9 @@ pub enum WidgetType { Other, } +/// This is used to render a viewport +pub type ViewportRender = dyn Fn(&Context, u64, u64) + Sync + Send; + // ---------------------------------------------------------------------------- /// For use in tests; especially doctests. diff --git a/crates/egui_demo_app/src/apps/custom3d_glow.rs b/crates/egui_demo_app/src/apps/custom3d_glow.rs index ff545bb61..d1bddc736 100644 --- a/crates/egui_demo_app/src/apps/custom3d_glow.rs +++ b/crates/egui_demo_app/src/apps/custom3d_glow.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use eframe::egui_glow; -use egui::mutex::Mutex; +use egui::{mutex::Mutex, ViewportRender}; use egui_glow::glow; pub struct Custom3d { @@ -21,7 +21,16 @@ impl Custom3d { } impl eframe::App for Custom3d { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { egui::ScrollArea::both() .auto_shrink([false; 2]) diff --git a/crates/egui_demo_app/src/wrap_app.rs b/crates/egui_demo_app/src/wrap_app.rs index 6cb425bf9..ab3c97661 100644 --- a/crates/egui_demo_app/src/wrap_app.rs +++ b/crates/egui_demo_app/src/wrap_app.rs @@ -1,3 +1,4 @@ +use egui::ViewportRender; use egui_demo_lib::is_mobile; #[cfg(feature = "glow")] @@ -14,7 +15,16 @@ struct EasyMarkApp { } impl eframe::App for EasyMarkApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } self.editor.panels(ctx); } } @@ -28,7 +38,16 @@ pub struct DemoApp { } impl eframe::App for DemoApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } self.demo_windows.ui(ctx); } } @@ -42,7 +61,16 @@ pub struct FractalClockApp { } impl eframe::App for FractalClockApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default() .frame(egui::Frame::dark_canvas(&ctx.style())) .show(ctx, |ui| { @@ -61,7 +89,16 @@ pub struct ColorTestApp { } impl eframe::App for ColorTestApp { - fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { if frame.is_web() { ui.label( @@ -227,7 +264,16 @@ impl eframe::App for WrapApp { visuals.panel_fill.to_normalized_gamma_f32() } - fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } #[cfg(target_arch = "wasm32")] if let Some(anchor) = frame.info().web_info.location.hash.strip_prefix('#') { let anchor = Anchor::all().into_iter().find(|x| x.to_string() == anchor); @@ -255,7 +301,7 @@ impl eframe::App for WrapApp { self.backend_panel(ctx, frame); } - self.show_selected_app(ctx, frame); + self.show_selected_app(ctx, frame, render); self.state.backend_panel.end_of_frame(ctx); @@ -322,11 +368,16 @@ impl WrapApp { }); } - fn show_selected_app(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + fn show_selected_app( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { let selected_anchor = self.state.selected_anchor; for (_name, anchor, app) in self.apps_iter_mut() { if anchor == selected_anchor || ctx.memory(|mem| mem.everything_is_visible()) { - app.update(ctx, frame); + app.update(ctx, frame, render); } } } diff --git a/examples/confirm_exit/src/main.rs b/examples/confirm_exit/src/main.rs index 9c115fdbb..88b01d2c4 100644 --- a/examples/confirm_exit/src/main.rs +++ b/examples/confirm_exit/src/main.rs @@ -2,7 +2,7 @@ use std::sync::{Arc, RwLock}; -use eframe::egui; +use eframe::egui::{self, ViewportRender}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -34,7 +34,16 @@ impl eframe::App for MyApp { self.data.read().unwrap().allowed_to_close } - fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { ui.heading("Try to close the window"); }); diff --git a/examples/custom_3d_glow/src/main.rs b/examples/custom_3d_glow/src/main.rs index f72859d23..b92f1faf4 100644 --- a/examples/custom_3d_glow/src/main.rs +++ b/examples/custom_3d_glow/src/main.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![allow(unsafe_code)] -use eframe::egui; +use eframe::egui::{self, ViewportRender}; use egui::mutex::Mutex; use std::sync::Arc; @@ -41,7 +41,16 @@ impl MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 0.0; diff --git a/examples/custom_font/src/main.rs b/examples/custom_font/src/main.rs index bc84223b2..4861ade24 100644 --- a/examples/custom_font/src/main.rs +++ b/examples/custom_font/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui; +use eframe::egui::{self, ViewportRender}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -60,7 +60,16 @@ impl MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { ui.heading("egui using custom fonts"); ui.text_edit_multiline(&mut self.text); diff --git a/examples/custom_font_style/src/main.rs b/examples/custom_font_style/src/main.rs index 89117b4f0..b44775e3c 100644 --- a/examples/custom_font_style/src/main.rs +++ b/examples/custom_font_style/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui; +use eframe::egui::{self, ViewportRender}; use egui::{FontFamily, FontId, RichText, TextStyle}; fn main() -> Result<(), eframe::Error> { @@ -64,7 +64,16 @@ impl MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, content); } } diff --git a/examples/custom_window_frame/src/main.rs b/examples/custom_window_frame/src/main.rs index 8ea32fbf7..352269e17 100644 --- a/examples/custom_window_frame/src/main.rs +++ b/examples/custom_window_frame/src/main.rs @@ -2,7 +2,7 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui; +use eframe::egui::{self, ViewportRender}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -30,7 +30,16 @@ impl eframe::App for MyApp { egui::Rgba::TRANSPARENT.to_array() // Make sure we don't paint anything behind the rounded corners } - fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } custom_window_frame(ctx, frame, "egui with custom frame", |ui| { ui.label("This is just the contents of the window."); ui.horizontal(|ui| { diff --git a/examples/download_image/src/main.rs b/examples/download_image/src/main.rs index 2a2c3540e..77ac52c81 100644 --- a/examples/download_image/src/main.rs +++ b/examples/download_image/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui; +use eframe::egui::{self, ViewportRender}; use egui_extras::RetainedImage; use poll_promise::Promise; @@ -21,7 +21,16 @@ struct MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } let promise = self.promise.get_or_insert_with(|| { // Begin download. // We download the image using `ehttp`, a library that works both in WASM and on native. diff --git a/examples/file_dialog/src/main.rs b/examples/file_dialog/src/main.rs index 77f88872a..81c843549 100644 --- a/examples/file_dialog/src/main.rs +++ b/examples/file_dialog/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui; +use eframe::egui::{self, ViewportRender}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -23,7 +23,16 @@ struct MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { ui.label("Drag-and-drop files onto the window!"); diff --git a/examples/hello_world/src/main.rs b/examples/hello_world/src/main.rs index 47c045db5..f27b4870a 100644 --- a/examples/hello_world/src/main.rs +++ b/examples/hello_world/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui; +use eframe::egui::{self, ViewportRender}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -30,7 +30,16 @@ impl Default for MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { ui.heading("My egui Application"); ui.horizontal(|ui| { diff --git a/examples/hello_world_par/src/main.rs b/examples/hello_world_par/src/main.rs index 4c2c6d78d..69955a26f 100644 --- a/examples/hello_world_par/src/main.rs +++ b/examples/hello_world_par/src/main.rs @@ -5,7 +5,7 @@ use std::sync::{mpsc, Arc, RwLock}; use std::thread::JoinHandle; -use eframe::egui; +use eframe::egui::{self, ViewportRender}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -136,7 +136,16 @@ impl std::ops::Drop for MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } let data = self.data.clone(); egui::Window::new("Main thread").show(ctx, move |ui, _, parent_id| { if ui.button("Spawn another thread").clicked() { diff --git a/examples/keyboard_events/src/main.rs b/examples/keyboard_events/src/main.rs index a51bf1908..648f7928c 100644 --- a/examples/keyboard_events/src/main.rs +++ b/examples/keyboard_events/src/main.rs @@ -19,7 +19,16 @@ struct Content { } impl eframe::App for Content { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { ui.heading("Press/Hold/Release example. Press A to test."); if ui.button("Clear").clicked() { diff --git a/examples/puffin_profiler/src/main.rs b/examples/puffin_profiler/src/main.rs index 2cfc5e61d..4dd7961f4 100644 --- a/examples/puffin_profiler/src/main.rs +++ b/examples/puffin_profiler/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui; +use eframe::egui::{self, ViewportRender}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -17,7 +17,16 @@ fn main() -> Result<(), eframe::Error> { struct MyApp {} impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { ui.heading("Example of how to use the puffin profiler with egui"); ui.separator(); diff --git a/examples/retained_image/src/main.rs b/examples/retained_image/src/main.rs index 148217fc6..470fbf65a 100644 --- a/examples/retained_image/src/main.rs +++ b/examples/retained_image/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui; +use eframe::egui::{self, ViewportRender}; use egui_extras::RetainedImage; fn main() -> Result<(), eframe::Error> { @@ -35,7 +35,16 @@ impl Default for MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { ui.heading("This is an image:"); self.image.show(ui); diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs index 4dff5326d..0c124ff39 100644 --- a/examples/screenshot/src/main.rs +++ b/examples/screenshot/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui::{self, ColorImage}; +use eframe::egui::{self, ColorImage, ViewportRender}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -24,7 +24,16 @@ struct MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { if let Some(screenshot) = self.screenshot.take() { self.texture = Some(ui.ctx().load_texture( diff --git a/examples/serial_windows/src/main.rs b/examples/serial_windows/src/main.rs index 5e85d6467..b3c653f07 100644 --- a/examples/serial_windows/src/main.rs +++ b/examples/serial_windows/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui; +use eframe::egui::{self, ViewportRender}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -46,7 +46,16 @@ struct MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { let label_text = if self.has_next { "When this window is closed the next will be opened after a short delay" diff --git a/examples/svg/src/main.rs b/examples/svg/src/main.rs index 5629f8035..18e2866ef 100644 --- a/examples/svg/src/main.rs +++ b/examples/svg/src/main.rs @@ -4,7 +4,7 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::egui; +use eframe::egui::{self, ViewportRender}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -37,7 +37,16 @@ impl Default for MyApp { } impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &egui::Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } egui::CentralPanel::default().show(ctx, |ui| { ui.heading("SVG example"); ui.label("The SVG is rasterized and displayed as a texture."); diff --git a/examples/user_attention/src/main.rs b/examples/user_attention/src/main.rs index 4f7e521d2..7a548c80e 100644 --- a/examples/user_attention/src/main.rs +++ b/examples/user_attention/src/main.rs @@ -1,5 +1,5 @@ use eframe::{ - egui::{Button, CentralPanel, Context, UserAttentionType}, + egui::{Button, CentralPanel, Context, UserAttentionType, ViewportRender}, CreationContext, NativeOptions, }; @@ -54,7 +54,16 @@ impl Application { } impl eframe::App for Application { - fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) { + fn update( + &mut self, + ctx: &Context, + frame: &mut eframe::Frame, + render: Option<&ViewportRender>, + ) { + if let Some(render) = render { + render(ctx, frame.viewport_id(), frame.parent_viewport_id()); + return; + } if let Some(request_at) = self.request_at { if request_at < SystemTime::now() { self.request_at = None;