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

wallet: chatview add the top line's ascent to the total_height calc and fix selecting lines.

darkfi 1 год назад
Родитель
Сommit
382447ae24

+ 2 - 5
bin/darkwallet/insert_line.py

@@ -3,20 +3,17 @@ from gui import *
 import os, time
 import os, time
 
 
 def send(timest, nick, msg):
 def send(timest, nick, msg):
-    print(timest, nick, msg)
-    node_id = api.lookup_node_id("/window/view/chatty")
-
     arg_data = bytearray()
     arg_data = bytearray()
     serial.write_u64(arg_data, timest)
     serial.write_u64(arg_data, timest)
     arg_data += os.urandom(32)
     arg_data += os.urandom(32)
     serial.encode_str(arg_data, nick)
     serial.encode_str(arg_data, nick)
     serial.encode_str(arg_data, msg)
     serial.encode_str(arg_data, msg)
 
 
-    api.call_method(node_id, "insert_line", arg_data)
+    api.call_method("/window/view/chatty", "insert_line", arg_data)
 
 
 for i in range(200):
 for i in range(200):
     name = f"bob-{i}"
     name = f"bob-{i}"
     send(1732944640000 + i*60000, "hhi12", f"hello {name}")
     send(1732944640000 + i*60000, "hhi12", f"hello {name}")
     #time.sleep(0.4)
     #time.sleep(0.4)
-    input("> ")
+    #input("> ")
 
 

+ 4 - 5
bin/darkwallet/pydrk/api.py

@@ -704,13 +704,12 @@ class Api:
 
 
         return (args, results)
         return (args, results)
 
 
-    def call_method(self, node_id, method_name, arg_data):
+    def call_method(self, node_path, method_name, arg_data):
         req = bytearray()
         req = bytearray()
-        serial.write_u32(req, node_id)
+        serial.encode_str(req, node_path)
         serial.encode_str(req, method_name)
         serial.encode_str(req, method_name)
         serial.encode_buf(req, arg_data)
         serial.encode_buf(req, arg_data)
         cur = self._make_request(Command.CALL_METHOD, req)
         cur = self._make_request(Command.CALL_METHOD, req)
-        errc = serial.read_u8(cur)
-        result = serial.decode_buf(cur)
-        return (errc, result)
+        result = serial.decode_opt(cur, serial.decode_buf)
+        return result
 
 

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

@@ -107,7 +107,7 @@ const TIMESTAMP_WIDTH: f32 = 60.;
 #[cfg(target_os = "android")]
 #[cfg(target_os = "android")]
 const MESSAGE_SPACING: f32 = 15.;
 const MESSAGE_SPACING: f32 = 15.;
 #[cfg(target_os = "linux")]
 #[cfg(target_os = "linux")]
-const MESSAGE_SPACING: f32 = 8.;
+const MESSAGE_SPACING: f32 = 5.;
 
 
 #[cfg(target_os = "android")]
 #[cfg(target_os = "android")]
 const LINE_HEIGHT: f32 = 58.;
 const LINE_HEIGHT: f32 = 58.;
@@ -117,7 +117,7 @@ const LINE_HEIGHT: f32 = 30.;
 #[cfg(target_os = "android")]
 #[cfg(target_os = "android")]
 const CHATVIEW_BASELINE: f32 = 36.;
 const CHATVIEW_BASELINE: f32 = 36.;
 #[cfg(target_os = "linux")]
 #[cfg(target_os = "linux")]
