Batch events for processing in iced_winit event loop
This commit is contained in:
parent
50a7852cb8
commit
031784e274
1 changed files with 61 additions and 56 deletions
|
|
@ -469,71 +469,74 @@ async fn run_instance<A, E, C>(
|
||||||
events.push(event);
|
events.push(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
event::Event::AboutToWait => {
|
||||||
}
|
if events.is_empty() && messages.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if events.is_empty() && messages.is_empty() {
|
debug.event_processing_started();
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
debug.event_processing_started();
|
let (interface_state, statuses) = user_interface.update(
|
||||||
|
&events,
|
||||||
|
state.cursor(),
|
||||||
|
&mut renderer,
|
||||||
|
&mut clipboard,
|
||||||
|
&mut messages,
|
||||||
|
);
|
||||||
|
|
||||||
let (interface_state, statuses) = user_interface.update(
|
debug.event_processing_finished();
|
||||||
&events,
|
|
||||||
state.cursor(),
|
|
||||||
&mut renderer,
|
|
||||||
&mut clipboard,
|
|
||||||
&mut messages,
|
|
||||||
);
|
|
||||||
|
|
||||||
debug.event_processing_finished();
|
for (event, status) in
|
||||||
|
events.drain(..).zip(statuses.into_iter())
|
||||||
|
{
|
||||||
|
runtime.broadcast(event, status);
|
||||||
|
}
|
||||||
|
|
||||||
for (event, status) in events.drain(..).zip(statuses.into_iter()) {
|
if !messages.is_empty()
|
||||||
runtime.broadcast(event, status);
|
|| matches!(
|
||||||
}
|
interface_state,
|
||||||
|
user_interface::State::Outdated
|
||||||
|
)
|
||||||
|
{
|
||||||
|
let mut cache =
|
||||||
|
ManuallyDrop::into_inner(user_interface).into_cache();
|
||||||
|
|
||||||
if !messages.is_empty()
|
// Update application
|
||||||
|| matches!(interface_state, user_interface::State::Outdated)
|
update(
|
||||||
{
|
&mut application,
|
||||||
let mut cache =
|
&mut compositor,
|
||||||
ManuallyDrop::into_inner(user_interface).into_cache();
|
&mut surface,
|
||||||
|
&mut cache,
|
||||||
|
&mut state,
|
||||||
|
&mut renderer,
|
||||||
|
&mut runtime,
|
||||||
|
&mut clipboard,
|
||||||
|
&mut should_exit,
|
||||||
|
&mut proxy,
|
||||||
|
&mut debug,
|
||||||
|
&mut messages,
|
||||||
|
&window,
|
||||||
|
);
|
||||||
|
|
||||||
// Update application
|
user_interface = ManuallyDrop::new(build_user_interface(
|
||||||
update(
|
&application,
|
||||||
&mut application,
|
cache,
|
||||||
&mut compositor,
|
&mut renderer,
|
||||||
&mut surface,
|
state.logical_size(),
|
||||||
&mut cache,
|
&mut debug,
|
||||||
&state,
|
));
|
||||||
&mut renderer,
|
|
||||||
&mut runtime,
|
|
||||||
&mut clipboard,
|
|
||||||
&mut should_exit,
|
|
||||||
&mut proxy,
|
|
||||||
&mut debug,
|
|
||||||
&mut messages,
|
|
||||||
&window,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update window
|
if should_exit {
|
||||||
state.synchronize(&application, &window);
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
user_interface = ManuallyDrop::new(build_user_interface(
|
if !redraw_pending {
|
||||||
&application,
|
window.request_redraw();
|
||||||
cache,
|
redraw_pending = true;
|
||||||
&mut renderer,
|
}
|
||||||
state.logical_size(),
|
|
||||||
&mut debug,
|
|
||||||
));
|
|
||||||
|
|
||||||
if should_exit {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
_ => {}
|
||||||
|
|
||||||
if !redraw_pending {
|
|
||||||
window.request_redraw();
|
|
||||||
redraw_pending = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -595,7 +598,7 @@ pub fn update<A: Application, C, E: Executor>(
|
||||||
compositor: &mut C,
|
compositor: &mut C,
|
||||||
surface: &mut C::Surface,
|
surface: &mut C::Surface,
|
||||||
cache: &mut user_interface::Cache,
|
cache: &mut user_interface::Cache,
|
||||||
state: &State<A>,
|
state: &mut State<A>,
|
||||||
renderer: &mut A::Renderer,
|
renderer: &mut A::Renderer,
|
||||||
runtime: &mut Runtime<E, Proxy<A::Message>, A::Message>,
|
runtime: &mut Runtime<E, Proxy<A::Message>, A::Message>,
|
||||||
clipboard: &mut Clipboard,
|
clipboard: &mut Clipboard,
|
||||||
|
|
@ -632,6 +635,8 @@ pub fn update<A: Application, C, E: Executor>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state.synchronize(application, window);
|
||||||
|
|
||||||
let subscription = application.subscription();
|
let subscription = application.subscription();
|
||||||
runtime.track(subscription.into_recipes());
|
runtime.track(subscription.into_recipes());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue