summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-11-05 04:50:57 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-11-05 04:50:57 +0100
commite966cd5b591d8014e53f414014cb49deffef535d (patch)
tree57baebe6b8442f1df972816b9d06c43948513306 /winit
parentd5a15419e98cf31c173fff5a10f97e36958d994f (diff)
downloadiced-e966cd5b591d8014e53f414014cb49deffef535d.tar.gz
iced-e966cd5b591d8014e53f414014cb49deffef535d.tar.bz2
iced-e966cd5b591d8014e53f414014cb49deffef535d.zip
Remove a bit of code duplication in both shells
Diffstat (limited to 'winit')
-rw-r--r--winit/src/application.rs79
1 files changed, 44 insertions, 35 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 3a41a0e4..8e97706f 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -214,19 +214,20 @@ async fn run_instance<A, E, C>(
use iced_futures::futures::stream::StreamExt;
use winit::event;
- let mut state = State::new(&application, &window);
-
let surface = compositor.create_surface(&window);
- let physical_size = state.physical_size();
+ let clipboard = Clipboard::new(&window);
+ let mut state = State::new(&application, &window);
let mut viewport_version = state.viewport_version();
- let mut swap_chain = compositor.create_swap_chain(
- &surface,
- physical_size.width,
- physical_size.height,
- );
+ let mut swap_chain = {
+ let physical_size = state.physical_size();
- let clipboard = Clipboard::new(&window);
+ compositor.create_swap_chain(
+ &surface,
+ physical_size.width,
+ physical_size.height,
+ )
+ };
let mut user_interface = ManuallyDrop::new(build_user_interface(
&mut application,
@@ -264,29 +265,17 @@ async fn run_instance<A, E, C>(
events.clear();
debug.event_processing_finished();
- if messages.is_empty() {
- debug.draw_started();
- primitive = user_interface
- .draw(&mut renderer, state.cursor_position());
- debug.draw_finished();
- } else {
+ if !messages.is_empty() {
let cache =
ManuallyDrop::into_inner(user_interface).into_cache();
- for message in messages.drain(..) {
- debug.log_message(&message);
-
- debug.update_started();
- let command =
- runtime.enter(|| application.update(message));
- debug.update_finished();
-
- runtime.spawn(command);
- }
-
- // Update subscriptions
- let subscription = application.subscription();
- runtime.track(subscription);
+ // Update application
+ update(
+ &mut application,
+ &mut runtime,
+ &mut debug,
+ messages,
+ );
// Update window
state.synchronize(&application, &window);
@@ -298,13 +287,13 @@ async fn run_instance<A, E, C>(
state.logical_size(),
&mut debug,
));
-
- debug.draw_started();
- primitive = user_interface
- .draw(&mut renderer, state.cursor_position());
- debug.draw_finished();
}
+ debug.draw_started();
+ primitive =
+ user_interface.draw(&mut renderer, state.cursor_position());
+ debug.draw_finished();
+
window.request_redraw();
}
event::Event::UserEvent(message) => {
@@ -412,7 +401,7 @@ pub fn requests_exit(
}
}
-fn build_user_interface<'a, A: Application>(
+pub fn build_user_interface<'a, A: Application>(
application: &'a mut A,
cache: Cache,
renderer: &mut A::Renderer,
@@ -429,3 +418,23 @@ fn build_user_interface<'a, A: Application>(
user_interface
}
+
+pub fn update<A: Application, E: Executor>(
+ application: &mut A,
+ runtime: &mut Runtime<E, Proxy<A::Message>, A::Message>,
+ debug: &mut Debug,
+ messages: Vec<A::Message>,
+) {
+ for message in messages {
+ debug.log_message(&message);
+
+ debug.update_started();
+ let command = runtime.enter(|| application.update(message));
+ debug.update_finished();
+
+ runtime.spawn(command);
+ }
+
+ let subscription = application.subscription();
+ runtime.track(subscription);
+}