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

app/edit: correctly render on android with window_scale applied

jkds 6 месяцев назад
Родитель
Сommit
4e5124c7d9
3 измененных файлов с 19 добавлено и 8 удалено
  1. 10 0
      bin/app/src/app/schema/chat.rs
  2. 3 3
      bin/app/src/gfx/mod.rs
  3. 6 5
      bin/app/src/ui/edit/mod.rs

+ 10 - 0
bin/app/src/app/schema/chat.rs

@@ -91,6 +91,10 @@ mod android_ui_consts {
     pub const CMD_HELP_NICK_DESC_WIDTH: f32 = 1000.;
     pub const CMD_HELP_NICK_DESC_X: f32 = 320.;
     pub const CMD_HELP_LABEL_Y: f32 = 20.;
+
+    // Action menu
+    pub const ACTION_PADDING: f32 = 32.;
+    pub const ACTION_SPACING: f32 = 8.;
 }
 
 #[cfg(target_os = "android")]
@@ -152,6 +156,10 @@ mod ui_consts {
     pub const CMD_HELP_NICK_DESC_WIDTH: f32 = 500.;
     pub const CMD_HELP_NICK_DESC_X: f32 = 160.;
     pub const CMD_HELP_LABEL_Y: f32 = 10.;
+
+    // Action menu
+    pub const ACTION_PADDING: f32 = 8.;
+    pub const ACTION_SPACING: f32 = 4.;
 }
 
 use super::EMOJI_PICKER_ICON_SIZE;
@@ -763,6 +771,8 @@ pub async fn make(
     node.set_property_f32(atom, Role::App, "select_ascent", CHATEDIT_SELECT_ASCENT).unwrap();
     node.set_property_f32(atom, Role::App, "select_descent", CHATEDIT_SELECT_DESCENT).unwrap();
     node.set_property_f32(atom, Role::App, "handle_descent", CHATEDIT_HANDLE_DESCENT).unwrap();
+    node.set_property_f32(atom, Role::App, "action_padding", ACTION_PADDING).unwrap();
+    node.set_property_f32(atom, Role::App, "action_spacing", ACTION_SPACING).unwrap();
     let prop = node.get_property("hi_bg_color").unwrap();
     if COLOR_SCHEME == ColorScheme::PaperLight {
         prop.set_f32(atom, Role::App, 0, 0.5).unwrap();

+ 3 - 3
bin/app/src/gfx/mod.rs

@@ -788,8 +788,8 @@ impl<'a> RenderContext<'a> {
                         d!("{ws}set_pipeline({pipeline:?})");
                     }
                 }
-                GfxDrawInstruction::Overlay(instrs) => {
-                    let pos = self.view.pos() + self.cursor;
+               GfxDrawInstruction::Overlay(instrs) => {
+                    let pos = self.view.pos() + (self.cursor * self.scale);
                     self.overlays.push(OverlayDefer { pos, instrs: instrs.clone() });
                 }
             }
@@ -1821,7 +1821,7 @@ impl EventHandler for Stage {
             loaded_pipelines: &self.loaded_pipelines,
             scale: 1.,
             view: Rectangle::from([0., 0., screen_w, screen_h]),
-            cursor: Point::from([0., 0.]),
+            cursor: Point::zero(),
             gfx_pipeline: GraphicPipeline::RGB,
             anims: &mut self.anims,
             overlays: vec![],

+ 6 - 5
bin/app/src/ui/edit/mod.rs

@@ -661,8 +661,12 @@ impl BaseEdit {
     fn handle_touch_start(&self, touch_pos: Point) -> bool {
         t!("handle_touch_start({touch_pos:?})");
 
+        let mut local_pos = touch_pos;
+        self.abs_to_local(&mut local_pos);
+        t!("localize touch_pos = {local_pos:?}");
+
         let atom = &mut self.render_api.make_guard(gfxtag!("BaseEdit::handle_touch_start_action"));
-        if let Some(action_id) = self.action_mode.interact(touch_pos) {
+        if let Some(action_id) = self.action_mode.interact(local_pos) {
             match action_id {
                 ACTION_COPY => {
                     if let Some(txt) = self.editor.lock().selected_text() {
@@ -697,7 +701,7 @@ impl BaseEdit {
             return false
         }
 
-        if self.try_handle_drag(touch_pos) {
+        if self.try_handle_drag(local_pos) {
             return true
         }
 
@@ -724,9 +728,6 @@ impl BaseEdit {
         let editor = self.editor.lock();
         let Some((mut first, mut last)) = self.get_select_handles(&editor) else { return false };
 
-        self.abs_to_local(&mut touch_pos);
-        t!("localize touch_pos = {touch_pos:?}");
-
         let baseline = self.baseline.get();
         let handle_off_y = self.handle_descent.get();