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

darkwallet: add a lightmode for eink monitors

rsx 2 лет назад
Родитель
Сommit
a79d3ab15f

+ 2 - 2
bin/darkwallet/Makefile

@@ -2,8 +2,8 @@ default:
 	cargo lrun
 
 android:
-	#podman run -v $(shell pwd):/root/dw -w /root/dw -t apk cargo quad-apk build
-	#adb uninstall darkfi.darkwallet
+	podman run -v $(shell pwd):/root/dw -w /root/dw -t apk cargo quad-apk build
+	adb uninstall darkfi.darkwallet
 	adb install target/android-artifacts/debug/apk/darkwallet.apk
 	reset
 	adb logcat -c

+ 41 - 18
bin/darkwallet/src/app.rs

@@ -45,6 +45,8 @@ const CHATDB_PATH: &str = "chatdb";
 #[cfg(target_os = "linux")]
 const KING_PATH: &str = "assets/king.png";
 
+const LIGHTMODE: bool = true;
+
 pub struct AsyncRuntime {
     signal: smol::channel::Sender<()>,
     shutdown: smol::channel::Receiver<()>,
@@ -244,19 +246,20 @@ impl App {
         let code = vec![Op::LoadVar("h".to_string())];
         prop.set_expr(3, code).unwrap();
 
+        let c = if LIGHTMODE { 1. } else { 0. };
         // Setup the pimpl
         let node_id = node.id;
         let (x1, y1) = (0., 0.);
         let (x2, y2) = (1., 1.);
         let verts = vec![
             // top left
-            Vertex { pos: [x1, y1], color: [0.3, 0., 0., 1.], uv: [0., 0.] },
+            Vertex { pos: [x1, y1], color: [c, c, c, 1.], uv: [0., 0.] },
             // top right
-            Vertex { pos: [x2, y1], color: [0., 0., 0., 1.], uv: [1., 0.] },
+            Vertex { pos: [x2, y1], color: [c, c, c, 1.], uv: [1., 0.] },
             // bottom left
-            Vertex { pos: [x1, y2], color: [0., 0., 0., 1.], uv: [0., 1.] },
+            Vertex { pos: [x1, y2], color: [c, c, c, 1.], uv: [0., 1.] },
             // bottom right
-            Vertex { pos: [x2, y2], color: [0., 0., 0., 1.], uv: [1., 1.] },
+            Vertex { pos: [x2, y2], color: [c, c, c, 1.], uv: [1., 1.] },
         ];
         let indices = vec![0, 2, 1, 1, 2, 3];
         drop(sg);
@@ -288,16 +291,29 @@ impl App {
         // Setup the pimpl
         let (x1, y1) = (0., 0.);
         let (x2, y2) = (1., 1.);
-        let verts = vec![
-            // top left
-            Vertex { pos: [x1, y1], color: [1., 0., 0., 1.], uv: [0., 0.] },
-            // top right
-            Vertex { pos: [x2, y1], color: [1., 0., 1., 1.], uv: [1., 0.] },
-            // bottom left
-            Vertex { pos: [x1, y2], color: [0., 0., 1., 1.], uv: [0., 1.] },
-            // bottom right
-            Vertex { pos: [x2, y2], color: [1., 1., 0., 1.], uv: [1., 1.] },
-        ];
+        let verts = if LIGHTMODE {
+            vec![
+                // top left
+                Vertex { pos: [x1, y1], color: [1., 0., 0., 1.], uv: [0., 0.] },
+                // top right
+                Vertex { pos: [x2, y1], color: [1., 0., 0., 1.], uv: [1., 0.] },
+                // bottom left
+                Vertex { pos: [x1, y2], color: [1., 0., 0., 1.], uv: [0., 1.] },
+                // bottom right
+                Vertex { pos: [x2, y2], color: [1., 0., 0., 1.], uv: [1., 1.] },
+            ]
+        } else {
+            vec![
+                // top left
+                Vertex { pos: [x1, y1], color: [1., 0., 0., 1.], uv: [0., 0.] },
+                // top right
+                Vertex { pos: [x2, y1], color: [1., 0., 1., 1.], uv: [1., 0.] },
+                // bottom left
+                Vertex { pos: [x1, y2], color: [0., 0., 1., 1.], uv: [0., 1.] },
+                // bottom right
+                Vertex { pos: [x2, y2], color: [1., 1., 0., 1.], uv: [1., 1.] },
+            ]
+        };
         let indices = vec![0, 2, 1, 1, 2, 3];
         drop(sg);
         let pimpl = Mesh::new(
@@ -487,10 +503,17 @@ impl App {
         node.set_property_f32("font_size", 40.).unwrap();
         node.set_property_str("text", "hello king!😁🍆jelly 🍆1234").unwrap();
         let prop = node.get_property("text_color").unwrap();
-        prop.set_f32(0, 1.).unwrap();
-        prop.set_f32(1, 1.).unwrap();
-        prop.set_f32(2, 1.).unwrap();
-        prop.set_f32(3, 1.).unwrap();
+        if LIGHTMODE {
+            prop.set_f32(0, 0.).unwrap();
+            prop.set_f32(1, 0.).unwrap();
+            prop.set_f32(2, 0.).unwrap();
+            prop.set_f32(3, 0.).unwrap();
+        } else {
+            prop.set_f32(0, 1.).unwrap();
+            prop.set_f32(1, 1.).unwrap();
+            prop.set_f32(2, 1.).unwrap();
+            prop.set_f32(3, 1.).unwrap();
+        }
         let prop = node.get_property("cursor_color").unwrap();
         prop.set_f32(0, 1.).unwrap();
         prop.set_f32(1, 0.5).unwrap();

+ 14 - 12
bin/darkwallet/src/ui/chatview.rs

@@ -289,7 +289,7 @@ impl ChatView {
                 // TODO we are maybe doing too many updates so make a widget to 'slow down'
                 // how often we move to fixed intervals.
                 // draw a poly shape and eval each line segment.
-                self.scroll.set(scroll + dist*0.05);
+                self.scroll.set(scroll + dist * 0.05);
                 self.scrollview().await;
             }
             TouchPhase::Ended => {
@@ -301,11 +301,12 @@ impl ChatView {
 
     /// Beware of this method. Here be dragons.
     /// Possibly racy so we limit it just to mouse stuff (for now).
-    fn cached_rect(&self) -> Rectangle {
+    fn cached_rect(&self) -> Option<Rectangle> {
         let Ok(rect) = read_rect(self.rect.clone()) else {
-            panic!("Node bad rect property");
+            error!(target: "ui::chatview", "cached_rect is None");
+            return None
         };
-        rect
+        Some(rect)
     }
     async fn get_parent_rect(&self) -> Option<Rectangle> {
         let sg = self.sg.lock().await;
@@ -318,7 +319,7 @@ impl ChatView {
     }
     async fn get_cached_world_rect(&self) -> Option<Rectangle> {
         // NBD if it's slightly wrong
-        let mut rect = self.cached_rect();
+        let mut rect = self.cached_rect()?;
 
         // If layers can be nested and we use offsets for (x, y)
         // then this will be incorrect for nested layers.
@@ -413,13 +414,12 @@ impl ChatView {
         let mut instrs =
             vec![DrawInstruction::ApplyViewport(rect), DrawInstruction::ApplyMatrix(model)];
         let drawcalls = self.drawcalls.lock().unwrap().clone();
-        let mut drawcalls: Vec<_> = drawcalls.into_iter().map(|dc| DrawInstruction::Draw(dc)).collect();
+        let mut drawcalls: Vec<_> =
+            drawcalls.into_iter().map(|dc| DrawInstruction::Draw(dc)).collect();
         instrs.append(&mut drawcalls);
 
-        let draw_calls = vec![(
-            self.dc_key,
-            DrawCall { instrs, dcs: vec![], z_index: self.z_index.get() },
-        )];
+        let draw_calls =
+            vec![(self.dc_key, DrawCall { instrs, dcs: vec![], z_index: self.z_index.get() })];
 
         self.render_api.replace_draw_calls(draw_calls).await;
 
@@ -542,8 +542,10 @@ impl ChatView {
         rect.y += parent_rect.y;
 
         let drawcalls = self.regen_mesh(rect.clone()).await;
-        let old_drawcalls = std::mem::replace(&mut *self.drawcalls.lock().unwrap(), drawcalls.clone());
-        let mut drawcalls: Vec<_> = drawcalls.into_iter().map(|dc| DrawInstruction::Draw(dc)).collect();
+        let old_drawcalls =
+            std::mem::replace(&mut *self.drawcalls.lock().unwrap(), drawcalls.clone());
+        let mut drawcalls: Vec<_> =
+            drawcalls.into_iter().map(|dc| DrawInstruction::Draw(dc)).collect();
 
         let mut freed_textures = vec![];
         let mut freed_buffers = vec![];

+ 9 - 5
bin/darkwallet/src/ui/editbox.rs

@@ -1104,11 +1104,12 @@ impl EditBox {
 
     /// Beware of this method. Here be dragons.
     /// Possibly racy so we limit it just to cursor scrolling.
-    fn cached_rect(&self) -> Rectangle {
+    fn cached_rect(&self) -> Option<Rectangle> {
         let Ok(rect) = read_rect(self.rect.clone()) else {
-            panic!("Node bad rect property");
+            error!(target: "ui::editbox", "cached_rect is None");
+            return None
         };
-        rect
+        Some(rect)
     }
     async fn get_parent_rect(&self) -> Option<Rectangle> {
         let sg = self.sg.lock().await;
@@ -1121,7 +1122,7 @@ impl EditBox {
     }
     async fn get_cached_world_rect(&self) -> Option<Rectangle> {
         // NBD if it's slightly wrong
-        let mut rect = self.cached_rect();
+        let mut rect = self.cached_rect()?;
 
         // If layers can be nested and we use offsets for (x, y)
         // then this will be incorrect for nested layers.
@@ -1139,7 +1140,10 @@ impl EditBox {
     /// to recalculate the scroll x property.
     fn apply_cursor_scrolling(&self) {
         // This may need updating but yolo rite
-        let rect = self.cached_rect();
+        let Some(rect) = self.cached_rect() else {
+            error!(target: "ui::editbox", "cached_rect() returned None");
+            return
+        };
 
         let cursor_pos = self.cursor_pos.get() as usize;
         let mut scroll = self.scroll.get();

+ 7 - 3
bin/darkwallet/src/ui/image.rs

@@ -17,10 +17,13 @@
  */
 
 //use async_lock::Mutex;
-use miniquad::{BufferId, TextureId};
 use image::ImageReader;
+use miniquad::{BufferId, TextureId};
 use rand::{rngs::OsRng, Rng};
-use std::{io::Cursor, sync::{Arc, Mutex as SyncMutex, Weak}};
+use std::{
+    io::Cursor,
+    sync::{Arc, Mutex as SyncMutex, Weak},
+};
 
 use crate::{
     gfx2::{DrawCall, DrawInstruction, DrawMesh, Rectangle, RenderApi, RenderApiPtr, Vertex},
@@ -113,7 +116,8 @@ impl Image {
             *data2.lock().unwrap() = res.unwrap();
         });
         let data = std::mem::take(&mut *data.lock().unwrap());
-        let img = ImageReader::new(Cursor::new(data)).with_guessed_format().unwrap().decode().unwrap();
+        let img =
+            ImageReader::new(Cursor::new(data)).with_guessed_format().unwrap().decode().unwrap();
         let img = img.to_rgba8();
 
         //let img = image::ImageReader::open(path).unwrap().decode().unwrap().to_rgba8();