Forráskód Böngészése

wallet: editbox only emits true for input handlers when it captures input

darkfi 1 éve
szülő
commit
c699f9da44

+ 7 - 7
bin/darkwallet/src/prop/mod.rs

@@ -206,9 +206,8 @@ impl Encodable for PropertyValue {
 #[derive(Debug, Clone)]
 pub enum ModifyAction {
     Clear,
-    #[allow(dead_code)]
     Set(usize),
-    #[allow(dead_code)]
+    SetCache(usize),
     Push(usize),
 }
 
@@ -452,7 +451,7 @@ impl Property {
         Ok(())
     }
 
-    fn set_cache(&self, i: usize, val: PropertyValue) -> Result<()> {
+    fn set_cache(&self, role: Role, i: usize, val: PropertyValue) -> Result<()> {
         if self.typ != val.as_type() {
             return Err(Error::PropertyWrongType)
         }
@@ -462,13 +461,14 @@ impl Property {
             return Err(Error::PropertyWrongIndex)
         }
         cache[i] = val;
+        self.on_modify.notify((role, ModifyAction::SetCache(i)));
         Ok(())
     }
-    pub fn set_cache_f32(&self, i: usize, val: f32) -> Result<()> {
-        self.set_cache(i, PropertyValue::Float32(val))
+    pub fn set_cache_f32(&self, role: Role, i: usize, val: f32) -> Result<()> {
+        self.set_cache(role, i, PropertyValue::Float32(val))
     }
-    pub fn set_cache_u32(&self, i: usize, val: u32) -> Result<()> {
-        self.set_cache(i, PropertyValue::Uint32(val))
+    pub fn set_cache_u32(&self, role: Role, i: usize, val: u32) -> Result<()> {
+        self.set_cache(role, i, PropertyValue::Uint32(val))
     }
 
     // Push

+ 1 - 1
bin/darkwallet/src/prop/wrap.rs

@@ -264,7 +264,7 @@ impl PropertyRect {
             };
 
             let v = machine.call()?.as_f32()?;
-            self.prop.set_cache_f32(i, v).unwrap();
+            self.prop.set_cache_f32(self.role, i, v).unwrap();
         }
         Ok(())
     }

+ 22 - 23
bin/darkwallet/src/ui/editbox.rs

@@ -432,9 +432,9 @@ impl EditBox {
         self.redraw().await;
     }
 
-    async fn handle_click_down(&self, btn: MouseButton, mouse_pos: Point) {
+    async fn handle_click_down(&self, btn: MouseButton, mouse_pos: Point) -> bool {
         if btn != MouseButton::Left {
-            return
+            return false
         }
 
         let rect = self.rect.get();
@@ -471,22 +471,24 @@ impl EditBox {
             self.selected.set_null(Role::Internal, 1).unwrap();
         } else {
             // Do nothing. Click was outside editbox, and editbox wasn't focused
-            return
+            return false
         }
 
         self.redraw().await;
+        true
     }
-    fn handle_click_up(&self, btn: MouseButton, pos: Point) {
+    fn handle_click_up(&self, btn: MouseButton, pos: Point) -> bool {
         if btn != MouseButton::Left {
-            return
+            return false
         }
 
         // releasing mouse button will end selection
         self.mouse_btn_held.store(false, Ordering::Relaxed);
+        false
     }
-    async fn handle_cursor_move(&self, pos: Point) {
+    async fn handle_cursor_move(&self, pos: Point) -> bool {
         if !self.mouse_btn_held.load(Ordering::Relaxed) {
-            return;
+            return false;
         }
 
         // if active and selection_active, then use x to modify the selection.
@@ -502,20 +504,7 @@ impl EditBox {
 
         self.apply_cursor_scrolling();
         self.redraw().await;
-    }
-
-    async fn handle_touch(&self, phase: TouchPhase, id: u64, touch_pos: Point) {
-        // Ignore multi-touch
-        if id != 0 {
-            return
-        }
-        // Simulate mouse events
-        match phase {
-            TouchPhase::Started => self.handle_click_down(MouseButton::Left, touch_pos).await,
-            TouchPhase::Moved => self.handle_cursor_move(touch_pos).await,
-            TouchPhase::Ended => self.handle_click_up(MouseButton::Left, touch_pos),
-            TouchPhase::Cancelled => {}
-        }
+        false
     }
 
     /// Used when clicking the text. Given the x coord of the mouse, it finds the index
@@ -1159,8 +1148,18 @@ impl UIObject for EditBox {
             return true
         }
 
-        self.handle_touch(phase, id, touch_pos).await;
-        true
+        // Ignore multi-touch
+        if id != 0 {
+            return false
+        }
+
+        // Simulate mouse events
+        match phase {
+            TouchPhase::Started => self.handle_click_down(MouseButton::Left, touch_pos).await,
+            TouchPhase::Moved => self.handle_cursor_move(touch_pos).await,
+            TouchPhase::Ended => self.handle_click_up(MouseButton::Left, touch_pos),
+            TouchPhase::Cancelled => false
+        }
     }
 }