Эх сурвалжийг харах

app: wire the settings screen into schema

darkfi 2 долоо хоног өмнө
parent
commit
87818b0281

+ 67 - 2
bin/app/src/app/schema/menu/mod.rs

@@ -67,6 +67,7 @@ mod android_ui_consts {
     pub const BTN_TEXT_Y: f32 = 30.;
     pub const LABEL_LINESPACE: f32 = 60.;
     pub const MENU_ICON_SCALE: f32 = 220.;
+    pub const SETTINGS_ICON_SCALE: f32 = 55.;
 }
 
 #[cfg(target_os = "android")]
@@ -108,6 +109,7 @@ mod ui_consts {
     pub const BTN_TEXT_Y: f32 = 14.;
     pub const LABEL_LINESPACE: f32 = 140.;
     pub const MENU_ICON_SCALE: f32 = 100.;
+    pub const SETTINGS_ICON_SCALE: f32 = 28.;
 }
 
 pub mod channel;
@@ -576,7 +578,9 @@ pub async fn setup_wallet_button(app: &App, chat_layer: SceneNodePtr, i18n_fish:
     let prop = node.get_property("rect").unwrap();
     let code = cc.compile("w - MENU_BTN_W_R / 2 - CHANNEL_LABEL_X").unwrap();
     prop.set_default_expr(0, code).unwrap();
-    let code = cc.compile("h - MENU_BTN_H - MENU_BTN_W_R / 2 - CHANNEL_LABEL_X").unwrap();
+    let code = cc
+        .compile("h - CHANNEL_LABEL_X - 3 * MENU_BTN_W_R - 2 * CHANNEL_LABEL_X + MENU_BTN_W_R / 2")
+        .unwrap();
     prop.set_default_expr(1, code).unwrap();
     prop.set_default_f32(2, 1.).unwrap();
     prop.set_default_f32(3, 1.).unwrap();
@@ -597,7 +601,7 @@ pub async fn setup_wallet_button(app: &App, chat_layer: SceneNodePtr, i18n_fish:
     let prop = node.get_property("rect").unwrap();
     let code = cc.compile("w - MENU_BTN_W_R - CHANNEL_LABEL_X").unwrap();
     prop.set_default_expr(0, code).unwrap();
-    let code = cc.compile("h - MENU_BTN_H - MENU_BTN_W_R - CHANNEL_LABEL_X").unwrap();
+    let code = cc.compile("h - CHANNEL_LABEL_X - 3 * MENU_BTN_W_R - 2 * CHANNEL_LABEL_X").unwrap();
     prop.set_default_expr(1, code).unwrap();
     prop.set_default_f32(2, MENU_BTN_W_R).unwrap();
     prop.set_default_f32(3, MENU_BTN_W_R).unwrap();
@@ -629,3 +633,64 @@ pub async fn setup_wallet_button(app: &App, chat_layer: SceneNodePtr, i18n_fish:
     let node = node.setup(|me| Button::new(me, renderer, redraw)).await;
     menu_layer.link(node);
 }
+
+pub async fn setup_settings_button(app: &App, chat_layer: SceneNodePtr) {
+    let atom = &mut PropertyAtomicGuard::none();
+    let mut cc = expr::Compiler::new();
+    cc.add_const_f32("MENU_BTN_W_R", MENU_BTN_W_R);
+    cc.add_const_f32("CHANNEL_LABEL_X", CHANNEL_LABEL_X);
+    cc.add_const_f32("SETTINGS_ICON_SCALE", SETTINGS_ICON_SCALE);
+
+    let menu_layer = chat_layer.lookup_node("/menu_layer").unwrap();
+
+    // Settings icon
+    let node = create_vector_art("settings_icon");
+    let prop = node.get_property("rect").unwrap();
+    let code = cc.compile("w - MENU_BTN_W_R / 2 - CHANNEL_LABEL_X").unwrap();
+    prop.set_default_expr(0, code).unwrap();
+    let code = cc
+        .compile("h - CHANNEL_LABEL_X - 2 * MENU_BTN_W_R - CHANNEL_LABEL_X + MENU_BTN_W_R / 2")
+        .unwrap();
+    prop.set_default_expr(1, code).unwrap();
+    prop.set_default_f32(2, SETTINGS_ICON_SCALE).unwrap();
+    prop.set_default_f32(3, SETTINGS_ICON_SCALE).unwrap();
+    node.set_property_u32(atom, Role::App, "z_index", 3).unwrap();
+    let shape = shape::create_settings(COLOR_CYAN).scaled(SETTINGS_ICON_SCALE);
+    node.set_property_shape(atom, Role::App, "shape", shape).unwrap();
+    let node =
+        node.setup(|me| VectorArt::new(me, app.renderer.clone(), app.redraw_trigger.clone())).await;
+    menu_layer.link(node);
+
+    // Settings button
+    let node = create_button("settings_btn");
+    node.set_property_bool(atom, Role::App, "is_active", true).unwrap();
+    let prop = node.get_property("rect").unwrap();
+    let code = cc.compile("w - MENU_BTN_W_R - CHANNEL_LABEL_X").unwrap();
+    prop.set_default_expr(0, code).unwrap();
+    let code = cc.compile("h - CHANNEL_LABEL_X - 2 * MENU_BTN_W_R - CHANNEL_LABEL_X").unwrap();
+    prop.set_default_expr(1, code).unwrap();
+    prop.set_default_f32(2, MENU_BTN_W_R).unwrap();
+    prop.set_default_f32(3, MENU_BTN_W_R).unwrap();
+    //node.set_property_bool(atom, Role::App, "debug", true).unwrap();
+
+    let (slot, recvr) = Slot::new("settings_clicked");
+    node.register("click", slot).unwrap();
+    let sg_root = app.sg_root.clone();
+    let redraw = app.redraw_trigger.clone();
+    let listen_click = app.ex.spawn(async move {
+        while let Ok(_) = recvr.recv().await {
+            let atom = &mut redraw.make_guard(gfxtag!("settings_click"));
+            let settings_node = sg_root.lookup_node("/window/content/settings_layer").unwrap();
+            settings_node.set_property_bool(atom, Role::App, "is_visible", true).unwrap();
+            let chat_node = sg_root.lookup_node("/window/content/chat").unwrap();
+            chat_node.set_property_bool(atom, Role::App, "is_visible", false).unwrap();
+        }
+    });
+    app.tasks.lock().push(listen_click);
+
+    let renderer = app.renderer.clone();
+    let redraw = app.redraw_trigger.clone();
+
+    let node = node.setup(|me| Button::new(me, renderer, redraw)).await;
+    menu_layer.link(node);
+}

+ 6 - 12
bin/app/src/app/schema/mod.rs

@@ -41,17 +41,11 @@ use crate::{
 mod chat;
 pub mod menu;
 use menu::channel::Channel;
+mod settings;
 pub mod test;
 pub mod test_chatview;
 pub mod test_edit;
 pub mod test_scroll_layer;
-// The settings screen is currently dormant: it was unwired from the
-// schema before the theming change and awaits revival. The module stays
-// declared (and therefore compile-checked against current APIs) with
-// its enum cycle-on-tap row ready; see task 8.2 of the app-theme
-// change. Re-link `settings::make` into a schema entry point to revive.
-#[allow(dead_code)]
-mod settings;
 mod wallet;
 
 macro_rules! i { ($($arg:tt)*) => { info!(target: "app::schema", $($arg)*); } }
@@ -63,7 +57,6 @@ mod android_ui_consts {
     pub const MAIN_MENU_PADDING: f32 = 20.;
     pub const SWITCH_THEME_BTN_H: f32 = 100.;
     pub const NETSTATUS_ICON_SIZE: f32 = 140.;
-    pub const SETTINGS_ICON_SIZE: f32 = 140.;
     pub const NETLOGO_SCALE: f32 = 50.;
     pub const EMOJI_PICKER_ICON_SIZE: f32 = 120.;
     pub const EMOJI_PICKER_ICON_MARGIN_X: f32 = 20.;
@@ -155,7 +148,6 @@ mod ui_consts {
     pub const MAIN_MENU_PADDING: f32 = 10.;
     pub const SWITCH_THEME_BTN_H: f32 = 50.;
     pub const NETSTATUS_ICON_SIZE: f32 = 60.;
-    pub const SETTINGS_ICON_SIZE: f32 = 60.;
     pub const NETLOGO_SCALE: f32 = 25.;
     pub const EMOJI_PICKER_ICON_SIZE: f32 = 40.;
     pub const EMOJI_PICKER_ICON_MARGIN_X: f32 = 8.;
@@ -265,7 +257,6 @@ pub async fn make(
     cc.add_const_f32("MAIN_MENU_PADDING", MAIN_MENU_PADDING);
     cc.add_const_f32("MAIN_MENU_HEADER_HEIGHT", MAIN_MENU_HEADER_HEIGHT);
     cc.add_const_f32("NETSTATUS_ICON_SIZE", NETSTATUS_ICON_SIZE);
-    cc.add_const_f32("SETTINGS_ICON_SIZE", SETTINGS_ICON_SIZE);
     cc.add_const_f32("NETSTAT_OVERLAY_MARGIN", NETSTAT_OVERLAY_MARGIN);
     cc.add_const_f32("NETSTAT_OVERLAY_BTN_W", NETSTAT_OVERLAY_BTN_W);
     cc.add_const_f32("NETSTAT_OVERLAY_BTN_H", NETSTAT_OVERLAY_BTN_H);
@@ -1180,8 +1171,11 @@ pub async fn make(
 
     wallet::make(app, content.clone(), i18n_fish).await;
 
-    // Setup wallet button after wallet layer is created
-    menu::setup_wallet_button(app, chat_layer, i18n_fish).await;
+    settings::make(app, content.clone(), i18n_fish).await;
+
+    // Setup the wallet and settings buttons after their target layers exist
+    menu::setup_wallet_button(app, chat_layer.clone(), i18n_fish).await;
+    menu::setup_settings_button(app, chat_layer).await;
 
     // @@@ Debug stuff @@@
     //let chatview_node = app.sg_root.lookup_node("/window/content/chat/dev_chat_layer").unwrap();

+ 2 - 2
bin/app/src/shape/mod.rs

@@ -72,8 +72,8 @@ pub use down_bgtab::create_down_bgtab;
 mod down_arrow;
 pub use down_arrow::create_down_arrow;
 
-//mod settings;
-//pub use settings::{create_right_border, create_settings};
+mod settings;
+pub use settings::create_settings;
 
 //mod switch;
 //pub use switch::create_switch;