From 5e52bd6ff67ace46a51141dc4b2621d75943c31c Mon Sep 17 00:00:00 2001 From: darkfi Date: Mon, 5 Aug 2024 10:42:43 +0200 Subject: [PATCH] wallet: chatview dont split pages when size is under PAGE_SIZE --- bin/darkwallet/insert_line.py | 3 ++- bin/darkwallet/src/ui/chatview.rs | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/bin/darkwallet/insert_line.py b/bin/darkwallet/insert_line.py index b0d3340ae..2154fe73b 100644 --- a/bin/darkwallet/insert_line.py +++ b/bin/darkwallet/insert_line.py @@ -3,7 +3,8 @@ from gui import * node_id = api.lookup_node_id("/window/view/chatty") arg_data = bytearray() -serial.write_u32(arg_data, 1849) +serial.write_u64(arg_data, 1722944340005) +arg_data += bytes(32) serial.encode_str(arg_data, "nick") serial.encode_str(arg_data, "hello1234") diff --git a/bin/darkwallet/src/ui/chatview.rs b/bin/darkwallet/src/ui/chatview.rs index 79842c3e1..c067f0d83 100644 --- a/bin/darkwallet/src/ui/chatview.rs +++ b/bin/darkwallet/src/ui/chatview.rs @@ -208,7 +208,7 @@ impl Page2 { let px_height = wrapped_line_idx as f32 * line_height; - //mesh.draw_outline(&Rectangle { x: 0., y: 0., w: clip.w, h: -px_height }, COLOR_GREEN, 1.); + mesh.draw_outline(&Rectangle { x: 0., y: 0., w: clip.w, h: -px_height }, COLOR_GREEN, 1.); let mesh = mesh.alloc(render_api).await.unwrap(); let mesh = mesh.draw_with_texture(atlas.texture_id); @@ -655,9 +655,22 @@ impl ChatView { msgs.sort_unstable_by_key(|msg| msg.timest); msgs.reverse(); - // Replace single page with N pages each with PAGE_SIZE messages + let chunk_size = if msgs.len() > PAGE_SIZE { + // Round up so we don't get a weird page with a single item + msgs.len() / 2 + 1 + } else { + PAGE_SIZE + }; + + // Replace single page with N pages each with chunk_size messages let mut new_pages = vec![]; - for page_msgs in msgs.chunks(PAGE_SIZE).map(|m| m.into()) { + for page_msgs in msgs.chunks(chunk_size).map(|m| m.to_vec()) { + debug!(target: "ui::chatview", "PAGE =========================="); + for msg in &page_msgs { + debug!(target: "ui::chatview", "{} {:?}", msg.timest, msg.chatmsg); + } + debug!(target: "ui::chatview", "==============================="); + let new_page = Page2::new(page_msgs, &self.render_api).await; new_pages.push(new_page); }