From 4b94b2ca1b998479f0ef42696b83ca0ad7e97ae8 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 15:50:16 +0900 Subject: [PATCH 01/14] Update epi_integration.rs --- crates/eframe/src/native/epi_integration.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index f27d011202e..30dea793f21 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -278,13 +278,23 @@ impl EpiIntegration { let full_output = self.egui_ctx.run(raw_input, |egui_ctx| { if let Some(viewport_ui_cb) = viewport_ui_cb { - // Child viewport + // Child Deferred Viewport crate::profile_scope!("viewport_callback"); viewport_ui_cb(egui_ctx); } else { + // ROOT Viewport ( with Immediate Viewport ) crate::profile_scope!("App::update"); app.update(egui_ctx, &mut self.frame); } + + let continuous_mode = egui_ctx.options(|options| options.continuous_mode); + if continuous_mode { + let viewport_id = egui_ctx.viewport_id(); + // TODO : Do not recall until the next repaint. + // 1000 millis / 60 fps = 16.67 millis + self.egui_ctx + .request_repaint_after_for(std::time::Duration::from_millis(8), viewport_id); + } }); let is_root_viewport = viewport_ui_cb.is_none(); From 67bc17c7e637fba3261d8dc7dd89014f653b7775 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 15:51:38 +0900 Subject: [PATCH 02/14] Update memory.rs --- crates/egui/src/memory.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 068347b5697..bd8c2bfc3c3 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -191,6 +191,14 @@ pub struct Options { /// Controls the tessellator. pub tessellation_options: epaint::TessellationOptions, + /// If `true`, This will call `egui::Context::request_repaint()` at the end of each frame + /// If `false` (default), egui is only updated if are input events (like mouse movements) or there are some animations in the GUI. + /// + /// ``` + /// ui.ctx().options_mut(|options| { options.continuous_mode = true}); + /// ``` + pub continuous_mode: bool, + /// If any widget moves or changes id, repaint everything. /// /// It is recommended you keep this OFF, because @@ -230,6 +238,7 @@ impl Default for Options { zoom_factor: 1.0, zoom_with_keyboard: true, tessellation_options: Default::default(), + continuous_mode: false, repaint_on_widget_change: false, screen_reader: false, preload_font_glyphs: true, @@ -246,6 +255,7 @@ impl Options { zoom_factor: _, // TODO zoom_with_keyboard, tessellation_options, + continuous_mode, repaint_on_widget_change, screen_reader: _, // needs to come from the integration preload_font_glyphs: _, @@ -257,6 +267,8 @@ impl Options { CollapsingHeader::new("⚙ Options") .default_open(false) .show(ui, |ui| { + ui.checkbox(continuous_mode, "Repaint at the end of each frame"); + ui.checkbox( repaint_on_widget_change, "Repaint if any widget moves or changes id", @@ -521,7 +533,9 @@ impl Focus { } } - let current_focused = self.focused_widget?; + let Some(current_focused) = self.focused_widget else { + return None; + }; // In what direction we are looking for the next widget. let search_direction = match self.focus_direction { @@ -544,7 +558,9 @@ impl Focus { } }); - let current_rect = self.focus_widgets_cache.get(¤t_focused.id)?; + let Some(current_rect) = self.focus_widgets_cache.get(¤t_focused.id) else { + return None; + }; let mut best_score = std::f32::INFINITY; let mut best_id = None; @@ -635,7 +651,7 @@ impl Memory { } pub(crate) fn had_focus_last_frame(&self, id: Id) -> bool { - self.focus().and_then(|f| f.id_previous_frame) == Some(id) + self.focus().id_previous_frame == Some(id) } /// True if the given widget had keyboard focus last frame, but not this one. @@ -661,7 +677,7 @@ impl Memory { /// Which widget has keyboard focus? pub fn focused(&self) -> Option { - self.focus().and_then(|f| f.focused()) + self.focus().focused() } /// Set an event filter for a widget. @@ -793,8 +809,10 @@ impl Memory { self.interactions.entry(self.viewport_id).or_default() } - pub(crate) fn focus(&self) -> Option<&Focus> { - self.focus.get(&self.viewport_id) + pub(crate) fn focus(&self) -> &Focus { + self.focus + .get(&self.viewport_id) + .expect("Failed to get focus") } pub(crate) fn focus_mut(&mut self) -> &mut Focus { From 34e436488ae6a221280042fa626c88520faecb58 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 15:52:51 +0900 Subject: [PATCH 03/14] Update memory.rs --- crates/egui/src/memory.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index bd8c2bfc3c3..09e13e671e9 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -195,7 +195,7 @@ pub struct Options { /// If `false` (default), egui is only updated if are input events (like mouse movements) or there are some animations in the GUI. /// /// ``` - /// ui.ctx().options_mut(|options| { options.continuous_mode = true}); + /// ui.ctx().options_mut(|options| options.continuous_mode = true); /// ``` pub continuous_mode: bool, From 2c48d6dab733775d06ff6080c108add2aeec5e57 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 15:55:00 +0900 Subject: [PATCH 04/14] Update backend_panel.rs --- crates/egui_demo_app/src/backend_panel.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/egui_demo_app/src/backend_panel.rs b/crates/egui_demo_app/src/backend_panel.rs index 2e2f0f0a71c..119743edb78 100644 --- a/crates/egui_demo_app/src/backend_panel.rs +++ b/crates/egui_demo_app/src/backend_panel.rs @@ -65,10 +65,11 @@ impl BackendPanel { match self.run_mode { RunMode::Continuous => { // Tell the backend to repaint as soon as possible - ctx.request_repaint(); + ctx.options_mut(|options| options.continuous_mode = true); } RunMode::Reactive => { // let the computer rest for a bit + ctx.options_mut(|options| options.continuous_mode = false); } } } From bc9d3742d9bdf00e18fbb239b69e130394c62383 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:07:04 +0900 Subject: [PATCH 05/14] Update memory.rs --- crates/egui/src/memory.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 09e13e671e9..50454462b0b 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -194,7 +194,7 @@ pub struct Options { /// If `true`, This will call `egui::Context::request_repaint()` at the end of each frame /// If `false` (default), egui is only updated if are input events (like mouse movements) or there are some animations in the GUI. /// - /// ``` + /// ```norun```` /// ui.ctx().options_mut(|options| options.continuous_mode = true); /// ``` pub continuous_mode: bool, From d67f20fd2d499c6fae6dde920fcd0936ef270192 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:09:30 +0900 Subject: [PATCH 06/14] Update memory.rs --- crates/egui/src/memory.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 50454462b0b..343cdabbf09 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -194,7 +194,7 @@ pub struct Options { /// If `true`, This will call `egui::Context::request_repaint()` at the end of each frame /// If `false` (default), egui is only updated if are input events (like mouse movements) or there are some animations in the GUI. /// - /// ```norun```` + /// ```norun``` /// ui.ctx().options_mut(|options| options.continuous_mode = true); /// ``` pub continuous_mode: bool, From 2b455158322648cf948a244eda07f0f19862600c Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:14:30 +0900 Subject: [PATCH 07/14] Update memory.rs --- crates/egui/src/memory.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 343cdabbf09..337cba1d4df 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -194,7 +194,7 @@ pub struct Options { /// If `true`, This will call `egui::Context::request_repaint()` at the end of each frame /// If `false` (default), egui is only updated if are input events (like mouse movements) or there are some animations in the GUI. /// - /// ```norun``` + /// ```no_run /// ui.ctx().options_mut(|options| options.continuous_mode = true); /// ``` pub continuous_mode: bool, From 1d4d54ba291a8e8c49bf2667f032543cae566e73 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:21:20 +0900 Subject: [PATCH 08/14] Update memory.rs --- crates/egui/src/memory.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 337cba1d4df..c43a1039566 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -193,10 +193,6 @@ pub struct Options { /// If `true`, This will call `egui::Context::request_repaint()` at the end of each frame /// If `false` (default), egui is only updated if are input events (like mouse movements) or there are some animations in the GUI. - /// - /// ```no_run - /// ui.ctx().options_mut(|options| options.continuous_mode = true); - /// ``` pub continuous_mode: bool, /// If any widget moves or changes id, repaint everything. From f00fd64595ff79d34e32b2af5c6fd1dac6517c2e Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:23:57 +0900 Subject: [PATCH 09/14] Update epi_integration.rs --- crates/eframe/src/native/epi_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 30dea793f21..ed45e73521f 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -290,7 +290,7 @@ impl EpiIntegration { let continuous_mode = egui_ctx.options(|options| options.continuous_mode); if continuous_mode { let viewport_id = egui_ctx.viewport_id(); - // TODO : Do not recall until the next repaint. + // TODO(rustbasic) : Do not recall until the next repaint. // 1000 millis / 60 fps = 16.67 millis self.egui_ctx .request_repaint_after_for(std::time::Duration::from_millis(8), viewport_id); From 8c2f7419a219b0a285a86be9544c0f422d588cd4 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:58:37 +0900 Subject: [PATCH 10/14] Update memory.rs --- crates/egui/src/memory.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index c43a1039566..28df0c40bbc 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -529,9 +529,7 @@ impl Focus { } } - let Some(current_focused) = self.focused_widget else { - return None; - }; + let current_focused = self.focused_widget?; // In what direction we are looking for the next widget. let search_direction = match self.focus_direction { @@ -554,9 +552,7 @@ impl Focus { } }); - let Some(current_rect) = self.focus_widgets_cache.get(¤t_focused.id) else { - return None; - }; + let current_rect = self.focus_widgets_cache.get(¤t_focused.id)?; let mut best_score = std::f32::INFINITY; let mut best_id = None; @@ -647,7 +643,7 @@ impl Memory { } pub(crate) fn had_focus_last_frame(&self, id: Id) -> bool { - self.focus().id_previous_frame == Some(id) + self.focus().and_then(|f| f.id_previous_frame) == Some(id) } /// True if the given widget had keyboard focus last frame, but not this one. @@ -673,7 +669,7 @@ impl Memory { /// Which widget has keyboard focus? pub fn focused(&self) -> Option { - self.focus().focused() + self.focus().and_then(|f| f.focused()) } /// Set an event filter for a widget. @@ -805,10 +801,8 @@ impl Memory { self.interactions.entry(self.viewport_id).or_default() } - pub(crate) fn focus(&self) -> &Focus { - self.focus - .get(&self.viewport_id) - .expect("Failed to get focus") + pub(crate) fn focus(&self) -> Option<&Focus> { + self.focus.get(&self.viewport_id) } pub(crate) fn focus_mut(&mut self) -> &mut Focus { From 1a1c0073ccd2b93453018205cd1bfa568e1677b9 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 29 Mar 2024 12:18:02 +0100 Subject: [PATCH 11/14] make `continuous_mode` work on all egui integrations --- crates/eframe/src/native/epi_integration.rs | 9 --------- crates/egui/src/context.rs | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index f8034590933..a6dfe5cc769 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -291,15 +291,6 @@ impl EpiIntegration { crate::profile_scope!("App::update"); app.update(egui_ctx, &mut self.frame); } - - let continuous_mode = egui_ctx.options(|options| options.continuous_mode); - if continuous_mode { - let viewport_id = egui_ctx.viewport_id(); - // TODO(rustbasic) : Do not recall until the next repaint. - // 1000 millis / 60 fps = 16.67 millis - self.egui_ctx - .request_repaint_after_for(std::time::Duration::from_millis(8), viewport_id); - } }); let is_root_viewport = viewport_ui_cb.is_none(); diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 222f8ab0575..d1aa4f658fb 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1977,7 +1977,7 @@ impl ContextImpl { .graphics .drain(self.memory.areas().order(), &self.memory.layer_transforms); - let mut repaint_needed = false; + let mut repaint_needed = self.memory.options.continuous_mode; { if self.memory.options.repaint_on_widget_change { From 52f06b1a4fd0e10fb5c286e8808752a0686637f2 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Mon, 1 Apr 2024 01:55:33 +0900 Subject: [PATCH 12/14] Update context.rs --- crates/egui/src/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index d3084fc82f2..74a71da2141 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1978,7 +1978,7 @@ impl ContextImpl { .graphics .drain(self.memory.areas().order(), &self.memory.layer_transforms); - let mut repaint_needed = self.memory.options.continuous_mode; + let mut repaint_needed = false; { if self.memory.options.repaint_on_widget_change { From ebe65d8b8f08302d30d2b5e843a1f67f2eee96d5 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 27 Apr 2024 15:29:18 +0900 Subject: [PATCH 13/14] Update epi_integration.rs --- crates/eframe/src/native/epi_integration.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index a6dfe5cc769..7e91d7f7f10 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -291,6 +291,17 @@ impl EpiIntegration { crate::profile_scope!("App::update"); app.update(egui_ctx, &mut self.frame); } + + let viewport_id = egui_ctx.viewport_id(); + + let continuous_mode = egui_ctx.options(|options| options.continuous_mode); + if continuous_mode { + // let viewport_id = egui_ctx.viewport_id(); + // TODO(rustbasic) : Do not recall until the next repaint. + // 1000 millis / 60 fps = 16.67 millis + self.egui_ctx + .request_repaint_after_for(std::time::Duration::from_millis(8), viewport_id); + } }); let is_root_viewport = viewport_ui_cb.is_none(); From 88c773fb48f2854f795e6c83667033ffc3fbdfdd Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 27 Apr 2024 15:38:43 +0900 Subject: [PATCH 14/14] Update epi_integration.rs --- crates/eframe/src/native/epi_integration.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 7e91d7f7f10..f8034590933 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -292,11 +292,9 @@ impl EpiIntegration { app.update(egui_ctx, &mut self.frame); } - let viewport_id = egui_ctx.viewport_id(); - let continuous_mode = egui_ctx.options(|options| options.continuous_mode); if continuous_mode { - // let viewport_id = egui_ctx.viewport_id(); + let viewport_id = egui_ctx.viewport_id(); // TODO(rustbasic) : Do not recall until the next repaint. // 1000 millis / 60 fps = 16.67 millis self.egui_ctx