From a3c7bdd84601a331aa2e4598f9be95f1f61361fd Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 12 Nov 2023 12:49:30 +0100 Subject: [PATCH] Minor cleanup --- crates/eframe/src/native/epi_integration.rs | 9 ++++++++- crates/egui-winit/src/lib.rs | 2 ++ crates/egui/src/data/input.rs | 21 +++++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index e70d340549c..1c0422409b0 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -216,6 +216,8 @@ pub fn handle_app_output( app_output: epi::backend::AppOutput, window_state: &mut WindowState, ) { + crate::profile_function!(); + let epi::backend::AppOutput { close: _, window_size, @@ -478,6 +480,8 @@ impl EpiIntegration { egui_winit.on_event(&self.egui_ctx, event) } + /// If `viewport_ui_cb` is None, we are in the root viewport + /// and will cal [`App::update`]. pub fn update( &mut self, app: &mut dyn epi::App, @@ -497,12 +501,15 @@ impl EpiIntegration { // Run user code: let full_output = self.egui_ctx.run(raw_input, |egui_ctx| { - crate::profile_scope!("App::update"); if let Some(viewport_ui_cb) = viewport_ui_cb { // Child viewport + crate::profile_scope!("callback"); + debug_assert!(id_pair.this != ViewportId::ROOT); viewport_ui_cb(egui_ctx); } else { // Root viewport + crate::profile_scope!("App::update"); + debug_assert_eq!(id_pair, ViewportIdPair::ROOT); app.update(egui_ctx, &mut self.frame); } }); diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index c82b0beb1fa..45835405252 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -726,6 +726,8 @@ impl State { egui_ctx: &egui::Context, platform_output: egui::PlatformOutput, ) { + crate::profile_function!(); + let egui::PlatformOutput { cursor_icon, open_url, diff --git a/crates/egui/src/data/input.rs b/crates/egui/src/data/input.rs index 11200075fc8..0ea87beda41 100644 --- a/crates/egui/src/data/input.rs +++ b/crates/egui/src/data/input.rs @@ -161,6 +161,19 @@ impl ViewportInfo { pub fn take(&mut self) -> Self { core::mem::take(self) } + + pub fn ui(&self, ui: &mut crate::Ui) { + let Self { + id_pair, + inner_rect, + outer_rect, + close_requested, + } = self; + ui.label(format!("id_pair: {id_pair:?}")); + ui.label(format!("inner_rect: {inner_rect:?}")); + ui.label(format!("outer_rect: {outer_rect:?}")); + ui.label(format!("close_requested: {close_requested:?}")); + } } /// A file about to be dropped into egui. @@ -1000,14 +1013,6 @@ impl RawInput { } } -impl ViewportInfo { - pub fn ui(&self, ui: &mut crate::Ui) { - ui.label(format!("id_pair: {:?}", self.id_pair)); - ui.label(format!("inner_rect: {:?}", self.inner_rect)); - ui.label(format!("outer_rect: {:?}", self.outer_rect)); - } -} - /// this is a `u64` as values of this kind can always be obtained by hashing #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]