Skip to content

Commit

Permalink
wallet: small UI tweaks and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfi committed Jan 6, 2025
1 parent 695ab91 commit 0bb067f
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 25 deletions.
5 changes: 5 additions & 0 deletions bin/darkwallet/java/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public String getExternalStoragePath() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}

public int getKeyboardHeight() {
Insets insets = view.getRootWindowInsets().getInsets(WindowInsets.Type.ime());
return insets.bottom;
}

//% END

//% QUAD_SURFACE_ON_CREATE_INPUT_CONNECTION
Expand Down
8 changes: 8 additions & 0 deletions bin/darkwallet/src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ pub fn cancel_composition() {
ndk_utils::call_void_method!(env, android::ACTIVITY, "cancelComposition", "()V");
}
}

pub fn get_keyboard_height() -> usize {
unsafe {
let env = android::attach_jni_env();

ndk_utils::call_int_method!(env, android::ACTIVITY, "getKeyboardHeight", "()I") as usize
}
}
126 changes: 108 additions & 18 deletions bin/darkwallet/src/app/schema/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,46 @@ pub async fn make(
let emoji_picker_node = node.clone();
layer_node.clone().link(node);

// Create the editbox bg
let node = create_vector_art("emoji_picker_bg");
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_dynamic_h_prop, 0, "dynamic_h");
node.set_property_u32(Role::App, "z_index", 2).unwrap();

