summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-04 22:46:57 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-04 22:47:36 +0200
commit5204cc8c8bc8361a11815d7c711b7da10a6ca8e5 (patch)
tree32476406652404cbec6d7c581fc8dabe918cd6e3 /src
parentebb8dbb065c2cb5390e35237eda122cbe9ef5f42 (diff)
downloadiced-5204cc8c8bc8361a11815d7c711b7da10a6ca8e5.tar.gz
iced-5204cc8c8bc8361a11815d7c711b7da10a6ca8e5.tar.bz2
iced-5204cc8c8bc8361a11815d7c711b7da10a6ca8e5.zip
Count redraws and add a couple of TODOs
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 3a7825bc..93f8110e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -39,15 +39,19 @@ pub trait UserInterface {
let mut cache = Some(iced_winit::Cache::default());
let mut events = Vec::new();
+ let mut redraws = 0;
window.request_redraw();
event_loop.run(move |event, _, control_flow| match event {
Event::EventsCleared => {
- // TODO: Once we remove lifetimes from widgets, we will be able
- // to keep user interfaces alive between events.
+ // TODO: We should find out a way to keep a user interface
+ // alive between events while still being able to drop it and
+ // rebuild it only when a message is handled.
//
- // This will allow us to only rebuild when a message is handled.
+ // The borrow checker does not seem to like it when I try this,
+ // even though I am not technically double borrowing at any
+ // point.
let mut user_interface = iced_winit::UserInterface::build(
self.view(),
cache.take().unwrap(),
@@ -61,6 +65,8 @@ pub trait UserInterface {
cache = Some(user_interface.into_cache());
} else {
+ // When there are messages, we are forced to rebuild twice
+ // for now :^)
let temp_cache = user_interface.into_cache();
for message in messages {
@@ -76,7 +82,7 @@ pub trait UserInterface {
let _ = user_interface.draw(&mut renderer);
cache = Some(user_interface.into_cache());
- };
+ }
window.request_redraw();
}
@@ -84,8 +90,13 @@ pub trait UserInterface {
event: WindowEvent::RedrawRequested,
..
} => {
- println!("Redrawing");
+ println!("Redrawing {}", redraws);
renderer.draw();
+
+ redraws += 1;
+
+ // TODO: Handle animations!
+ // Maybe we can use `ControlFlow::WaitUntil` for this.
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,