Bläddra i källkod

app: made styling fixes to settings manager

darkfi 1 vecka sedan
förälder
incheckning
f70feec55d

+ 2 - 0
bin/app/pydrk/api.py

@@ -547,6 +547,8 @@ class Api:
                     return (PropertyStatus.EXPR, Expr(serial.decode_str(cur)))
                 case PropertyStatus.UNSET | PropertyStatus.OK:
                     return (prop_status, Api.read_prop_val(cur, prop_type))
+                case _:
+                    raise Exception(f"unknown property status returned: {prop_status} (desynced stream?)")
 
         return serial.decode_arr(cur, prop_read_fn)
 

+ 6 - 26
bin/app/src/app/mod.rs

@@ -114,46 +114,26 @@ impl App {
         let i18n_fish = self.setup_locale();
 
         let window = create_window("window");
-        #[cfg(target_os = "android")]
-        let base_scale = {
-            let screen_density = miniquad::window::dpi_scale();
-            i!("Android screen density: {screen_density}");
-            screen_density / 3.5
-        };
-        #[cfg(not(target_os = "android"))]
-        let base_scale = 1.;
-
-        let setting_node = self.sg_root.lookup_node("/setting").unwrap();
-        let win_scale_setting =
-            PropertyFloat32::wrap(&setting_node, Role::Internal, "win.scale", 0).unwrap();
-        let is_valid_scale = |scale: f32| scale > 0. && scale.is_finite();
-        let saved_scale = win_scale_setting.get();
-        let saved_scale = if is_valid_scale(saved_scale) {
-            saved_scale
-        } else {
-            warn!(target: "app", "Invalid persisted win.scale: {saved_scale}, falling back to 1.");
-            1.
-        };
-        let window_scale = base_scale * saved_scale;
-
-        d!("Setting window scale to {window_scale}");
-        let prop = window.get_property("scale").unwrap();
-        let atom = &mut PropertyAtomicGuard::none();
-        prop.set_f32(atom, Role::App, 0, window_scale).unwrap();
 
         #[cfg(target_os = "android")]
         {
             let insets = android::insets::get_insets();
             d!("Setting window insets to {insets:?}");
             let prop = window.get_property("insets").unwrap();
+            let atom = &mut PropertyAtomicGuard::none();
             for i in 0..4 {
                 prop.set_f32(atom, Role::App, i, insets[i]).unwrap();
             }
         }
+
+        let setting_node = self.sg_root.lookup_node("/setting").unwrap();
+        let window_scale =
+            PropertyFloat32::wrap(&setting_node, Role::Internal, "win.scale", 0).unwrap();
         let window = window
             .setup(|me| {
                 Window::new(
                     me,
+                    window_scale.clone(),
                     self.renderer.clone(),
                     i18n_fish.clone(),
                     self.ex.clone(),

+ 0 - 5
bin/app/src/app/node.rs

@@ -72,11 +72,6 @@ pub fn create_window(name: &str) -> SceneNode {
     prop.set_defaults_f32(vec![0., 0., 0., 0.]).unwrap();
     node.add_property(prop).unwrap();
 
-    let mut prop = Property::new("scale", PropertyType::Float32, PropertySubType::Null, PERM_APP);
-    prop.set_ui_text("Scale", "Window scale factor for DPI scaling");
-    prop.set_defaults_f32(vec![1.0]).unwrap();
-    node.add_property(prop).unwrap();
-
     node.add_signal("start", "App UI started", vec![]).unwrap();
     node.add_signal("stop", "App UI stopped", vec![]).unwrap();
     node.add_signal(

+ 7 - 3
bin/app/src/app/schema/chat.rs

@@ -242,9 +242,13 @@ pub async fn make(
     emoji_meshes: emoji_picker::EmojiMeshesPtr,
     redraw: RedrawTrigger,
 ) -> SceneNodePtr {
-    let window_scale =
-        PropertyFloat32::wrap(&sg_root.lookup_node("/window").unwrap(), Role::Internal, "scale", 0)
-            .unwrap();
+    let window_scale = PropertyFloat32::wrap(
+        &sg_root.lookup_node("/setting").unwrap(),
+        Role::Internal,
+        "win.scale",
+        0,
+    )
+    .unwrap();
     let atom = &mut PropertyAtomicGuard::none();
 
     let mut cc = Compiler::new();

+ 7 - 11
bin/app/src/app/schema/menu/mod.rs

@@ -68,6 +68,8 @@ mod android_ui_consts {
     pub const LABEL_LINESPACE: f32 = 60.;
     pub const MENU_ICON_SCALE: f32 = 220.;
     pub const SETTINGS_ICON_SCALE: f32 = 55.;
+
+    pub const DARKFI_LOGO_SCALE: f32 = 40.;
 }
 
 #[cfg(target_os = "android")]
@@ -110,6 +112,8 @@ mod ui_consts {
     pub const LABEL_LINESPACE: f32 = 140.;
     pub const MENU_ICON_SCALE: f32 = 100.;
     pub const SETTINGS_ICON_SCALE: f32 = 28.;
+
+    pub const DARKFI_LOGO_SCALE: f32 = 20.;
 }
 
 pub mod channel;
@@ -126,9 +130,9 @@ pub async fn make(
     emoji_meshes: EmojiMeshesPtr,
 ) {
     let window_scale = PropertyFloat32::wrap(
-        &app.sg_root.lookup_node("/window").unwrap(),
+        &app.sg_root.lookup_node("/setting").unwrap(),
         Role::Internal,
-        "scale",
+        "win.scale",
         0,
     )
     .unwrap();
@@ -308,7 +312,7 @@ pub async fn make(
     prop.set_default_f32(3, CHANNEL_HEADER_HEIGHT).unwrap();
     node.set_property_u32(atom, Role::App, "z_index", 3).unwrap();
     node.set_property_bool(atom, Role::App, "is_visible", true).unwrap();
-    let shape = shape::create_darkfi_logo([1., 1., 1., 1.]).scaled(20.);
+    let shape = shape::create_darkfi_logo([1., 1., 1., 1.]).scaled(DARKFI_LOGO_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;
@@ -561,14 +565,6 @@ pub async fn setup_wallet_button(app: &App, chat_layer: SceneNodePtr, i18n_fish:
     cc.add_const_f32("MENU_BTN_H", MENU_BTN_H);
     cc.add_const_f32("CHANNEL_LABEL_X", CHANNEL_LABEL_X);
 
-    let _window_scale = PropertyFloat32::wrap(
-        &app.sg_root.lookup_node("/window").unwrap(),
-        Role::Internal,
-        "scale",
-        0,
-    )
-    .unwrap();
-
     let chat_is_visible = PropertyBool::wrap(&chat_layer, Role::App, "is_visible", 0).unwrap();
     let menu_layer = chat_layer.lookup_node("/menu_layer").unwrap();
 

+ 7 - 3
bin/app/src/app/schema/mod.rs

@@ -266,9 +266,13 @@ pub async fn make(
 
     let atom = &mut PropertyAtomicGuard::none();
 
-    let window_scale =
-        PropertyFloat32::wrap(&app.sg_root.lookup_node("/window").unwrap(), Role::App, "scale", 0)
-            .unwrap();
+    let window_scale = PropertyFloat32::wrap(
+        &app.sg_root.lookup_node("/setting").unwrap(),
+        Role::App,
+        "win.scale",
+        0,
+    )
+    .unwrap();
 
     // Root content layer
     let content = create_layer("content");

+ 6 - 36
bin/app/src/app/schema/settings.rs

@@ -51,7 +51,7 @@ use std::{
 mod android_ui_consts {
     pub const SETTING_LABEL_X: f32 = 40.;
     pub const SETTING_LABEL_LINESPACE: f32 = 140.;
-    pub const SEARCH_BAR_Y: f32 = 60.;
+    pub const SEARCH_BAR_Y: f32 = SETTING_LABEL_LINESPACE;
     pub const SETTING_LABEL_Y: f32 = (SETTING_LABEL_LINESPACE - 1.2 * SETTING_LABEL_FONTSIZE) / 2.;
     pub const SLIDER_PAD: f32 = 20.;
     pub const RESET_BTN_W: f32 = 70.;
@@ -96,7 +96,7 @@ mod ui_consts {
 mod ui_consts {
     pub const SETTING_LABEL_X: f32 = 20.;
     pub const SETTING_LABEL_LINESPACE: f32 = 60.;
-    pub const SEARCH_BAR_Y: f32 = 60.;
+    pub const SEARCH_BAR_Y: f32 = SETTING_LABEL_LINESPACE;
     pub const SETTING_LABEL_Y: f32 = (SETTING_LABEL_LINESPACE - 1.2 * SETTING_LABEL_FONTSIZE) / 2.;
     pub const SLIDER_PAD: f32 = 10.;
     pub const RESET_BTN_W: f32 = 35.;
@@ -171,16 +171,6 @@ impl Setting {
     }
 }
 
-#[cfg(target_os = "android")]
-fn win_base_scale() -> f32 {
-    miniquad::window::dpi_scale() / 3.5
-}
-
-#[cfg(not(target_os = "android"))]
-fn win_base_scale() -> f32 {
-    1.
-}
-
 pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
     let mut cc = Compiler::new();
     cc.add_const_f32("BORDER_RIGHT_SCALE", BORDER_RIGHT_SCALE);
@@ -195,9 +185,9 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
     cc.add_const_f32("CONFIRM_BTN_W", CONFIRM_BTN_W);
     cc.add_const_f32("X_RATIO", 1. / 2.);
     let window_scale = PropertyFloat32::wrap(
-        &app.sg_root.lookup_node("/window").unwrap(),
+        &app.sg_root.lookup_node("/setting").unwrap(),
         Role::Internal,
-        "scale",
+        "win.scale",
         0,
     )
     .unwrap();
@@ -1676,7 +1666,6 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
             node.register("click", slot).unwrap();
             let setting2 = setting.clone();
             let sg_root2 = setting_layer_node.clone();
-            let app_root2 = app.sg_root.clone();
             let active_setting2 = active_setting.clone();
             let editz_text2 = editz_text.clone();
             let listen_click = app.ex.spawn(async move {
@@ -1689,7 +1678,7 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
                     if setting2.is_bool() {
                         refresh_bool_row(&setting2, &sg_root2, atom);
                     } else if setting2.name == "win.scale" {
-                        reset_win_scale_row(&setting2, &sg_root2, &app_root2, atom);
+                        reset_win_scale_row(&setting2, &sg_root2, atom);
                     }
 
                     // Show the selected setting value label (set its text empty)
@@ -1772,10 +1761,8 @@ fn spawn_win_scale_listener(
 ) {
     let (slot, recvr) = Slot::new("slider_changed");
     slider.register("changed", slot).unwrap();
-    let sg_root = app.sg_root.clone();
     let row_root = row_root.clone();
     let redraw = app.redraw_trigger.clone();
-    let base_scale = win_base_scale();
     let task = app.ex.spawn(async move {
         while let Ok(data) = recvr.recv().await {
             let Ok(val) = deserialize::<f32>(&data) else { continue };
@@ -1784,12 +1771,6 @@ fn spawn_win_scale_listener(
                 error!(target: "app::settings", "failed to set win.scale: {e}");
                 continue
             }
-            let window = sg_root.lookup_node("/window").unwrap();
-            window
-                .get_property("scale")
-                .unwrap()
-                .set_f32(atom, Role::App, 0, base_scale * val)
-                .unwrap();
             info!(target: "app::settings", "Applied win.scale live: {val}");
             refresh_setting(setting.clone(), row_root.clone());
         }
@@ -1817,12 +1798,7 @@ fn decode_selection_payload(data: &[u8]) -> Option<(u32, String)> {
     Some((idx, item))
 }
 
-fn reset_win_scale_row(
-    setting: &Setting,
-    row_root: &SceneNodePtr,
-    app_root: &SceneNodePtr,
-    atom: &mut PropertyAtomicGuard,
-) {
+fn reset_win_scale_row(setting: &Setting, row_root: &SceneNodePtr, atom: &mut PropertyAtomicGuard) {
     let def = match setting.get_default() {
         PropertyValue::Float32(v) => v.clamp(0.8, 1.2),
         _ => 1.,
@@ -1830,12 +1806,6 @@ fn reset_win_scale_row(
     if let Some(slider) = row_root.lookup_node("/value_slider") {
         slider.set_property_f32(atom, Role::App, "value", def).unwrap();
     }
-    let window = app_root.lookup_node("/window").unwrap();
-    window
-        .get_property("scale")
-        .unwrap()
-        .set_f32(atom, Role::App, 0, win_base_scale() * def)
-        .unwrap();
 }
 fn refresh_bool_row(setting: &Setting, sn: &SceneNodePtr, atom: &mut PropertyAtomicGuard) {
     let on = matches!(setting.get_value(), PropertyValue::Bool(true));

+ 2 - 2
bin/app/src/app/schema/test.rs

@@ -66,9 +66,9 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
     let atom = &mut PropertyAtomicGuard::none();
 
     let window_scale = PropertyFloat32::wrap(
-        &app.sg_root.lookup_node("/window").unwrap(),
+        &app.sg_root.lookup_node("/setting").unwrap(),
         Role::Internal,
-        "scale",
+        "win.scale",
         0,
     )
     .unwrap();

+ 7 - 3
bin/app/src/app/schema/test_chatview.rs

@@ -122,9 +122,13 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
     }
     drop(dev_tree);
 
-    let window_scale =
-        PropertyFloat32::wrap(&app.sg_root.lookup_node("/window").unwrap(), Role::App, "scale", 0)
-            .unwrap();
+    let window_scale = PropertyFloat32::wrap(
+        &app.sg_root.lookup_node("/setting").unwrap(),
+        Role::App,
+        "win.scale",
+        0,
+    )
+    .unwrap();
     let chatview_node = node
         .setup(|me| {
             ChatView::new(

+ 2 - 2
bin/app/src/app/schema/test_edit.rs

@@ -36,9 +36,9 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
     let atom = &mut PropertyAtomicGuard::none();
 
     let window_scale = PropertyFloat32::wrap(
-        &app.sg_root.lookup_node("/window").unwrap(),
+        &app.sg_root.lookup_node("/setting").unwrap(),
         Role::Internal,
-        "scale",
+        "win.scale",
         0,
     )
     .unwrap();

+ 4 - 0
bin/app/src/app/schema/wallet/data.rs

@@ -61,6 +61,8 @@ mod android_ui_consts {
 
     pub const PROGRESS_FONTSIZE: f32 = 36.;
     pub const PROGRESS_MARGIN: f32 = 10.;
+
+    pub const DARKFI_LOGO_SCALE: f32 = 40.;
 }
 
 #[cfg(target_os = "android")]
@@ -117,6 +119,8 @@ mod ui_consts {
 
     pub const PROGRESS_FONTSIZE: f32 = 14.;
     pub const PROGRESS_MARGIN: f32 = 5.;
+
+    pub const DARKFI_LOGO_SCALE: f32 = 20.;
 }
 
 pub use ui_consts::*;

+ 1 - 1
bin/app/src/app/schema/wallet/main.rs

@@ -231,7 +231,7 @@ pub async fn make(
     prop.set_default_f32(3, HEADER_HEIGHT).unwrap();
     node.set_property_u32(atom, Role::App, "z_index", 3).unwrap();
     node.set_property_bool(atom, Role::App, "is_visible", true).unwrap();
-    let shape = shape::create_darkfi_logo([1., 1., 1., 1.]).scaled(20.);
+    let shape = shape::create_darkfi_logo([1., 1., 1., 1.]).scaled(DARKFI_LOGO_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;

+ 2 - 2
bin/app/src/app/schema/wallet/mod.rs

@@ -42,9 +42,9 @@ use crate::{
 
 pub async fn make(app: &App, content: SceneNodePtr, i18n_fish: &I18nBabelFish) {
     let window_scale = PropertyFloat32::wrap(
-        &app.sg_root.lookup_node("/window").unwrap(),
+        &app.sg_root.lookup_node("/setting").unwrap(),
         Role::Internal,
-        "scale",
+        "win.scale",
         0,
     )
     .unwrap();

+ 10 - 0
bin/app/src/net.rs

@@ -301,6 +301,16 @@ impl ZeroMQAdapter {
                         let default = prop.defaults.lock().unwrap()[i].clone();
                         if default.is_null() {
                             2u8.encode(&mut reply).unwrap();
+                        } else if default.is_expr() {
+                            // An unset index resolving through a default
+                            // expr reports the decompiled expr source under
+                            // the EXPR status. Encoding the SExprCode bytes
+                            // as the payload would desync the client, which
+                            // expects a payload matching the property type
+                            // on the UNSET path.
+                            3u8.encode(&mut reply).unwrap();
+                            let expr = default.as_sexpr().unwrap();
+                            decompile(&expr).encode(&mut reply).unwrap();
                         } else {
                             1u8.encode(&mut reply).unwrap();
                             // Shapes are not serialized on the get path;

+ 1 - 1
bin/app/src/ui/win/mod.rs

@@ -79,6 +79,7 @@ pub struct Window {
 impl Window {
     pub async fn new(
         node: SceneNodeWeak,
+        scale: PropertyFloat32,
         renderer: Renderer,
         i18n_fish: I18nBabelFish,
         ex: ExecutorPtr,
@@ -88,7 +89,6 @@ impl Window {
         let node_ref = &node.upgrade().unwrap();
         let locale = PropertyStr::wrap(node_ref, Role::Internal, "locale", 0).unwrap();
         let screen_size = PropertyDimension::wrap(node_ref, Role::Internal, "screen_size").unwrap();
-        let scale = PropertyFloat32::wrap(node_ref, Role::Internal, "scale", 0).unwrap();
 
         let gesture_session = GestureSession::new(node.clone(), ex);