-const CHATVIEW_BASELINE: f32 = 30.;
+const CHATVIEW_BASELINE: f32 = 20.;
 
 
 pub(super) async fn make_test(app: &App, window: SceneNodePtr) {
 pub(super) async fn make_test(app: &App, window: SceneNodePtr) {
     let window_scale = PropertyFloat32::wrap(&window, Role::Internal, "scale", 0).unwrap();
     let window_scale = PropertyFloat32::wrap(&window, Role::Internal, "scale", 0).unwrap();

+ 6 - 28
bin/darkwallet/src/net.rs

@@ -551,37 +551,15 @@ impl ZeroMQAdapter {
                 */
                 */
             }
             }
             Command::CallMethod => {
             Command::CallMethod => {
-                /*
-                let node_id = SceneNodeId::decode(&mut cur).unwrap();
+                let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
                 let method_name = String::decode(&mut cur).unwrap();
                 let method_name = String::decode(&mut cur).unwrap();
                 let arg_data = Vec::<u8>::decode(&mut cur).unwrap();
                 let arg_data = Vec::<u8>::decode(&mut cur).unwrap();
-                debug!(target: "req", "{:?}({}, {}, ...)", cmd, node_id, method_name);
+                debug!(target: "req", "{cmd:?}({node_path}, {method_name}, ...)");
 
 
-                let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
-
-                let method_name2 = method_name.clone();
-                let (tx, rx) = mpsc::sync_channel::<Result<Vec<u8>>>(1);
-                let response_fn = Box::new(move |result| {
-                    debug!(target: "req", "processing callmethod for {}:'{}'", node_id, method_name2);
-                    tx.send(result).unwrap();
-                });
-                node.call_method(&method_name, arg_data, response_fn)?;
-                drop(scene_graph);
-
-                let result = rx.recv().unwrap();
-                debug!(target: "req", "received callmethod for {}:'{}'", node_id, method_name);
-                match result {
-                    Ok(res_data) => {
-                        0u8.encode(&mut reply).unwrap();
-                        res_data.encode(&mut reply).unwrap();
-                    }
-                    Err(err) => {
-                        let errc = err as u8;
-                        errc.encode(&mut reply).unwrap();
-                        0u8.encode(&mut reply).unwrap();
-                    }
-                }
-                */
+                let node =
+                    self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
+                let result = node.call_method(&method_name, arg_data).await?;
+                result.encode(&mut reply).unwrap();
             }
             }
         }
         }
 
 

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

