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

wallet: add empty ChatView stub struct

darkfi 2 лет назад
Родитель
Сommit
40b4280170

+ 48 - 1
bin/darkwallet/src/app.rs

@@ -8,7 +8,7 @@ use crate::{
     prop::{Property, PropertySubType, PropertyType},
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId, SceneNodeType},
     text2::TextShaperPtr,
-    ui::{EditBox, Mesh, RenderLayer, Stoppable, Text, Window},
+    ui::{ChatView, EditBox, Mesh, RenderLayer, Stoppable, Text, Window},
 };
 
 //fn print_type_of<T>(_: &T) {
@@ -377,6 +377,36 @@ impl App {
         node.pimpl = pimpl;
 
         sg.link(node_id, layer_node_id).unwrap();
+
+        // ChatView
+        let node_id = create_chatview(&mut sg, "chatty");
+        let node = sg.get_node(node_id).unwrap();
+        let prop = node.get_property("rect").unwrap();
+        prop.set_f32(0, 0.).unwrap();
+        prop.set_f32(1, 0.).unwrap();
+        let code = vec![Op::LoadVar("lw".to_string())];
+        prop.set_expr(2, code).unwrap();
+        let code = vec![Op::Sub((
+            Box::new(Op::LoadVar("lh".to_string())),
+            Box::new(Op::ConstFloat32(50.)),
+        ))];
+        prop.set_expr(3, code).unwrap();
+        node.set_property_u32("z_index", 1).unwrap();
+
+        drop(sg);
+        let pimpl = ChatView::new().await;
+        let mut sg = self.sg.lock().await;
+        let node = sg.get_node_mut(node_id).unwrap();
+        node.pimpl = pimpl;
+
+        sg.link(node_id, layer_node_id).unwrap();
+
+        // On android lets scale the UI up
+        // TODO: add support for fractional scaling
+        // This also affects mouse/touch input since coords need to be accurately translated
+        // Also we need to think about nesting of layers.
+        //let window_node = sg.get_node_mut(window_id).unwrap();
+        //win_node.set_property_f32("scale", 1.6).unwrap();
     }
 
     async fn trigger_redraw(&self) {
@@ -506,3 +536,20 @@ fn create_editbox(sg: &mut SceneGraph, name: &str) -> SceneNodeId {
 
     node.id
 }
+
+fn create_chatview(sg: &mut SceneGraph, name: &str) -> SceneNodeId {
+    let node = sg.add_node(name, SceneNodeType::ChatView);
+
+    let mut prop = Property::new("rect", PropertyType::Float32, PropertySubType::Pixel);
+    prop.set_array_len(4);
+    prop.allow_exprs();
+    node.add_property(prop).unwrap();
+
+    let mut prop = Property::new("z_index", PropertyType::Uint32, PropertySubType::Null);
+    node.add_property(prop).unwrap();
+
+    let mut prop = Property::new("debug", PropertyType::Bool, PropertySubType::Null);
+    node.add_property(prop).unwrap();
+
+    node.id
+}

+ 1 - 2
bin/darkwallet/src/scene.rs

@@ -627,13 +627,12 @@ pub struct Method {
 
 pub enum Pimpl {
     Null,
-    //EditBox(editbox::EditBoxPtr),
-    //ChatView(chatview::ChatViewPtr),
     Window(ui::WindowPtr),
     RenderLayer(ui::RenderLayerPtr),
     Mesh(ui::MeshPtr),
     Text(ui::TextPtr),
     EditBox(ui::EditBoxPtr),
+    ChatView(ui::ChatViewPtr),
 }
 
 impl std::fmt::Debug for SceneNode {

+ 41 - 0
bin/darkwallet/src/ui/chatview.rs

@@ -0,0 +1,41 @@
+use rand::{rngs::OsRng, Rng};
+use std::sync::Arc;
+
+use crate::{
+    error::Result,
+    gfx2::{
+        DrawCall, DrawInstruction, DrawMesh, GraphicsEventPublisherPtr, Point, Rectangle,
+        RenderApi, RenderApiPtr, Vertex,
+    },
+    mesh::{Color, MeshBuilder, MeshInfo, COLOR_BLUE, COLOR_WHITE},
+    prop::{
+        PropertyBool, PropertyColor, PropertyFloat32, PropertyPtr, PropertyStr, PropertyUint32,
+    },
+    pubsub::Subscription,
+    scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
+    text2::{self, Glyph, GlyphPositionIter, RenderedAtlas, SpritePtr, TextShaper, TextShaperPtr},
+    util::zip3,
+};
+
+use super::{eval_rect, get_parent_rect, read_rect, DrawUpdate, OnModify, Stoppable};
+
+pub type ChatViewPtr = Arc<ChatView>;
+
+pub struct ChatView {
+    dc_key: u64,
+}
+
+impl ChatView {
+    pub async fn new() -> Pimpl {
+        let self_ = Arc::new(Self { dc_key: OsRng.gen() });
+
+        Pimpl::ChatView(self_)
+    }
+
+    pub async fn draw(&self, sg: &SceneGraph, parent_rect: &Rectangle) -> Option<DrawUpdate> {
+        Some(DrawUpdate {
+            key: self.dc_key,
+            draw_calls: vec![(self.dc_key, DrawCall { instrs: vec![], dcs: vec![], z_index: 0 })],
+        })
+    }
+}

+ 1 - 0
bin/darkwallet/src/ui/layer.rs

@@ -121,6 +121,7 @@ impl RenderLayer {
                 Pimpl::Mesh(mesh) => mesh.draw(&sg, &rect),
                 Pimpl::Text(txt) => txt.draw(&sg, &rect).await,
                 Pimpl::EditBox(editb) => editb.draw(&sg, &rect).await,
+                Pimpl::ChatView(chat) => chat.draw(&sg, &rect).await,
                 _ => {
                     error!(target: "ui::layer", "unhandled pimpl type");
                     continue

+ 2 - 0
bin/darkwallet/src/ui/mod.rs

@@ -8,6 +8,8 @@ use crate::{
     scene::{SceneGraph, SceneNode, SceneNodeId, SceneNodeType},
 };
 
+mod chatview;
+pub use chatview::{ChatView, ChatViewPtr};
 mod editbox;
 pub use editbox::{EditBox, EditBoxPtr};
 mod mesh;