Request a redraw only on relevant events
This commit is contained in:
		
							parent
							
								
									c0a5dc980e
								
							
						
					
					
						commit
						49dbf2c146
					
				| @ -119,6 +119,8 @@ pub fn main() { | ||||
|                 } | ||||
|             } | ||||
|             Event::MainEventsCleared => { | ||||
|                 // If there are events pending
 | ||||
|                 if !state.is_queue_empty() { | ||||
|                     // We update iced
 | ||||
|                     let _ = state.update( | ||||
|                         None, | ||||
| @ -130,6 +132,7 @@ pub fn main() { | ||||
|                     // and request a redraw
 | ||||
|                     window.request_redraw(); | ||||
|                 } | ||||
|             } | ||||
|             Event::RedrawRequested(_) => { | ||||
|                 if resized { | ||||
|                     let size = window.inner_size(); | ||||
|  | ||||
| @ -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 _), | ||||
|  | ||||
| @ -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(), | ||||
|  | ||||
| @ -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 _), | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user