@@ -372,12 +372,14 @@ impl ChatView {
     /// Mark line as selected
     /// Mark line as selected
     async fn select_line(&self, mut y: f32) {
     async fn select_line(&self, mut y: f32) {
         // The cursor is inside the rect. We just have to find which line it clicked.
         // The cursor is inside the rect. We just have to find which line it clicked.
-        let scroll = self.scroll.get();
         let rect = self.rect.get();
         let rect = self.rect.get();
-        let bottom = scroll + rect.y + rect.h;
 
 
-        assert!(bottom >= y);
-        y = bottom - y;
+        // y coord within widget's screen rect
+        y -= rect.y;
+        // The scroll is the position of the bottom of the rect on screen
+        let scroll = self.scroll.get();
+        // Now what is its distance from the absolute bottom
+        y = rect.h - y + scroll;
 
 
         let mut msgbuf = self.msgbuf.lock().await;
         let mut msgbuf = self.msgbuf.lock().await;
         msgbuf.select_line(y).await;
         msgbuf.select_line(y).await;

+ 21 - 3
bin/darkwallet/src/ui/chatview/page.rs

@@ -132,6 +132,7 @@ impl PrivMessage {
         &mut self,
         &mut self,
         clip: &Rectangle,
         clip: &Rectangle,
         line_height: f32,
         line_height: f32,
+        msg_spacing: f32,
         baseline: f32,
         baseline: f32,
         timestamp_width: f32,
         timestamp_width: f32,
         nick_colors: &[Color],
         nick_colors: &[Color],
@@ -149,7 +150,7 @@ impl PrivMessage {
         let mut mesh = MeshBuilder::new();
         let mut mesh = MeshBuilder::new();
 
 
         if self.is_selected {
         if self.is_selected {
-            let height = self.height(line_height);
+            let height = self.height(line_height) + msg_spacing;
             mesh.draw_filled_box(
             mesh.draw_filled_box(
                 &Rectangle { x: 0., y: -height, w: clip.w, h: height },
                 &Rectangle { x: 0., y: -height, w: clip.w, h: height },
                 hi_bg_color,
                 hi_bg_color,
@@ -201,7 +202,13 @@ impl PrivMessage {
         mesh
         mesh
     }
     }
 
 
-    fn render_timestamp(&self, mesh: &mut MeshBuilder, baseline: f32, line_height: f32, timestamp_color: Color) {
+    fn render_timestamp(
+        &self,
+        mesh: &mut MeshBuilder,
+        baseline: f32,
+        line_height: f32,
+        timestamp_color: Color,
+    ) {
         let off_y = self.wrapped_lines.len() as f32 * line_height;
         let off_y = self.wrapped_lines.len() as f32 * line_height;
 
 
         let glyph_pos_iter = GlyphPositionIter::new(
         let glyph_pos_iter = GlyphPositionIter::new(
@@ -517,6 +524,7 @@ impl Message {
         &mut self,
         &mut self,
         clip: &Rectangle,
         clip: &Rectangle,
         line_height: f32,
         line_height: f32,
+        msg_spacing: f32,
         baseline: f32,
         baseline: f32,
         timestamp_width: f32,
         timestamp_width: f32,
         nick_colors: &[Color],
         nick_colors: &[Color],
@@ -530,6 +538,7 @@ impl Message {
             Self::Priv(m) => m.gen_mesh(
             Self::Priv(m) => m.gen_mesh(
                 clip,
                 clip,
                 line_height,
                 line_height,
+                msg_spacing,
                 baseline,
                 baseline,
                 timestamp_width,
                 timestamp_width,
                 nick_colors,
                 nick_colors,
@@ -707,6 +716,7 @@ impl MessageBuffer {
 
 
     pub async fn calc_total_height(&mut self) -> f32 {
     pub async fn calc_total_height(&mut self) -> f32 {
         let line_height = self.line_height.get();
         let line_height = self.line_height.get();
+        let baseline = self.baseline.get();
         let msg_spacing = self.msg_spacing.get();
         let msg_spacing = self.msg_spacing.get();
         let mut height = 0.;
         let mut height = 0.;
 
 
@@ -718,12 +728,18 @@ impl MessageBuffer {
         while let Some(msg) = msgs.next().await {
         while let Some(msg) = msgs.next().await {
             if is_first {
             if is_first {
                 is_first = false;
                 is_first = false;
+            } else {
                 height += msg_spacing;
                 height += msg_spacing;
             }
             }
 
 
             height += msg.height(line_height);
             height += msg.height(line_height);
         }
         }
 
 
+        // For the very top item. This is the ascent
+        if !is_first {
+            height += line_height - baseline;
+        }
+
         height
         height
     }
     }
 
 
@@ -856,6 +872,7 @@ impl MessageBuffer {
                 break
                 break
             }
             }
             if msg_top < scroll {
             if msg_top < scroll {
+                current_pos += msg_spacing;
                 current_pos += mesh_height;
                 current_pos += mesh_height;
                 continue
                 continue
             }
             }
@@ -863,6 +880,7 @@ impl MessageBuffer {
             let mesh = msg.gen_mesh(
             let mesh = msg.gen_mesh(
                 rect,
                 rect,
                 line_height,
                 line_height,
+                msg_spacing,
                 baseline,
                 baseline,
                 timestamp_width,
                 timestamp_width,
                 &nick_colors,
                 &nick_colors,
@@ -978,7 +996,7 @@ impl MessageBuffer {
         while let Some(msg) = msgs.next().await {
         while let Some(msg) = msgs.next().await {
             let mesh_height = msg.height(line_height);
             let mesh_height = msg.height(line_height);
             let msg_bottom = current_pos;
             let msg_bottom = current_pos;
-            let msg_top = current_pos + mesh_height;
+            let msg_top = current_pos + mesh_height + msg_spacing;
 
 
             if msg_bottom <= y && y <= msg_top {
             if msg_bottom <= y && y <= msg_top {
                 // Do nothing
                 // Do nothing