summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/integration/src/main.rs21
-rw-r--r--glutin/src/application.rs4
-rw-r--r--native/src/program/state.rs11
-rw-r--r--winit/src/application.rs4
4 files changed, 27 insertions, 13 deletions
diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs
index db8b4366..4c4b6d84 100644
--- a/examples/integration/src/main.rs
+++ b/examples/integration/src/main.rs
@@ -119,16 +119,19 @@ pub fn main() {
}
}
Event::MainEventsCleared => {
- // We update iced
- let _ = state.update(
- None,
- viewport.logical_size(),
- &mut renderer,
- &mut debug,
- );
+ // If there are events pending
+ if !state.is_queue_empty() {
+ // We update iced
+ let _ = state.update(
+ None,
+ viewport.logical_size(),
+ &mut renderer,
+ &mut debug,
+ );
- // and request a redraw
- window.request_redraw();
+ // and request a redraw
+ window.request_redraw();
+ }
}
Event::RedrawRequested(_) => {
if resized {
diff --git a/glutin/src/application.rs b/glutin/src/application.rs
index c777a13b..4f36114c 100644
--- a/glutin/src/application.rs
+++ b/glutin/src/application.rs
@@ -95,6 +95,10 @@ pub fn run<A, E, C>(
event_loop.run(move |event, _, control_flow| match event {
event::Event::MainEventsCleared => {
+ if state.is_queue_empty() {
+ return;
+ }
+
let command = runtime.enter(|| {
state.update(
clipboard.as_ref().map(|c| c as _),
diff --git a/native/src/program/state.rs b/native/src/program/state.rs
index 8716d8b9..bb428198 100644
--- a/native/src/program/state.rs
+++ b/native/src/program/state.rs
@@ -88,6 +88,13 @@ where
self.queued_messages.push(message);
}
+ /// Returns whether the event queue of the [`State`] is empty or not.
+ ///
+ /// [`State`]: struct.State.html
+ pub fn is_queue_empty(&self) -> bool {
+ self.queued_events.is_empty() && self.queued_messages.is_empty()
+ }
+
/// Processes all the queued events and messages, rebuilding and redrawing
/// the widgets of the linked [`Program`] if necessary.
///
@@ -102,10 +109,6 @@ where
renderer: &mut P::Renderer,
debug: &mut Debug,
) -> Option<Command<P::Message>> {
- if self.queued_events.is_empty() && self.queued_messages.is_empty() {
- return None;
- }
-
let mut user_interface = build_user_interface(
&mut self.program,
self.cache.take().unwrap(),
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 73ac72b2..a5d00407 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -150,6 +150,10 @@ pub fn run<A, E, C>(
event_loop.run(move |event, _, control_flow| match event {
event::Event::MainEventsCleared => {
+ if state.is_queue_empty() {
+ return;
+ }
+
let command = runtime.enter(|| {
state.update(
clipboard.as_ref().map(|c| c as _),