From 2131f251fcf106c6f3ac91f0bc0aa8c382ebc693 Mon Sep 17 00:00:00 2001 From: Konkitoman Date: Tue, 25 Jul 2023 12:43:34 +0300 Subject: [PATCH] Update example and now the viewport will always render if can create a native window will be embedded --- crates/eframe/src/native/run.rs | 6 +---- crates/egui/src/context.rs | 14 +++++------- examples/hello_world_simple/src/main.rs | 30 ++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 70af24f31..6f7d5c2b2 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -1065,11 +1065,7 @@ mod glow_integration { let screen_size_in_pixels: [u32; 2] = win.window.as_ref().unwrap().inner_size().into(); - egui_glow::painter::clear( - &gl, - screen_size_in_pixels, - app.clear_color(&integration.egui_ctx.style().visuals), - ); + egui_glow::painter::clear(&gl, screen_size_in_pixels, [0.0, 0.0, 0.0, 0.0]); integration.egui_ctx.set_current_viewport_id(win.window_id); egui::FullOutput { diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index b8cf282a6..ba093bef5 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1987,13 +1987,12 @@ impl Context { window_builder: ViewportBuilder, func: impl Fn(&Context, u64, u64) + Send + Sync + 'static, ) { - let id = self.write(|ctx| { - if ctx.is_desktop { + if self.is_desktop() { + self.write(|ctx| { if let Some(window) = ctx.viewports.get_mut(&window_builder.title) { window.2 = ctx.current_rendering_viewport; window.3 = true; window.4 = Arc::new(Box::new(func)); - window.1 } else { let id = ctx.viewport_counter + 1; ctx.viewport_counter = id; @@ -2007,12 +2006,11 @@ impl Context { Arc::new(Box::new(func)), ), ); - id } - } else { - 0 - } - }); + }); + } else { + func(self, 0, 0); + } } } diff --git a/examples/hello_world_simple/src/main.rs b/examples/hello_world_simple/src/main.rs index b06c0477d..1c707bd70 100644 --- a/examples/hello_world_simple/src/main.rs +++ b/examples/hello_world_simple/src/main.rs @@ -2,7 +2,7 @@ use std::sync::{Arc, RwLock}; -use eframe::egui; +use eframe::egui::{self, window::ViewportBuilder}; fn main() -> Result<(), eframe::Error> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -36,6 +36,34 @@ fn main() -> Result<(), eframe::Error> { age += 1; } ui.label(format!("Hello '{name}', age {age}")); + let mut is_desktop = ctx.is_desktop(); + ui.checkbox(&mut is_desktop, "Is Desktop"); + ctx.set_desktop(is_desktop); + + ctx.create_viewport( + ViewportBuilder::default() + .with_inner_size((50, 30)) + .with_decorations(false) + .with_transparent(true) + .with_resizable(false), + |ctx, _, _| { + let size = egui::Rect::from_min_size( + egui::Pos2::new(0.0, 0.0), + egui::Vec2::new(50.0, 50.0), + ); + let mut ui = egui::Ui::new( + ctx.clone(), + egui::LayerId::background(), + "Viewport Popup".into(), + size, + size, + ); + egui::Frame::popup(&ctx.style()).show(&mut ui, |ui| { + ui.label("Popup"); + }); + }, + ); + let clone = window1_embedded.clone(); let embedded = *window1_embedded.read().unwrap(); egui::CollapsingHeader::new("Show Test1").show(ui, |ui| {