瀏覽代碼

wallet: page up/down to scroll chatview

darkfi 1 年之前
父節點
當前提交
12f50b40d8

+ 5 - 0
bin/darkwallet/src/app/node.rs

@@ -505,6 +505,11 @@ pub fn create_chatview(name: &str) -> SceneNode {
     prop.set_defaults_f32(vec![1000.]).unwrap();
     node.add_property(prop).unwrap();
 
+    let mut prop = Property::new("key_scroll_speed", PropertyType::Float32, PropertySubType::Pixel);
+    prop.set_ui_text("Page Up/Down Scroll Speed", "Scroll speed when pressing page up/down");
+    prop.set_defaults_f32(vec![6.]).unwrap();
+    node.add_property(prop).unwrap();
+
     node.add_method(
         "insert_line",
         vec![

+ 2 - 1
bin/darkwallet/src/app/schema/mod.rs

@@ -49,6 +49,7 @@ mod menu;
 //mod test;
 
 pub const COLOR_SCHEME: ColorScheme = ColorScheme::DarkMode;
+//pub const COLOR_SCHEME: ColorScheme = ColorScheme::PaperLight;
 
 mod android_ui_consts {
     pub const EMOJI_PICKER_ICON_SIZE: f32 = 100.;
@@ -239,7 +240,7 @@ pub async fn make(app: &App, window: SceneNodePtr) {
     if is_first_time {
         let filename = get_first_time_filename();
         if let Some(parent) = filename.parent() {
-            let _ = fs::create_dir_all(parent);
+            let _ = std::fs::create_dir_all(parent);
         }
         let _ = File::create(filename);
     }

+ 9 - 3
bin/darkwallet/src/gfx/mod.rs

@@ -681,7 +681,9 @@ impl Stage {
             //       width, height, gfx_texture_id, texture,
             //       ansi_texture(width as usize, height as usize, &data));
         }
-        self.textures.insert(gfx_texture_id, texture);
+        if let Some(_) = self.textures.insert(gfx_texture_id, texture) {
+            panic!("Duplicate texture ID={gfx_texture_id} detected!");
+        }
     }
     fn method_delete_texture(&mut self, gfx_texture_id: GfxTextureId) {
         let texture = self.textures.remove(&gfx_texture_id).expect("couldn't find gfx_texture_id");
@@ -703,7 +705,9 @@ impl Stage {
             //debug!(target: "gfx", "Invoked method: new_vertex_buffer({:?}, {}) -> {:?}",
             //       verts, gfx_buffer_id, buffer);
         }
-        self.buffers.insert(gfx_buffer_id, buffer);
+        if let Some(_) = self.buffers.insert(gfx_buffer_id, buffer) {
+            panic!("Duplicate vertex buffer ID={gfx_buffer_id} detected!");
+        }
     }
     fn method_new_index_buffer(&mut self, indices: Vec<u16>, gfx_buffer_id: GfxBufferId) {
         let buffer = self.ctx.new_buffer(
@@ -717,7 +721,9 @@ impl Stage {
             //debug!(target: "gfx", "Invoked method: new_index_buffer({:?}, {}) -> {:?}",
             //       indices, gfx_buffer_id, buffer);
         }
-        self.buffers.insert(gfx_buffer_id, buffer);
+        if let Some(_) = self.buffers.insert(gfx_buffer_id, buffer) {
+            panic!("Duplicate index buffer ID={gfx_buffer_id} detected!");
+        }
     }
     fn method_delete_buffer(&mut self, gfx_buffer_id: GfxBufferId) {
         let buffer = self.buffers.remove(&gfx_buffer_id).expect("couldn't find gfx_buffer_id");

+ 0 - 1
bin/darkwallet/src/plugin/darkirc.rs

@@ -33,7 +33,6 @@ use darkfi_serial::{
 use sled_overlay::sled;
 use std::{
     io::Cursor,
-    path::PathBuf,
     sync::{Arc, Mutex as SyncMutex, OnceLock, Weak},
     time::UNIX_EPOCH,
 };

+ 13 - 6
bin/darkwallet/src/ui/chatview/mod.rs

@@ -170,6 +170,7 @@ pub struct ChatView {
     scroll_start_accel: PropertyFloat32,
     scroll_resist: PropertyFloat32,
     select_hold_time: PropertyFloat32,
+    key_scroll_speed: PropertyFloat32,
 
     /// Scroll accel
     motion_cv: Arc<CondVar>,
@@ -223,6 +224,8 @@ impl ChatView {
             PropertyFloat32::wrap(node_ref, Role::Internal, "scroll_resist", 0).unwrap();
         let select_hold_time =
             PropertyFloat32::wrap(node_ref, Role::Internal, "select_hold_time", 0).unwrap();
+        let key_scroll_speed =
+            PropertyFloat32::wrap(node_ref, Role::Internal, "key_scroll_speed", 0).unwrap();
 
         let motion_cv = Arc::new(CondVar::new());
         let bgload_cv = Arc::new(CondVar::new());
@@ -265,6 +268,7 @@ impl ChatView {
             scroll_start_accel,
             scroll_resist,
             select_hold_time,
+            key_scroll_speed,
 
             motion_cv,
             speed: AtomicF32::new(0.),
@@ -475,6 +479,12 @@ impl ChatView {
         self.bgload_cv.notify();
     }
 
+    /// Signal to begin scrolling
+    fn start_scroll(&self, y: f32) {
+        self.speed.fetch_add(y * self.scroll_start_accel.get(), Ordering::Relaxed);
+        self.motion_cv.notify();
+    }
+
     async fn handle_movement(&self) {
         // We need to fix this impl because it depends very much on the speed of the device
         // that it's running on.
@@ -824,13 +834,11 @@ impl UIObject for ChatView {
 
         match key {
             KeyCode::PageUp => {
-                let scroll = self.scroll.get() + 200.;
-                self.scrollview(scroll).await;
+                self.start_scroll(1. * self.key_scroll_speed.get());
                 return true
             }
             KeyCode::PageDown => {
-                let scroll = self.scroll.get() - 200.;
-                self.scrollview(scroll).await;
+                self.start_scroll(-1. * self.key_scroll_speed.get());
                 return true
             }
             _ => {}
@@ -897,8 +905,7 @@ impl UIObject for ChatView {
             return false
         }
 
-        self.speed.fetch_add(wheel_pos.y * self.scroll_start_accel.get(), Ordering::Relaxed);
-        self.motion_cv.notify();
+        self.start_scroll(wheel_pos.y);
         true
     }