فهرست منبع

app: use screen_density to set the window_scale

darkfi 1 سال پیش
والد
کامیت
c8003d98b8
3فایلهای تغییر یافته به همراه29 افزوده شده و 5 حذف شده
  1. 4 0
      bin/app/java/MainActivity.java
  2. 16 4
      bin/app/src/android.rs
  3. 9 1
      bin/app/src/app/mod.rs

+ 4 - 0
bin/app/java/MainActivity.java

@@ -136,6 +136,10 @@ public int getKeyboardHeight() {
     return Math.max(0, imeInsets.bottom - navInsets.bottom);
 }
 
+public float getScreenDensity() {
+    return getResources().getDisplayMetrics().density;
+}
+
 //% END
 
 //% MAIN_ACTIVITY_ON_CREATE

+ 16 - 4
bin/app/src/android.rs

@@ -46,6 +46,14 @@ macro_rules! call_mainactivity_str_method {
         }
     }};
 }
+macro_rules! call_mainactivity_float_method {
+    ($method:expr) => {{
+        unsafe {
+            let env = android::attach_jni_env();
+            ndk_utils::call_method!(CallFloatMethod, env, android::ACTIVITY, $method, "()F")
+        }
+    }};
+}
 
 struct GlobalData {
     sender: Option<async_channel::Sender<AndroidSuggestEvent>>,
@@ -277,13 +285,17 @@ pub fn get_editable(id: usize) -> Option<Editable> {
     }
 }
 
-pub fn get_keyboard_height() -> usize {
-    call_mainactivity_int_method!("getKeyboardHeight", "()I") as usize
-}
-
 pub fn get_appdata_path() -> PathBuf {
     call_mainactivity_str_method!("getAppDataPath").into()
 }
 pub fn get_external_storage_path() -> PathBuf {
     call_mainactivity_str_method!("getExternalStoragePath").into()
 }
+
+pub fn get_keyboard_height() -> usize {
+    call_mainactivity_int_method!("getKeyboardHeight", "()I") as usize
+}
+
+pub fn get_screen_density() -> f32 {
+    call_mainactivity_float_method!("getScreenDensity")
+}

+ 9 - 1
bin/app/src/app/mod.rs

@@ -31,6 +31,7 @@ use std::{
 };
 
 use crate::{
+    android,
     error::Error,
     expr::Op,
     gfx::{GraphicsEventPublisherPtr, RenderApi, Vertex},
@@ -184,7 +185,14 @@ impl App {
             sled_tree: settings_tree,
         });
 
-        settings.add_setting("scale", PropertyValue::Float32(1.));
+        let mut window_scale = 1.;
+        #[cfg(target_os = "android")]
+        {
+            window_scale = android::get_screen_density() / 2.25;
+            t!("Setting window_scale to {window_scale}");
+        }
+
+        settings.add_setting("scale", PropertyValue::Float32(window_scale));
         settings.load_settings();
 
         // Save app settings in sled when they change