Explorar o código

app/edit: fix disreprency between render and touch pos for action bar

jkds hai 6 meses
pai
achega
0f6b989c4a
Modificáronse 2 ficheiros con 6 adicións e 11 borrados
  1. 1 6
      bin/app/src/ui/edit/action.rs
  2. 5 5
      bin/app/src/ui/edit/mod.rs

+ 1 - 6
bin/app/src/ui/edit/action.rs

@@ -105,23 +105,18 @@ impl ActionMode {
     }
 
     /// Returns `Some(n)` if item n is selected.
-    pub fn interact(&self, mut pos: Point) -> Option<u32> {
-        d!("Interact with action bar {pos:?}");
+    pub fn interact(&self, pos: Point) -> Option<u32> {
         let Some(menu) = std::mem::take(&mut *self.menu.lock()) else {
-            d!("No items");
             return None
         };
 
-        // Check each item
         for item in &menu.items {
-            d!("Checking action item: {:?}", item.rect);
             if item.rect.contains(pos) {
                 d!("Action clicked: {}", item.action_id);
                 return Some(item.action_id);
             }
         }
 
-        // Inside menu but no item clicked
         d!("Nothing clicked");
         None
     }

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

@@ -661,9 +661,8 @@ 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 rect = self.rect.get();
+        let local_pos = touch_pos - rect.pos();
 
         let atom = &mut self.render_api.make_guard(gfxtag!("BaseEdit::handle_touch_start_action"));
         if let Some(action_id) = self.action_mode.interact(local_pos) {
@@ -695,13 +694,12 @@ impl BaseEdit {
             self.action_mode.redraw(atom.batch_id);
         }
 
-        let rect = self.rect.get();
         if !rect.contains(touch_pos) {
             t!("rect!cont rect={rect:?}, touch_pos={touch_pos:?}");
             return false
         }
 
-        if self.try_handle_drag(local_pos) {
+        if self.try_handle_drag(touch_pos) {
             return true
         }
 
@@ -728,6 +726,8 @@ 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);
+
         let baseline = self.baseline.get();
         let handle_off_y = self.handle_descent.get();