Просмотр исходного кода

wallet: chatview optimize gen_mesh() to actually load missing meshes from cache and also avoid drawing too often.

darkfi 1 год назад
Родитель
Сommit
5fdb7b786d
2 измененных файлов с 26 добавлено и 6 удалено
  1. 21 4
      bin/darkwallet/src/ui/chatview/mod.rs
  2. 5 2
      bin/darkwallet/src/ui/chatview/page.rs

+ 21 - 4
bin/darkwallet/src/ui/chatview/mod.rs

@@ -88,12 +88,19 @@ struct TouchInfo {
     start_scroll: f32,
     start_y: f32,
     start_instant: std::time::Instant,
+    last_instant: std::time::Instant,
     last_y: f32,
 }
 
 impl TouchInfo {
     fn new() -> Self {
-        Self { start_scroll: 0., start_y: 0., start_instant: std::time::Instant::now(), last_y: 0. }
+        Self {
+            start_scroll: 0.,
+            start_y: 0.,
+            start_instant: std::time::Instant::now(),
+            last_instant: std::time::Instant::now(),
+            last_y: 0.,
+        }
     }
 }
 
@@ -436,13 +443,20 @@ impl ChatView {
                 touch_info.start_scroll = self.scroll.get();
                 touch_info.start_y = touch_y;
                 touch_info.start_instant = std::time::Instant::now();
+                touch_info.last_instant = std::time::Instant::now();
                 touch_info.last_y = touch_y;
             }
             TouchPhase::Moved => {
-                let (start_scroll, start_y) = {
+                let instant = std::time::Instant::now();
+                let (start_scroll, start_y, do_update) = {
                     let mut touch_info = self.touch_info.lock().unwrap();
                     touch_info.last_y = touch_y;
-                    (touch_info.start_scroll, touch_info.start_y)
+                    let last_elapsed = touch_info.last_instant.elapsed().as_millis_f32();
+                    let do_update = last_elapsed > 20.;
+                    if do_update {
+                        touch_info.last_instant = std::time::Instant::now();
+                    }
+                    (touch_info.start_scroll, touch_info.start_y, do_update)
                 };
 
                 let dist = touch_y - start_y;
@@ -452,7 +466,10 @@ impl ChatView {
                 // how often we move to fixed intervals.
                 // draw a poly shape and eval each line segment.
                 let scroll = start_scroll + dist;
-                self.scrollview(scroll).await;
+                let instant = std::time::Instant::now();
+                if do_update {
+                    self.scrollview(scroll).await;
+                }
             }
             TouchPhase::Ended => {
                 // Now calculate scroll acceleration

+ 5 - 2
bin/darkwallet/src/ui/chatview/page.rs

@@ -119,6 +119,10 @@ impl PrivMessage {
         debug_render: bool,
         render_api: &RenderApi,
     ) -> DrawMesh {
+        if let Some(mesh) = &self.mesh_cache {
+            return mesh.clone()
+        }
+
         //debug!(target: "ui::chatview", "gen_mesh({})", glyph_str(&self.unwrapped_glyphs));
         let mut mesh = MeshBuilder::new();
 
@@ -586,8 +590,7 @@ impl MessageBuffer {
     ) -> Vec<(f32, DrawMesh)> {
         let mut meshes = vec![];
 
-        let descent = line_height - baseline;
-        let mut current_pos = descent;
+        let mut current_pos = 0.;
         for msg in &mut self.msgs {
             let mesh_height = msg.height(line_height);
             let msg_bottom = current_pos;