Skip to content

Commit

Permalink
wallet: add emoji picker widget (unimpl) and connect hide/show button
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfi committed Jan 4, 2025
1 parent 7251272 commit 0f1eac3
Show file tree
Hide file tree
Showing 10 changed files with 396 additions and 19 deletions.
38 changes: 38 additions & 0 deletions bin/darkwallet/data/close.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Blender 4.3.1
# www.blender.org
mtllib close.mtl
o close
v 0.000000 0.000000 0.000000
v 0.000000 0.000000 -0.194555
v 0.194555 0.000000 0.000000
v 0.550000 0.000000 -0.744555
v 0.744555 0.000000 -0.550000
v 0.000000 0.000000 0.000000
v -0.194555 0.000000 0.000000
v -0.550000 0.000000 -0.744555
v -0.744555 0.000000 -0.550000
v 0.000000 0.000000 0.000000
v 0.000000 0.000000 0.194555
v 0.550000 0.000000 0.744555
v 0.744555 0.000000 0.550000
v 0.000000 0.000000 0.000000
v -0.550000 0.000000 0.744555
v -0.744555 0.000000 0.550000
vn -0.0000 1.0000 -0.0000
vn -0.0000 -1.0000 -0.0000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
s 0
f 1/1/1 3/2/1 2/3/1
f 3/2/1 4/3/1 2/3/1
f 6/1/2 7/2/2 2/3/2
f 7/2/2 8/3/2 2/3/2
f 10/1/2 3/2/2 11/3/2
f 3/2/2 12/3/2 11/3/2
f 14/1/1 7/2/1 11/3/1
f 7/2/1 15/3/1 11/3/1
f 3/2/1 5/2/1 4/3/1
f 7/2/2 9/2/2 8/3/2
f 3/2/2 13/2/2 12/3/2
f 7/2/1 16/2/1 15/3/1
19 changes: 19 additions & 0 deletions bin/darkwallet/src/app/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pub fn create_vector_art(name: &str) -> SceneNode {
debug!(target: "app", "create_vector_art({name})");
let mut node = SceneNode::new(name, SceneNodeType::VectorArt);

let mut prop = Property::new("is_visible", PropertyType::Bool, PropertySubType::Null);
prop.set_defaults_bool(vec![true]).unwrap();
node.add_property(prop).unwrap();

let mut prop = Property::new("rect", PropertyType::Float32, PropertySubType::Pixel);
prop.set_array_len(4);
prop.allow_exprs();
Expand Down Expand Up @@ -474,3 +478,18 @@ pub fn create_chatview(name: &str) -> SceneNode {

node
}

pub fn create_emoji_picker(name: &str) -> SceneNode {
debug!(target: "app", "create_emoji_picker({name})");
let mut node = SceneNode::new(name, SceneNodeType::Image);

let mut prop = Property::new("rect", PropertyType::Float32, PropertySubType::Pixel);
prop.set_array_len(4);
prop.allow_exprs();
node.add_property(prop).unwrap();

let prop = Property::new("z_index", PropertyType::Uint32, PropertySubType::Null);
node.add_property(prop).unwrap();

node
}
94 changes: 89 additions & 5 deletions bin/darkwallet/src/app/schema/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use darkfi::system::msleep;
use sled_overlay::sled;

use crate::{
app::{
node::{
create_button, create_chatedit, create_chatview, create_editbox, create_image,
create_layer, create_text, create_vector_art,
create_button, create_chatedit, create_chatview, create_editbox, create_emoji_picker,
create_image, create_layer, create_text, create_vector_art,
},
populate_tree, App,
},
Expand All @@ -37,8 +38,8 @@ use crate::{
shape,
text::TextShaperPtr,
ui::{
Button, ChatEdit, ChatView, EditBox, Image, Layer, ShapeVertex, Text, VectorArt,
VectorShape, Window,
Button, ChatEdit, ChatView, EditBox, EmojiPicker, Image, Layer, ShapeVertex, Text,
VectorArt, VectorShape, Window,
},
ExecutorPtr,
};
Expand Down Expand Up @@ -69,6 +70,7 @@ mod android_ui_consts {
pub const EMOJI_SCALE: f32 = 40.;
pub const EMOJI_NEG_Y: f32 = 85.;
pub const EMOJIBTN_BOX: [f32; 4] = [20., 118., 80., 75.];
pub const EMOJI_CLOSE_SCALE: f32 = 20.;
pub const SENDARROW_NEG_X: f32 = 50.;
pub const SENDARROW_NEG_Y: f32 = 80.;
pub const SENDBTN_BOX: [f32; 4] = [86., 120., 80., 70.];
Expand Down Expand Up @@ -128,6 +130,7 @@ mod ui_consts {
pub const EMOJI_SCALE: f32 = 20.;
pub const EMOJI_NEG_Y: f32 = 34.;
pub const EMOJIBTN_BOX: [f32; 4] = [16., 50., 44., 36.];
pub const EMOJI_CLOSE_SCALE: f32 = 10.;
pub const SENDARROW_NEG_X: f32 = 50.;
pub const SENDARROW_NEG_Y: f32 = 32.;
pub const SENDBTN_BOX: [f32; 4] = [72., 50., 45., 34.];
Expand Down Expand Up @@ -257,7 +260,6 @@ pub async fn make(app: &App, window: SceneNodePtr, channel: &str, db: &sled::Db)
prop.set_f32(Role::App, 1, 0.).unwrap();
prop.set_expr(Role::App, 2, expr::load_var("w")).unwrap();
prop.set_f32(Role::App, 3, CHATEDIT_HEIGHT).unwrap();
node.set_property_u32(Role::App, "z_index", 2).unwrap();
node.set_property_f32(Role::App, "baseline", CHANNEL_LABEL_BASELINE).unwrap();
node.set_property_f32(Role::App, "font_size", FONTSIZE).unwrap();
node.set_property_str(Role::App, "text", &("#".to_string() + channel)).unwrap();
Expand All @@ -283,6 +285,52 @@ pub async fn make(app: &App, window: SceneNodePtr, channel: &str, db: &sled::Db)
.await;
layer_node.clone().link(node);

// Create the emoji picker
let mut node = create_emoji_picker("emoji_picker");
let prop = Property::new("dynamic_h", PropertyType::Float32, PropertySubType::Pixel);
node.add_property(prop).unwrap();
let emoji_h_prop = node.get_property("dynamic_h").unwrap();
let prop = node.get_property("rect").unwrap();
prop.set_f32(Role::App, 0, 0.).unwrap();
let code = cc.compile("h - dynamic_h").unwrap();
prop.set_expr(Role::App, 1, code).unwrap();
prop.set_expr(Role::App, 2, expr::load_var("w")).unwrap();
prop.set_expr(Role::App, 3, expr::load_var("dynamic_h")).unwrap();
prop.add_depend(&emoji_h_prop, 0, "dynamic_h");
let emoji_h_prop = PropertyFloat32::wrap(&node, Role::App, "dynamic_h", 0).unwrap();
let emoji_rect_prop = prop;
//node.set_property_f32(Role::App, "baseline", CHANNEL_LABEL_BASELINE).unwrap();
//node.set_property_f32(Role::App, "font_size", FONTSIZE).unwrap();
node.set_property_u32(Role::App, "z_index", 2).unwrap();
let node = node
.setup(|me| {
EmojiPicker::new(
me,
window_scale.clone(),
app.render_api.clone(),
app.text_shaper.clone(),
app.ex.clone(),
)
})
.await;
layer_node.clone().link(node);

// Main content view
let chat_layer_node = layer_node;
let layer_node = create_layer("content");
let prop = layer_node.get_property("rect").unwrap();
prop.set_f32(Role::App, 0, 0.).unwrap();
prop.set_f32(Role::App, 1, 0.).unwrap();
prop.set_expr(Role::App, 2, expr::load_var("w")).unwrap();
let code = cc.compile("h - emoji_h").unwrap();
prop.set_expr(Role::App, 3, code).unwrap();
prop.add_depend(&emoji_rect_prop, 3, "emoji_h");
layer_node.set_property_bool(Role::App, "is_visible", true).unwrap();
layer_node.set_property_u32(Role::App, "z_index", 1).unwrap();
let layer_node =
layer_node.setup(|me| Layer::new(me, app.render_api.clone(), app.ex.clone())).await;
chat_layer_node.link(layer_node.clone());

// ChatView
let node = create_chatview("chatty");
let prop = node.get_property("rect").unwrap();
Expand Down Expand Up @@ -468,6 +516,7 @@ pub async fn make(app: &App, window: SceneNodePtr, channel: &str, db: &sled::Db)

// Create the emoji button
let node = create_vector_art("emoji_btn_bg");
let emoji_btn_is_visible = PropertyBool::wrap(&node, Role::App, "is_visible", 0).unwrap();
let prop = node.get_property("rect").unwrap();
prop.set_f32(Role::App, 0, EMOJI_BTN_X).unwrap();
let code = cc.compile("h - EMOJI_NEG_Y").unwrap();
Expand All @@ -480,6 +529,22 @@ pub async fn make(app: &App, window: SceneNodePtr, channel: &str, db: &sled::Db)
node.setup(|me| VectorArt::new(me, shape, app.render_api.clone(), app.ex.clone())).await;
layer_node.clone().link(node);

// Create the emoji button
let node = create_vector_art("emoji_close_btn_bg");
node.set_property_bool(Role::App, "is_visible", false).unwrap();
let prop = node.get_property("rect").unwrap();
let emoji_close_is_visible = PropertyBool::wrap(&node, Role::App, "is_visible", 0).unwrap();
prop.set_f32(Role::App, 0, EMOJI_BTN_X).unwrap();
let code = cc.compile("h - EMOJI_NEG_Y").unwrap();
prop.set_expr(Role::App, 1, code).unwrap();
prop.set_f32(Role::App, 2, 500.).unwrap();
prop.set_f32(Role::App, 3, 500.).unwrap();
node.set_property_u32(Role::App, "z_index", 3).unwrap();
let shape = shape::create_close_icon().scaled(EMOJI_CLOSE_SCALE);
let node =
node.setup(|me| VectorArt::new(me, shape, app.render_api.clone(), app.ex.clone())).await;
layer_node.clone().link(node);

// Text edit
let node = create_chatedit("editz");
node.set_property_bool(Role::App, "is_active", true).unwrap();
Expand Down Expand Up @@ -635,6 +700,25 @@ pub async fn make(app: &App, window: SceneNodePtr, channel: &str, db: &sled::Db)
let listen_click = app.ex.spawn(async move {
while let Ok(_) = recvr.recv().await {
info!(target: "app::chat", "clicked emoji");
if emoji_btn_is_visible.get() {
assert!(!emoji_close_is_visible.get());
assert!(emoji_h_prop.get() < 0.001);
emoji_btn_is_visible.set(false);
emoji_close_is_visible.set(true);
for i in 1..=20 {
emoji_h_prop.set((20 * i) as f32);
msleep(10).await;
}
} else {
assert!(emoji_close_is_visible.get());
assert!(emoji_h_prop.get() > 0.);
emoji_btn_is_visible.set(true);
emoji_close_is_visible.set(false);
for i in 1..=20 {
emoji_h_prop.set((400 - 20 * i) as f32);
msleep(10).await;
}
}
}
});
app.tasks.lock().unwrap().push(listen_click);
Expand Down
5 changes: 5 additions & 0 deletions bin/darkwallet/src/prop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ impl Property {
}
Ok(())
}
pub fn set_defaults_bool(&mut self, defaults: Vec<bool>) -> Result<()> {
self.check_defaults_len(defaults.len())?;
self.defaults = defaults.into_iter().map(|v| PropertyValue::Bool(v)).collect();
Ok(())
}
pub fn set_defaults_u32(&mut self, defaults: Vec<u32>) -> Result<()> {
self.check_defaults_len(defaults.len())?;
self.defaults = defaults.into_iter().map(|v| PropertyValue::Uint32(v)).collect();
Expand Down
1 change: 1 addition & 0 deletions bin/darkwallet/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,5 @@ pub enum Pimpl {
ChatView(ui::ChatViewPtr),
Image(ui::ImagePtr),
Button(ui::ButtonPtr),
EmojiPicker(ui::EmojiPickerPtr),
}
27 changes: 27 additions & 0 deletions bin/darkwallet/src/shape/close.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::ui::{ShapeVertex, VectorShape};
pub fn create_close_icon() -> VectorShape {
VectorShape {
verts: vec![
ShapeVertex::from_xy(0.0, 0.0, [0., 1., 1., 1.]),
ShapeVertex::from_xy(0.0, -0.194555, [0., 1., 1., 1.]),
ShapeVertex::from_xy(0.194555, 0.0, [0., 1., 1., 1.]),
ShapeVertex::from_xy(0.55, -0.744555, [0., 1., 1., 1.]),
ShapeVertex::from_xy(0.744555, -0.55, [0., 1., 1., 1.]),
ShapeVertex::from_xy(0.0, 0.0, [0., 1., 1., 1.]),
ShapeVertex::from_xy(-0.194555, 0.0, [0., 1., 1., 1.]),
ShapeVertex::from_xy(-0.55, -0.744555, [0., 1., 1., 1.]),
ShapeVertex::from_xy(-0.744555, -0.55, [0., 1., 1., 1.]),
ShapeVertex::from_xy(0.0, 0.0, [0., 1., 1., 1.]),
ShapeVertex::from_xy(0.0, 0.194555, [0., 1., 1., 1.]),
ShapeVertex::from_xy(0.55, 0.744555, [0., 1., 1., 1.]),
ShapeVertex::from_xy(0.744555, 0.55, [0., 1., 1., 1.]),
ShapeVertex::from_xy(0.0, 0.0, [0., 1., 1., 1.]),
ShapeVertex::from_xy(-0.55, 0.744555, [0., 1., 1., 1.]),
ShapeVertex::from_xy(-0.744555, 0.55, [0., 1., 1., 1.]),
],
indices: vec![
0, 2, 1, 2, 3, 1, 5, 6, 1, 6, 7, 1, 9, 2, 10, 2, 11, 10, 13, 6, 10, 6, 14, 10, 2, 4, 3,
6, 8, 7, 2, 12, 11, 6, 15, 14,
],
}
}
3 changes: 3 additions & 0 deletions bin/darkwallet/src/shape/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use crate::ui::{ShapeVertex, VectorShape};
mod back_arrow;
pub use back_arrow::create_back_arrow;

mod close;
pub use close::create_close_icon;

mod send_arrow;
pub use send_arrow::create_send_arrow;

Expand Down
Loading

0 comments on commit 0f1eac3

Please sign in to comment.