Просмотр исходного кода

app: fix window sizing and re-enable android per device density scaling

jkds 7 месяцев назад
Родитель
Сommit
6b0ddc2e24

+ 8 - 5
bin/app/src/app/mod.rs

@@ -87,11 +87,14 @@ impl App {
             sled_tree: settings_tree,
         });
 
-        // TODO: apply this to insets otherwise its wrong
-        //#[cfg(target_os = "android")]
-        //let window_scale = android::get_screen_density() / 2.625;
-        //#[cfg(not(target_os = "android"))]
-        let window_scale = 1.;
+        #[cfg(target_os = "android")]
+        let window_scale = {
+            let screen_density = android::get_screen_density();
+            i!("Android screen density: {screen_density}");
+            screen_density / 2.625
+        };
+        #[cfg(not(target_os = "android"))]
+        let window_scale = 1.2;
 
         d!("Setting window scale to {window_scale}");
 

+ 2 - 1
bin/app/src/main.rs

@@ -74,7 +74,7 @@ pub use util::ExecutorPtr;
 macro_rules! t { ($($arg:tt)*) => { trace!(target: "main", $($arg)*); } }
 #[cfg(feature = "enable-plugins")]
 macro_rules! d { ($($arg:tt)*) => { trace!(target: "main", $($arg)*); } }
-#[cfg(feature = "enable-plugins")]
+#[cfg(any(feature = "enable-plugins", feature = "enable-netdebug"))]
 macro_rules! i { ($($arg:tt)*) => { trace!(target: "main", $($arg)*); } }
 
 fn panic_hook(panic_info: &std::panic::PanicHookInfo) {
@@ -166,6 +166,7 @@ impl God {
             let ex = bg_ex.clone();
             let render_api = render_api.clone();
             let zmq_task = bg_ex.spawn(async {
+                i!("Enabled net debugging backend in this build");
                 let zmq_rpc = ZeroMQAdapter::new(sg_root, render_api, ex).await;
                 zmq_rpc.run().await;
             });

+ 12 - 2
bin/app/src/net.rs

@@ -30,6 +30,8 @@ use crate::{
     ExecutorPtr,
 };
 
+const USE_IPV6: bool = true;
+
 #[derive(Debug, SerialDecodable)]
 #[repr(u8)]
 enum Command {
@@ -86,10 +88,18 @@ pub struct ZeroMQAdapter {
 impl ZeroMQAdapter {
     pub async fn new(sg_root: SceneNodePtr, render_api: RenderApi, ex: ExecutorPtr) -> Arc<Self> {
         let mut zmq_rep = zeromq::RepSocket::new();
-        zmq_rep.bind("tcp://0.0.0.0:9484").await.unwrap();
+        if USE_IPV6 {
+            zmq_rep.bind("tcp://[::]:9484").await.unwrap();
+        } else {
+            zmq_rep.bind("tcp://0.0.0.0:9484").await.unwrap();
+        }
 
         let mut zmq_pub = zeromq::PubSocket::new();
-        zmq_pub.bind("tcp://0.0.0.0:9485").await.unwrap();
+        if USE_IPV6 {
+            zmq_pub.bind("tcp://[::]:9485").await.unwrap();
+        } else {
+            zmq_pub.bind("tcp://0.0.0.0:9485").await.unwrap();
+        }
 
         Arc::new(Self {
             sg_root,

+ 5 - 10
bin/app/src/text/mod.rs

@@ -31,13 +31,11 @@ pub use editor::Editor;
 mod render;
 pub use render::{render_layout, render_layout_with_opts, DebugRenderOptions};
 
-// Global shared FontContext (thread-safe via internal Arc<Mutex<>>)
 pub static GLOBAL_FONT_CTX: LazyLock<parley::FontContext> = LazyLock::new(|| {
-    let collection = Collection::new(CollectionOptions { shared: true, system_fonts: false });
-
-    let source_cache = SourceCache::new(SourceCacheOptions { shared: true });
-
-    let mut font_ctx = parley::FontContext { collection, source_cache };
+    let mut font_ctx = parley::FontContext {
+        collection: Collection::new(CollectionOptions { shared: true, system_fonts: false }),
+        source_cache: SourceCache::new(SourceCacheOptions { shared: true }),
+    };
 
     let font_data = include_bytes!("../../ibm-plex-mono-regular.otf") as &[u8];
     font_ctx.collection.register_fonts(peniko::Blob::new(Arc::new(font_data)), None);
@@ -48,19 +46,16 @@ pub static GLOBAL_FONT_CTX: LazyLock<parley::FontContext> = LazyLock::new(|| {
     font_ctx
 });
 
-// Thread-local LayoutContext
 thread_local! {
     pub static THREAD_LAYOUT_CTX: RefCell<parley::LayoutContext<Color>> =
         RefCell::new(parley::LayoutContext::new());
 }
 
-// Public constants
-pub const FONT_STACK: &[parley::FontFamily<'_>] = &[
+const FONT_STACK: &[parley::FontFamily<'_>] = &[
     parley::FontFamily::Named(std::borrow::Cow::Borrowed("IBM Plex Mono")),
     parley::FontFamily::Named(std::borrow::Cow::Borrowed("Noto Color Emoji")),
 ];
 
-// FREE FUNCTIONS (no TextContext wrapper!)
 pub fn make_layout(
     text: &str,
     text_color: Color,

+ 1 - 1
bin/app/src/ui/chatview/page.rs

@@ -104,7 +104,7 @@ impl PrivMessage {
     }
 
     fn height(&self, line_height: f32) -> f32 {
-        self.txt_layout.as_ref().unwrap().len() as f32 * line_height
+        self.txt_layout.as_ref().unwrap().len() as f32 * line_height * self.window_scale
     }
 
     fn cache_txt_layout(

+ 1 - 4
bin/app/src/ui/edit/mod.rs

@@ -235,8 +235,6 @@ pub struct BaseEdit {
     touch_info: SyncMutex<TouchInfo>,
     is_phone_select: AtomicBool,
 
-    // TODO: we should make use of this!
-    window_scale: PropertyFloat32,
     parent_rect: Arc<SyncMutex<Option<Rectangle>>>,
     is_mouse_hover: AtomicBool,
 
@@ -297,7 +295,7 @@ impl BaseEdit {
             text.clone(),
             font_size.clone(),
             text_color.clone(),
-            window_scale.clone(),
+            window_scale,
             lineheight.clone(),
         )));
 
@@ -384,7 +382,6 @@ impl BaseEdit {
             touch_info: SyncMutex::new(TouchInfo::new(scroll, behave.scroll_ctrl())),
             is_phone_select: AtomicBool::new(false),
 
-            window_scale: window_scale.clone(),
             parent_rect,
             is_mouse_hover: AtomicBool::new(false),
 

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

@@ -187,7 +187,8 @@ impl Window {
                 while let Ok(insets_val) = insets_rx.recv().await {
                     let Some(self_) = me.upgrade() else { break };
                     let atom = &mut self_.render_api.make_guard(gfxtag!("Window::insets_task"));
-                    let insets_val = Rectangle::from(insets_val);
+                    let scale = self_.scale.get();
+                    let insets_val = Rectangle::from(insets_val) / scale;
                     t!("Insets changed: {insets_val:?}");
                     insets.set(atom, &insets_val);
                 }