let mut shape = VectorShape::new();
// Main bg
shape.add_filled_box(
expr::const_f32(0.),
expr::const_f32(0.),
expr::load_var("w"),
expr::load_var("h"),
[0., 0.11, 0.11, 1.],
);
// Top line
shape.add_filled_box(
expr::const_f32(EMOJI_BG_W),
expr::const_f32(0.),
expr::load_var("w"),
expr::const_f32(1.),
[0.41, 0.6, 0.65, 1.],
);
// Bottom line
//shape.add_filled_box(
// expr::const_f32(0.),
// cc.compile("h - 1").unwrap(),
// expr::load_var("w"),
// expr::load_var("h"),
// [0.41, 0.6, 0.65, 1.],
//);
let node =
node.setup(|me| VectorArt::new(me, shape, app.render_api.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");
Expand Down Expand Up @@ -535,13 +575,13 @@ pub async fn make(
[0.41, 0.6, 0.65, 1.],
);
// Bottom line
shape.add_filled_box(
expr::const_f32(0.),
cc.compile("h - 1").unwrap(),
expr::load_var("w"),
expr::load_var("h"),
[0.41, 0.6, 0.65, 1.],
);
//shape.add_filled_box(
// expr::const_f32(0.),
// cc.compile("h - 1").unwrap(),
// expr::load_var("w"),
// expr::load_var("h"),
// [0.41, 0.6, 0.65, 1.],
//);
let node =
node.setup(|me| VectorArt::new(me, shape, app.render_api.clone(), app.ex.clone())).await;
layer_node.clone().link(node);
Expand Down Expand Up @@ -597,7 +637,7 @@ pub async fn make(
node.set_property_bool(Role::App, "is_active", true).unwrap();
node.set_property_bool(Role::App, "is_focused", true).unwrap();

node.set_property_f32(Role::App, "max_height", 300.).unwrap();
node.set_property_f32(Role::App, "max_height", 600.).unwrap();

let prop = node.get_property("rect").unwrap();
prop.set_f32(Role::App, 0, CHATEDIT_LHS_PAD).unwrap();
Expand Down Expand Up @@ -719,6 +759,43 @@ pub async fn make(
});
app.tasks.lock().unwrap().push(listen_click);

// No way to get the top of the editbox until eval has been called.
// But this is on top so it happens before the eval. So the value is 0.
// Not sure the best way to fix this.
/*
// Create the editbox fg shadow
let node = create_vector_art("editbox_fg");
let prop = node.get_property("rect").unwrap();
prop.set_f32(Role::App, 0, EMOJI_BG_W).unwrap();
let code = cc.compile("editz_bg_top_y").unwrap();
prop.set_expr(Role::App, 1, code).unwrap();
prop.set_expr(Role::App, 2, expr::load_var("w")).unwrap();
prop.set_f32(Role::App, 3, 300.).unwrap();
//prop.set_expr(Role::App, 2, expr::load_var("w")).unwrap();
//prop.set_expr(Role::App, 3, expr::load_var("editz_bg_h")).unwrap();
node.set_property_u32(Role::App, "z_index", 4).unwrap();
prop.add_depend(&editbox_bg_rect_prop, 1, "editz_bg_top_y");
prop.add_depend(&editbox_bg_rect_prop, 3, "editz_bg_h");
let mut shape = VectorShape::new();
// Left hand darker box
shape.add_gradient_box(
expr::const_f32(0.),
expr::const_f32(0.),
expr::load_var("w"),
expr::const_f32(40.),
[
[0., 0., 0., 1.],
[0., 0., 0., 1.],
[0., 0., 0., 0.],
[0., 0., 0., 0.],
]
);
let node =
node.setup(|me| VectorArt::new(me, shape, app.render_api.clone(), app.ex.clone())).await;
layer_node.clone().link(node);
*/

// Create the send button
let node = create_button("send_btn");
node.set_property_bool(Role::App, "is_active", true).unwrap();
Expand Down Expand Up @@ -757,24 +834,37 @@ pub async fn make(
let listen_click = app.ex.spawn(async move {
while let Ok(_) = recvr.recv().await {
info!(target: "app::chat", "clicked emoji");

/*
miniquad::window::show_keyboard(true);
#[cfg(target_os = "android")]
let panel_height = crate::android::get_keyboard_height();
#[cfg(not(target_os = "android"))]
let panel_height = 400.;
miniquad::window::show_keyboard(false);
info!("panel_height = {panel_height}");
*/

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;
}
emoji_h_prop.set(400. as f32);
//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;
}
emoji_h_prop.set(0. as f32);
//for i in 1..=20 {
// emoji_h_prop.set((400 - 20 * i) as f32);
// msleep(10).await;
//}
}
}
});
Expand Down Expand Up @@ -842,8 +932,8 @@ pub async fn make(

let mut shape = VectorShape::new();

let color1 = [0., 0., 0., 0.4];
let color2 = [0., 0., 0., 0.9];
let color1 = [0., 0.13, 0.08, 0.75];
let color2 = [0., 0., 0., 1.];
let gradient = [color1.clone(), color1, color2.clone(), color2];
let hicolor = [0., 0.94, 1., 1.];

Expand Down
2 changes: 1 addition & 1 deletion bin/darkwallet/src/app/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod menu;
mod ui_consts {
pub const CHATDB_PATH: &str = "/data/data/darkfi.darkwallet/chatdb/";
pub const BG_PATH: &str = "bg.png";
pub const EMOJI_PICKER_ICON_SIZE: f32 = 100.;
pub const EMOJI_PICKER_ICON_SIZE: f32 = 140.;
}

#[cfg(all(
Expand Down
4 changes: 2 additions & 2 deletions bin/darkwallet/src/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ mod wrap;
pub use wrap::{glyph_str, wrap};

// Upscale emoji relative to font size
pub const EMOJI_SCALE_FACT: f32 = 1.5;
pub const EMOJI_SCALE_FACT: f32 = 1.6;
// How much of the emoji is above baseline?
pub const EMOJI_PROP_ABOVE_BASELINE: f32 = 0.75;
pub const EMOJI_PROP_ABOVE_BASELINE: f32 = 0.8;

// From https://sourceforge.net/projects/freetype/files/freetype2/2.6/
//
Expand Down
8 changes: 4 additions & 4 deletions bin/darkwallet/src/ui/chatedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,10 @@ impl ChatEdit {
// .lock()
// .editable
// .set_text("".to_string(), "king!😁🍆jelly 🍆1234".to_string());
//self_.text_wrap.lock().editable.set_text(
// "".to_string(),
// "A berry is a small, pulpy, and often edible fruit. Typically, berries are juicy, rounded, brightly colored, sweet, sour or tart, and do not have a stone or pit, although many pips or seeds may be present. Common examples of berries in the culinary sense are strawberries, raspberries, blueberries, blackberries, white currants, blackcurrants, and redcurrants. In Britain, soft fruit is a horticultural term for such fruits.".to_string()
//);
self_.text_wrap.lock().editable.set_text(
"".to_string(),
"A berry is a small, pulpy, and often edible fruit. Typically, berries are juicy, rounded, brightly colored, sweet, sour or tart, and do not have a stone or pit, although many pips or seeds may be present. Common examples of berries in the culinary sense are strawberries, raspberries, blueberries, blackberries, white currants, blackcurrants, and redcurrants. In Britain, soft fruit is a horticultural term for such fruits. The common usage of the term berry is different from the scientific or botanical definition of a berry, which refers to a fruit produced from the ovary of a single flower where the outer layer of the ovary wall develops into an edible fleshy portion (pericarp). The botanical definition includes many fruits that are not commonly known or referred to as berries, such as grapes, tomatoes, cucumbers, eggplants, bananas, and chili peppers.".to_string()
);
//self_
// .text_wrap
// .lock()
Expand Down

0 comments on commit 0bb067f

Please sign in to comment.