Răsfoiți Sursa

wallet: migrate internal APIs to use Point struct everywhere

darkfi 1 an în urmă
părinte
comite
f6ba337563

+ 92 - 95
bin/darkwallet/src/gfx/mod.rs

@@ -437,29 +437,29 @@ pub struct GraphicsEventPublisher {
     lock_resize: SyncMutex<Option<SubscriptionId>>,
     resize: PublisherPtr<(f32, f32)>,
 
-    lock_mouse_move: SyncMutex<Option<SubscriptionId>>,
-    mouse_move: PublisherPtr<(f32, f32)>,
+    lock_key_down: SyncMutex<Option<SubscriptionId>>,
+    key_down: PublisherPtr<(KeyCode, KeyMods, bool)>,
 
-    lock_mouse_wheel: SyncMutex<Option<SubscriptionId>>,
-    mouse_wheel: PublisherPtr<(f32, f32)>,
+    lock_key_up: SyncMutex<Option<SubscriptionId>>,
+    key_up: PublisherPtr<(KeyCode, KeyMods)>,
+
+    lock_char: SyncMutex<Option<SubscriptionId>>,
+    chr: PublisherPtr<(char, KeyMods, bool)>,
 
     lock_mouse_btn_down: SyncMutex<Option<SubscriptionId>>,
-    mouse_btn_down: PublisherPtr<(MouseButton, f32, f32)>,
+    mouse_btn_down: PublisherPtr<(MouseButton, Point)>,
 
     lock_mouse_btn_up: SyncMutex<Option<SubscriptionId>>,
-    mouse_btn_up: PublisherPtr<(MouseButton, f32, f32)>,
-
-    lock_char: SyncMutex<Option<SubscriptionId>>,
-    chr: PublisherPtr<(char, KeyMods, bool)>,
+    mouse_btn_up: PublisherPtr<(MouseButton, Point)>,
 
-    lock_key_down: SyncMutex<Option<SubscriptionId>>,
-    key_down: PublisherPtr<(KeyCode, KeyMods, bool)>,
+    lock_mouse_move: SyncMutex<Option<SubscriptionId>>,
+    mouse_move: PublisherPtr<Point>,
 
-    lock_key_up: SyncMutex<Option<SubscriptionId>>,
-    key_up: PublisherPtr<(KeyCode, KeyMods)>,
+    lock_mouse_wheel: SyncMutex<Option<SubscriptionId>>,
+    mouse_wheel: PublisherPtr<Point>,
 
     lock_touch: SyncMutex<Option<SubscriptionId>>,
-    touch: PublisherPtr<(TouchPhase, u64, f32, f32)>,
+    touch: PublisherPtr<(TouchPhase, u64, Point)>,
 }
 
 impl GraphicsEventPublisher {
@@ -468,11 +468,14 @@ impl GraphicsEventPublisher {
             lock_resize: SyncMutex::new(None),
             resize: Publisher::new(),
 
-            lock_mouse_move: SyncMutex::new(None),
-            mouse_move: Publisher::new(),
+            lock_key_down: SyncMutex::new(None),
+            key_down: Publisher::new(),
 
-            lock_mouse_wheel: SyncMutex::new(None),
-            mouse_wheel: Publisher::new(),
+            lock_key_up: SyncMutex::new(None),
+            key_up: Publisher::new(),
+
+            lock_char: SyncMutex::new(None),
+            chr: Publisher::new(),
 
             lock_mouse_btn_down: SyncMutex::new(None),
             mouse_btn_down: Publisher::new(),
@@ -480,14 +483,11 @@ impl GraphicsEventPublisher {
             lock_mouse_btn_up: SyncMutex::new(None),
             mouse_btn_up: Publisher::new(),
 
-            lock_char: SyncMutex::new(None),
-            chr: Publisher::new(),
-
-            lock_key_down: SyncMutex::new(None),
-            key_down: Publisher::new(),
+            lock_mouse_move: SyncMutex::new(None),
+            mouse_move: Publisher::new(),
 
-            lock_key_up: SyncMutex::new(None),
-            key_up: Publisher::new(),
+            lock_mouse_wheel: SyncMutex::new(None),
+            mouse_wheel: Publisher::new(),
 
             lock_touch: SyncMutex::new(None),
             touch: Publisher::new(),
@@ -569,29 +569,38 @@ impl GraphicsEventPublisher {
             self.resize.notify(ev);
         }
     }
+    fn notify_key_down(&self, key: KeyCode, mods: KeyMods, repeat: bool) {
+        let ev = (key, mods, repeat);
 
-    fn notify_mouse_move(&self, x: f32, y: f32) {
-        let ev = (x, y);
+        let locked = self.lock_key_down.lock().unwrap().clone();
+        if let Some(locked) = locked {
+            self.key_down.notify_with_include(ev, &[locked]);
+        } else {
+            self.key_down.notify(ev);
+        }
+    }
+    fn notify_key_up(&self, key: KeyCode, mods: KeyMods) {
+        let ev = (key, mods);
 
-        let locked = self.lock_mouse_move.lock().unwrap().clone();
+        let locked = self.lock_key_up.lock().unwrap().clone();
         if let Some(locked) = locked {
-            self.mouse_move.notify_with_include(ev, &[locked]);
+            self.key_up.notify_with_include(ev, &[locked]);
         } else {
-            self.mouse_move.notify(ev);
+            self.key_up.notify(ev);
         }
     }
-    fn notify_mouse_wheel(&self, x: f32, y: f32) {
-        let ev = (x, y);
+    fn notify_char(&self, chr: char, mods: KeyMods, repeat: bool) {
+        let ev = (chr, mods, repeat);
 
-        let locked = self.lock_mouse_wheel.lock().unwrap().clone();
+        let locked = self.lock_char.lock().unwrap().clone();
         if let Some(locked) = locked {
-            self.mouse_wheel.notify_with_include(ev, &[locked]);
+            self.chr.notify_with_include(ev, &[locked]);
         } else {
-            self.mouse_wheel.notify(ev);
+            self.chr.notify(ev);
         }
     }
-    fn notify_mouse_btn_down(&self, button: MouseButton, x: f32, y: f32) {
-        let ev = (button, x, y);
+    fn notify_mouse_btn_down(&self, button: MouseButton, mouse_pos: Point) {
+        let ev = (button, mouse_pos);
 
         let locked = self.lock_mouse_btn_down.lock().unwrap().clone();
         if let Some(locked) = locked {
@@ -600,8 +609,8 @@ impl GraphicsEventPublisher {
             self.mouse_btn_down.notify(ev);
         }
     }
-    fn notify_mouse_btn_up(&self, button: MouseButton, x: f32, y: f32) {
-        let ev = (button, x, y);
+    fn notify_mouse_btn_up(&self, button: MouseButton, mouse_pos: Point) {
+        let ev = (button, mouse_pos);
 
         let locked = self.lock_mouse_btn_up.lock().unwrap().clone();
         if let Some(locked) = locked {
@@ -611,40 +620,24 @@ impl GraphicsEventPublisher {
         }
     }
 
-    fn notify_char(&self, chr: char, mods: KeyMods, repeat: bool) {
-        let ev = (chr, mods, repeat);
-
-        let locked = self.lock_char.lock().unwrap().clone();
-        if let Some(locked) = locked {
-            self.chr.notify_with_include(ev, &[locked]);
-        } else {
-            self.chr.notify(ev);
-        }
-    }
-
-    fn notify_key_down(&self, key: KeyCode, mods: KeyMods, repeat: bool) {
-        let ev = (key, mods, repeat);
-
-        let locked = self.lock_key_down.lock().unwrap().clone();
+    fn notify_mouse_move(&self, mouse_pos: Point) {
+        let locked = self.lock_mouse_move.lock().unwrap().clone();
         if let Some(locked) = locked {
-            self.key_down.notify_with_include(ev, &[locked]);
+            self.mouse_move.notify_with_include(mouse_pos, &[locked]);
         } else {
-            self.key_down.notify(ev);
+            self.mouse_move.notify(mouse_pos);
         }
     }
-    fn notify_key_up(&self, key: KeyCode, mods: KeyMods) {
-        let ev = (key, mods);
-
-        let locked = self.lock_key_up.lock().unwrap().clone();
+    fn notify_mouse_wheel(&self, wheel_pos: Point) {
+        let locked = self.lock_mouse_wheel.lock().unwrap().clone();
         if let Some(locked) = locked {
-            self.key_up.notify_with_include(ev, &[locked]);
+            self.mouse_wheel.notify_with_include(wheel_pos, &[locked]);
         } else {
-            self.key_up.notify(ev);
+            self.mouse_wheel.notify(wheel_pos);
         }
     }
-
-    fn notify_touch(&self, phase: TouchPhase, id: u64, x: f32, y: f32) {
-        let ev = (phase, id, x, y);
+    fn notify_touch(&self, phase: TouchPhase, id: u64, touch_pos: Point) {
+        let ev = (phase, id, touch_pos);
 
         let locked = self.lock_touch.lock().unwrap().clone();
         if let Some(locked) = locked {
@@ -657,28 +650,28 @@ impl GraphicsEventPublisher {
     pub fn subscribe_resize(&self) -> Subscription<(f32, f32)> {
         self.resize.clone().subscribe()
     }
-    pub fn subscribe_mouse_move(&self) -> Subscription<(f32, f32)> {
-        self.mouse_move.clone().subscribe()
+    pub fn subscribe_key_down(&self) -> Subscription<(KeyCode, KeyMods, bool)> {
+        self.key_down.clone().subscribe()
     }
-    pub fn subscribe_mouse_wheel(&self) -> Subscription<(f32, f32)> {
-        self.mouse_wheel.clone().subscribe()
+    pub fn subscribe_key_up(&self) -> Subscription<(KeyCode, KeyMods)> {
+        self.key_up.clone().subscribe()
     }
-    pub fn subscribe_mouse_btn_down(&self) -> Subscription<(MouseButton, f32, f32)> {
+    pub fn subscribe_char(&self) -> Subscription<(char, KeyMods, bool)> {
+        self.chr.clone().subscribe()
+    }
+    pub fn subscribe_mouse_btn_down(&self) -> Subscription<(MouseButton, Point)> {
         self.mouse_btn_down.clone().subscribe()
     }
-    pub fn subscribe_mouse_btn_up(&self) -> Subscription<(MouseButton, f32, f32)> {
+    pub fn subscribe_mouse_btn_up(&self) -> Subscription<(MouseButton, Point)> {
         self.mouse_btn_up.clone().subscribe()
     }
-    pub fn subscribe_char(&self) -> Subscription<(char, KeyMods, bool)> {
-        self.chr.clone().subscribe()
-    }
-    pub fn subscribe_key_down(&self) -> Subscription<(KeyCode, KeyMods, bool)> {
-        self.key_down.clone().subscribe()
+    pub fn subscribe_mouse_move(&self) -> Subscription<Point> {
+        self.mouse_move.clone().subscribe()
     }
-    pub fn subscribe_key_up(&self) -> Subscription<(KeyCode, KeyMods)> {
-        self.key_up.clone().subscribe()
+    pub fn subscribe_mouse_wheel(&self) -> Subscription<Point> {
+        self.mouse_wheel.clone().subscribe()
     }
-    pub fn subscribe_touch(&self) -> Subscription<(TouchPhase, u64, f32, f32)> {
+    pub fn subscribe_touch(&self) -> Subscription<(TouchPhase, u64, Point)> {
         self.touch.clone().subscribe()
     }
 }
@@ -904,33 +897,37 @@ impl EventHandler for Stage {
         self.event_pub.notify_resize(width, height);
     }
 
-    fn mouse_motion_event(&mut self, x: f32, y: f32) {
-        self.event_pub.notify_mouse_move(x, y);
-    }
-    fn mouse_wheel_event(&mut self, x: f32, y: f32) {
-        self.event_pub.notify_mouse_wheel(x, y);
-    }
-    fn mouse_button_down_event(&mut self, button: MouseButton, x: f32, y: f32) {
-        self.event_pub.notify_mouse_btn_down(button, x, y);
+    fn key_down_event(&mut self, keycode: KeyCode, mods: KeyMods, repeat: bool) {
+        self.event_pub.notify_key_down(keycode, mods, repeat);
     }
-    fn mouse_button_up_event(&mut self, button: MouseButton, x: f32, y: f32) {
-        self.event_pub.notify_mouse_btn_up(button, x, y);
+    fn key_up_event(&mut self, keycode: KeyCode, mods: KeyMods) {
+        self.event_pub.notify_key_up(keycode, mods);
     }
-
     fn char_event(&mut self, chr: char, mods: KeyMods, repeat: bool) {
         self.event_pub.notify_char(chr, mods, repeat);
     }
 
-    fn key_down_event(&mut self, keycode: KeyCode, mods: KeyMods, repeat: bool) {
-        self.event_pub.notify_key_down(keycode, mods, repeat);
+    fn mouse_button_down_event(&mut self, button: MouseButton, x: f32, y: f32) {
+        let pos = Point::from([x, y]);
+        self.event_pub.notify_mouse_btn_down(button, pos);
     }
-    fn key_up_event(&mut self, keycode: KeyCode, mods: KeyMods) {
-        self.event_pub.notify_key_up(keycode, mods);
+    fn mouse_button_up_event(&mut self, button: MouseButton, x: f32, y: f32) {
+        let pos = Point::from([x, y]);
+        self.event_pub.notify_mouse_btn_up(button, pos);
+    }
+    fn mouse_motion_event(&mut self, x: f32, y: f32) {
+        let pos = Point::from([x, y]);
+        self.event_pub.notify_mouse_move(pos);
+    }
+    fn mouse_wheel_event(&mut self, x: f32, y: f32) {
+        let pos = Point::from([x, y]);
+        self.event_pub.notify_mouse_wheel(pos);
     }
 
     /// The id corresponds to multi-touch. Multiple touch events have different ids.
     fn touch_event(&mut self, phase: TouchPhase, id: u64, x: f32, y: f32) {
-        self.event_pub.notify_touch(phase, id, x, y);
+        let pos = Point::from([x, y]);
+        self.event_pub.notify_touch(phase, id, pos);
     }
 
     fn quit_requested_event(&mut self) {

+ 8 - 16
bin/darkwallet/src/ui/button.rs

@@ -99,8 +99,7 @@ impl UIObject for Button {
         &self,
         sg: &SceneGraph,
         btn: MouseButton,
-        mouse_x: f32,
-        mouse_y: f32,
+        mouse_pos: &Point,
     ) -> bool {
         if !self.is_active.get() {
             return false
@@ -110,10 +109,8 @@ impl UIObject for Button {
             return false
         }
 
-        let mouse_pos = Point::from([mouse_x, mouse_y]);
-
         let Some(rect) = self.get_cached_rect() else { return false };
-        if !rect.contains(&mouse_pos) {
+        if !rect.contains(mouse_pos) {
             return false
         }
 
@@ -125,8 +122,7 @@ impl UIObject for Button {
         &self,
         sg: &SceneGraph,
         btn: MouseButton,
-        mouse_x: f32,
-        mouse_y: f32,
+        mouse_pos: &Point,
     ) -> bool {
         if !self.is_active.get() {
             return false
@@ -142,11 +138,9 @@ impl UIObject for Button {
             return false
         }
 
-        let mouse_pos = Point::from([mouse_x, mouse_y]);
-
         // Are we releasing the click inside the button?
         let Some(rect) = self.get_cached_rect() else { return false };
-        if !rect.contains(&mouse_pos) {
+        if !rect.contains(mouse_pos) {
             return false
         }
 
@@ -163,8 +157,7 @@ impl UIObject for Button {
         sg: &SceneGraph,
         phase: TouchPhase,
         id: u64,
-        touch_x: f32,
-        touch_y: f32,
+        touch_pos: &Point,
     ) -> bool {
         if !self.is_active.get() {
             return false
@@ -176,8 +169,7 @@ impl UIObject for Button {
         }
 
         let Some(rect) = self.get_cached_rect() else { return false };
-        let touch_pos = Point { x: touch_x, y: touch_y };
-        if !rect.contains(&touch_pos) {
+        if !rect.contains(touch_pos) {
             //debug!(target: "ui::chatview", "not inside rect");
             return false
         }
@@ -185,11 +177,11 @@ impl UIObject for Button {
         // Simulate mouse events
         match phase {
             TouchPhase::Started => {
-                self.handle_mouse_btn_down(sg, MouseButton::Left, touch_x, touch_y).await;
+                self.handle_mouse_btn_down(sg, MouseButton::Left, touch_pos).await;
             }
             TouchPhase::Moved => {}
             TouchPhase::Ended => {
-                self.handle_mouse_btn_up(sg, MouseButton::Left, touch_x, touch_y).await;
+                self.handle_mouse_btn_up(sg, MouseButton::Left, touch_pos).await;
             }
             TouchPhase::Cancelled => {}
         }

+ 14 - 19
bin/darkwallet/src/ui/chatview/mod.rs

@@ -752,21 +752,18 @@ impl UIObject for ChatView {
         &self,
         sg: &SceneGraph,
         btn: MouseButton,
-        mouse_x: f32,
-        mouse_y: f32,
+        mouse_pos: &Point,
     ) -> bool {
         if btn != MouseButton::Left {
             return false
         }
 
-        let mouse_pos = Point::from([mouse_x, mouse_y]);
-
         let Ok(rect) = read_rect(self.rect.clone()) else { return false };
-        if !rect.contains(&mouse_pos) {
+        if !rect.contains(mouse_pos) {
             return false
         }
 
-        self.select_line(mouse_y).await;
+        self.select_line(mouse_pos.y).await;
         self.mouse_btn_held.store(true, Ordering::Relaxed);
         true
     }
@@ -775,8 +772,7 @@ impl UIObject for ChatView {
         &self,
         sg: &SceneGraph,
         btn: MouseButton,
-        mouse_x: f32,
-        mouse_y: f32,
+        mouse_pos: &Point,
     ) -> bool {
         if btn != MouseButton::Left {
             return false
@@ -786,9 +782,8 @@ impl UIObject for ChatView {
         true
     }
 
-    async fn handle_mouse_move(&self, sg: &SceneGraph, mouse_x: f32, mouse_y: f32) -> bool {
+    async fn handle_mouse_move(&self, sg: &SceneGraph, mouse_pos: &Point) -> bool {
         //debug!(target: "ui::chatview", "handle_mouse_move({mouse_x}, {mouse_y})");
-        let mouse_pos = Point::from([mouse_x, mouse_y]);
 
         // We store the mouse pos for use in handle_mouse_wheel()
         *self.mouse_pos.lock().unwrap() = mouse_pos.clone();
@@ -798,16 +793,16 @@ impl UIObject for ChatView {
         }
 
         let Ok(rect) = read_rect(self.rect.clone()) else { return false };
-        if !rect.contains(&mouse_pos) {
+        if !rect.contains(mouse_pos) {
             return false
         }
 
-        self.select_line(mouse_y).await;
+        self.select_line(mouse_pos.y).await;
         false
     }
 
-    async fn handle_mouse_wheel(&self, sg: &SceneGraph, wheel_x: f32, wheel_y: f32) -> bool {
-        debug!(target: "ui::chatview", "handle_mouse_wheel({wheel_x}, {wheel_y})");
+    async fn handle_mouse_wheel(&self, sg: &SceneGraph, wheel_pos: &Point) -> bool {
+        //debug!(target: "ui::chatview", "handle_mouse_wheel({wheel_x}, {wheel_y})");
 
         let Ok(rect) = read_rect(self.rect.clone()) else { return false };
 
@@ -817,7 +812,7 @@ impl UIObject for ChatView {
             return false
         }
 
-        self.speed.fetch_add(wheel_y * self.scroll_start_accel.get(), Ordering::Relaxed);
+        self.speed.fetch_add(wheel_pos.y * self.scroll_start_accel.get(), Ordering::Relaxed);
         self.motion_cv.notify();
         true
     }
@@ -827,8 +822,7 @@ impl UIObject for ChatView {
         sg: &SceneGraph,
         phase: TouchPhase,
         id: u64,
-        touch_x: f32,
-        touch_y: f32,
+        touch_pos: &Point,
     ) -> bool {
         // Ignore multi-touch
         if id != 0 {
@@ -838,8 +832,9 @@ impl UIObject for ChatView {
         let Ok(rect) = read_rect(self.rect.clone()) else { return false };
         //debug!(target: "ui::chatview", "handle_touch({phase:?}, {touch_x}, {touch_y})");
 
-        let touch_pos = Point { x: touch_x, y: touch_y };
-        if !rect.contains(&touch_pos) {
+        let touch_y = touch_pos.y;
+
+        if !rect.contains(touch_pos) {
             match phase {
                 TouchPhase::Started => *self.touch_info.lock().unwrap() = None,
                 _ => self.end_touch_phase(touch_y),

+ 17 - 24
bin/darkwallet/src/ui/editbox.rs

@@ -432,13 +432,11 @@ impl EditBox {
         self.redraw().await;
     }
 
-    async fn handle_click_down(&self, btn: MouseButton, mouse_x: f32, mouse_y: f32) {
+    async fn handle_click_down(&self, btn: MouseButton, mouse_pos: &Point) {
         if btn != MouseButton::Left {
             return
         }
 
-        let mouse_pos = Point::from([mouse_x, mouse_y]);
-
         let Some(rect) = self.cached_rect() else { return };
 
         // clicking inside box will:
@@ -454,7 +452,7 @@ impl EditBox {
                 self.is_focused.set(true);
             }
 
-            let cpos = self.find_closest_glyph_idx(mouse_x, &rect);
+            let cpos = self.find_closest_glyph_idx(mouse_pos.x, &rect);
 
             // set cursor pos
             self.cursor_pos.set(cpos);
@@ -478,7 +476,7 @@ impl EditBox {
 
         self.redraw().await;
     }
-    fn handle_click_up(&self, btn: MouseButton, _mouse_x: f32, _mouse_y: f32) {
+    fn handle_click_up(&self, btn: MouseButton, pos: &Point) {
         if btn != MouseButton::Left {
             return
         }
@@ -486,7 +484,7 @@ impl EditBox {
         // releasing mouse button will end selection
         self.mouse_btn_held.store(false, Ordering::Relaxed);
     }
-    async fn handle_cursor_move(&self, mouse_x: f32, _mouse_y: f32) {
+    async fn handle_cursor_move(&self, pos: &Point) {
         if !self.mouse_btn_held.load(Ordering::Relaxed) {
             return;
         }
@@ -497,7 +495,7 @@ impl EditBox {
         // also set cursor_pos too
 
         let Some(rect) = self.cached_rect() else { return };
-        let cpos = self.find_closest_glyph_idx(mouse_x, &rect);
+        let cpos = self.find_closest_glyph_idx(pos.x, &rect);
 
         self.cursor_pos.set(cpos);
         self.selected.set_u32(Role::Internal, 1, cpos).unwrap();
@@ -506,18 +504,16 @@ impl EditBox {
         self.redraw().await;
     }
 
-    async fn handle_touch(&self, phase: TouchPhase, id: u64, touch_x: f32, touch_y: f32) {
+    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_x, touch_y).await
-            }
-            TouchPhase::Moved => self.handle_cursor_move(touch_x, touch_y).await,
-            TouchPhase::Ended => self.handle_click_up(MouseButton::Left, touch_x, touch_y),
+            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 => {}
         }
     }
@@ -1135,14 +1131,13 @@ impl UIObject for EditBox {
         &self,
         sg: &SceneGraph,
         btn: MouseButton,
-        mouse_x: f32,
-        mouse_y: f32,
+        mouse_pos: &Point,
     ) -> bool {
         if !self.is_active.get() {
             return true
         }
 
-        self.handle_click_down(btn, mouse_x, mouse_y).await;
+        self.handle_click_down(btn, mouse_pos).await;
         true
     }
 
@@ -1150,23 +1145,22 @@ impl UIObject for EditBox {
         &self,
         sg: &SceneGraph,
         btn: MouseButton,
-        mouse_x: f32,
-        mouse_y: f32,
+        mouse_pos: &Point,
     ) -> bool {
         if !self.is_active.get() {
             return true
         }
 
-        self.handle_click_up(btn, mouse_x, mouse_y);
+        self.handle_click_up(btn, mouse_pos);
         true
     }
 
-    async fn handle_mouse_move(&self, sg: &SceneGraph, mouse_x: f32, mouse_y: f32) -> bool {
+    async fn handle_mouse_move(&self, sg: &SceneGraph, mouse_pos: &Point) -> bool {
         if !self.is_active.get() {
             return false
         }
 
-        self.handle_cursor_move(mouse_x, mouse_y).await;
+        self.handle_cursor_move(mouse_pos).await;
         false
     }
 
@@ -1175,14 +1169,13 @@ impl UIObject for EditBox {
         sg: &SceneGraph,
         phase: TouchPhase,
         id: u64,
-        touch_x: f32,
-        touch_y: f32,
+        touch_pos: &Point,
     ) -> bool {
         if !self.is_active.get() {
             return true
         }
 
-        self.handle_touch(phase, id, touch_x, touch_y).await;
+        self.handle_touch(phase, id, touch_pos).await;
         true
     }
 }

+ 11 - 14
bin/darkwallet/src/ui/layer.rs

@@ -23,7 +23,7 @@ use rand::{rngs::OsRng, Rng};
 use std::sync::{Arc, Weak};
 
 use crate::{
-    gfx::{GfxDrawCall, GfxDrawInstruction, Rectangle, RenderApiPtr},
+    gfx::{GfxDrawCall, GfxDrawInstruction, Point, Rectangle, RenderApiPtr},
     prop::{PropertyBool, PropertyPtr, PropertyUint32, Role},
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
     ExecutorPtr,
@@ -241,13 +241,12 @@ impl UIObject for RenderLayer {
         &self,
         sg: &SceneGraph,
         btn: MouseButton,
-        mouse_x: f32,
-        mouse_y: f32,
+        mouse_pos: &Point,
     ) -> bool {
         for child_id in get_child_nodes_ordered(&sg, self.node_id) {
             let node = sg.get_node(child_id).unwrap();
             let obj = get_ui_object(node);
-            if obj.handle_mouse_btn_down(sg, btn, mouse_x, mouse_y).await {
+            if obj.handle_mouse_btn_down(sg, btn, mouse_pos).await {
                 return true
             }
         }
@@ -257,33 +256,32 @@ impl UIObject for RenderLayer {
         &self,
         sg: &SceneGraph,
         btn: MouseButton,
-        mouse_x: f32,
-        mouse_y: f32,
+        mouse_pos: &Point,
     ) -> bool {
         for child_id in get_child_nodes_ordered(&sg, self.node_id) {
             let node = sg.get_node(child_id).unwrap();
             let obj = get_ui_object(node);
-            if obj.handle_mouse_btn_up(sg, btn, mouse_x, mouse_y).await {
+            if obj.handle_mouse_btn_up(sg, btn, mouse_pos).await {
                 return true
             }
         }
         false
     }
-    async fn handle_mouse_move(&self, sg: &SceneGraph, mouse_x: f32, mouse_y: f32) -> bool {
+    async fn handle_mouse_move(&self, sg: &SceneGraph, mouse_pos: &Point) -> bool {
         for child_id in get_child_nodes_ordered(&sg, self.node_id) {
             let node = sg.get_node(child_id).unwrap();
             let obj = get_ui_object(node);
-            if obj.handle_mouse_move(sg, mouse_x, mouse_y).await {
+            if obj.handle_mouse_move(sg, mouse_pos).await {
                 return true
             }
         }
         false
     }
-    async fn handle_mouse_wheel(&self, sg: &SceneGraph, wheel_x: f32, wheel_y: f32) -> bool {
+    async fn handle_mouse_wheel(&self, sg: &SceneGraph, wheel_pos: &Point) -> bool {
         for child_id in get_child_nodes_ordered(&sg, self.node_id) {
             let node = sg.get_node(child_id).unwrap();
             let obj = get_ui_object(node);
-            if obj.handle_mouse_wheel(sg, wheel_x, wheel_y).await {
+            if obj.handle_mouse_wheel(sg, wheel_pos).await {
                 return true
             }
         }
@@ -294,13 +292,12 @@ impl UIObject for RenderLayer {
         sg: &SceneGraph,
         phase: TouchPhase,
         id: u64,
-        touch_x: f32,
-        touch_y: f32,
+        touch_pos: &Point,
     ) -> bool {
         for child_id in get_child_nodes_ordered(&sg, self.node_id) {
             let node = sg.get_node(child_id).unwrap();
             let obj = get_ui_object(node);
-            if obj.handle_touch(sg, phase, id, touch_x, touch_y).await {
+            if obj.handle_touch(sg, phase, id, touch_pos).await {
                 return true
             }
         }

+ 6 - 9
bin/darkwallet/src/ui/mod.rs

@@ -23,7 +23,7 @@ use std::sync::{Arc, Weak};
 use crate::{
     error::{Error, Result},
     expr::{SExprMachine, SExprVal},
-    gfx::{GfxBufferId, GfxDrawCall, GfxTextureId, Rectangle},
+    gfx::{GfxBufferId, GfxDrawCall, GfxTextureId, Point, Rectangle},
     prop::{PropertyPtr, Role},
     scene::{Pimpl, SceneGraph, SceneNode, SceneNodeId, SceneNodeType},
     ExecutorPtr,
@@ -76,8 +76,7 @@ pub trait UIObject: Sync {
         &self,
         sg: &SceneGraph,
         btn: MouseButton,
-        mouse_x: f32,
-        mouse_y: f32,
+        mouse_pos: &Point,
     ) -> bool {
         false
     }
@@ -85,15 +84,14 @@ pub trait UIObject: Sync {
         &self,
         sg: &SceneGraph,
         btn: MouseButton,
-        mouse_x: f32,
-        mouse_y: f32,
+        mouse_pos: &Point,
     ) -> bool {
         false
     }
-    async fn handle_mouse_move(&self, sg: &SceneGraph, mouse_x: f32, mouse_y: f32) -> bool {
+    async fn handle_mouse_move(&self, sg: &SceneGraph, mouse_pos: &Point) -> bool {
         false
     }
-    async fn handle_mouse_wheel(&self, sg: &SceneGraph, wheel_x: f32, wheel_y: f32) -> bool {
+    async fn handle_mouse_wheel(&self, sg: &SceneGraph, wheel_pos: &Point) -> bool {
         false
     }
     async fn handle_touch(
@@ -101,8 +99,7 @@ pub trait UIObject: Sync {
         sg: &SceneGraph,
         phase: TouchPhase,
         id: u64,
-        touch_x: f32,
-        touch_y: f32,
+        touch_pos: &Point,
     ) -> bool {
         false
     }

+ 26 - 26
bin/darkwallet/src/ui/win.rs

@@ -20,7 +20,7 @@ use miniquad::{KeyCode, KeyMods, MouseButton, TouchPhase};
 use std::sync::{Arc, Weak};
 
 use crate::{
-    gfx::{GfxDrawCall, GraphicsEventPublisherPtr, Rectangle, RenderApiPtr},
+    gfx::{GfxDrawCall, GraphicsEventPublisherPtr, Point, Rectangle, RenderApiPtr},
     prop::{PropertyPtr, Role},
     pubsub::Subscription,
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
@@ -209,9 +209,9 @@ impl Window {
 
     async fn process_mouse_btn_down(
         me: &Weak<Self>,
-        ev_sub: &Subscription<(MouseButton, f32, f32)>,
+        ev_sub: &Subscription<(MouseButton, Point)>,
     ) -> bool {
-        let Ok((btn, mouse_x, mouse_y)) = ev_sub.receive().await else {
+        let Ok((btn, mouse_pos)) = ev_sub.receive().await else {
             debug!(target: "ui::editbox", "Event relayer closed");
             return false
         };
@@ -221,15 +221,15 @@ impl Window {
             panic!("self destroyed before mouse_btn_down_task was stopped!");
         };
 
-        self_.handle_mouse_btn_down(btn, mouse_x, mouse_y).await;
+        self_.handle_mouse_btn_down(btn, mouse_pos).await;
         true
     }
 
     async fn process_mouse_btn_up(
         me: &Weak<Self>,
-        ev_sub: &Subscription<(MouseButton, f32, f32)>,
+        ev_sub: &Subscription<(MouseButton, Point)>,
     ) -> bool {
-        let Ok((btn, mouse_x, mouse_y)) = ev_sub.receive().await else {
+        let Ok((btn, mouse_pos)) = ev_sub.receive().await else {
             debug!(target: "ui::editbox", "Event relayer closed");
             return false
         };
@@ -239,12 +239,12 @@ impl Window {
             panic!("self destroyed before mouse_btn_up_task was stopped!");
         };
 
-        self_.handle_mouse_btn_up(btn, mouse_x, mouse_y).await;
+        self_.handle_mouse_btn_up(btn, mouse_pos).await;
         true
     }
 
-    async fn process_mouse_move(me: &Weak<Self>, ev_sub: &Subscription<(f32, f32)>) -> bool {
-        let Ok((mouse_x, mouse_y)) = ev_sub.receive().await else {
+    async fn process_mouse_move(me: &Weak<Self>, ev_sub: &Subscription<Point>) -> bool {
+        let Ok(mouse_pos) = ev_sub.receive().await else {
             debug!(target: "ui::editbox", "Event relayer closed");
             return false
         };
@@ -254,12 +254,12 @@ impl Window {
             panic!("self destroyed before mouse_move_task was stopped!");
         };
 
-        self_.handle_mouse_move(mouse_x, mouse_y).await;
+        self_.handle_mouse_move(mouse_pos).await;
         true
     }
 
-    async fn process_mouse_wheel(me: &Weak<Self>, ev_sub: &Subscription<(f32, f32)>) -> bool {
-        let Ok((wheel_x, wheel_y)) = ev_sub.receive().await else {
+    async fn process_mouse_wheel(me: &Weak<Self>, ev_sub: &Subscription<Point>) -> bool {
+        let Ok(wheel_pos) = ev_sub.receive().await else {
             debug!(target: "ui::chatview", "Event relayer closed");
             return false
         };
@@ -269,15 +269,15 @@ impl Window {
             panic!("self destroyed before mouse_wheel_task was stopped!");
         };
 
-        self_.handle_mouse_wheel(wheel_x, wheel_y).await;
+        self_.handle_mouse_wheel(wheel_pos).await;
         true
     }
 
     async fn process_touch(
         me: &Weak<Self>,
-        ev_sub: &Subscription<(TouchPhase, u64, f32, f32)>,
+        ev_sub: &Subscription<(TouchPhase, u64, Point)>,
     ) -> bool {
-        let Ok((phase, id, touch_x, touch_y)) = ev_sub.receive().await else {
+        let Ok((phase, id, touch_pos)) = ev_sub.receive().await else {
             debug!(target: "ui::editbox", "Event relayer closed");
             return false
         };
@@ -287,7 +287,7 @@ impl Window {
             panic!("self destroyed before touch_task was stopped!");
         };
 
-        self_.handle_touch(phase, id, touch_x, touch_y).await;
+        self_.handle_touch(phase, id, touch_pos).await;
         true
     }
 
@@ -327,61 +327,61 @@ impl Window {
         }
     }
 
-    async fn handle_mouse_btn_down(&self, btn: MouseButton, mouse_x: f32, mouse_y: f32) {
+    async fn handle_mouse_btn_down(&self, btn: MouseButton, mouse_pos: Point) {
         let sg = self.sg.lock().await;
 
         for child_id in get_child_nodes_ordered(&sg, self.node_id) {
             let node = sg.get_node(child_id).unwrap();
             let obj = get_ui_object(node);
-            if obj.handle_mouse_btn_down(&sg, btn.clone(), mouse_x, mouse_y).await {
+            if obj.handle_mouse_btn_down(&sg, btn.clone(), &mouse_pos).await {
                 return
             }
         }
     }
 
-    async fn handle_mouse_btn_up(&self, btn: MouseButton, mouse_x: f32, mouse_y: f32) {
+    async fn handle_mouse_btn_up(&self, btn: MouseButton, mouse_pos: Point) {
         let sg = self.sg.lock().await;
 
         for child_id in get_child_nodes_ordered(&sg, self.node_id) {
             let node = sg.get_node(child_id).unwrap();
             let obj = get_ui_object(node);
-            if obj.handle_mouse_btn_up(&sg, btn.clone(), mouse_x, mouse_y).await {
+            if obj.handle_mouse_btn_up(&sg, btn.clone(), &mouse_pos).await {
                 return
             }
         }
     }
 
-    async fn handle_mouse_move(&self, mouse_x: f32, mouse_y: f32) {
+    async fn handle_mouse_move(&self, mouse_pos: Point) {
         let sg = self.sg.lock().await;
 
         for child_id in get_child_nodes_ordered(&sg, self.node_id) {
             let node = sg.get_node(child_id).unwrap();
             let obj = get_ui_object(node);
-            if obj.handle_mouse_move(&sg, mouse_x, mouse_y).await {
+            if obj.handle_mouse_move(&sg, &mouse_pos).await {
                 return
             }
         }
     }
 
-    async fn handle_mouse_wheel(&self, wheel_x: f32, wheel_y: f32) {
+    async fn handle_mouse_wheel(&self, wheel_pos: Point) {
         let sg = self.sg.lock().await;
 
         for child_id in get_child_nodes_ordered(&sg, self.node_id) {
             let node = sg.get_node(child_id).unwrap();
             let obj = get_ui_object(node);
-            if obj.handle_mouse_wheel(&sg, wheel_x, wheel_y).await {
+            if obj.handle_mouse_wheel(&sg, &wheel_pos).await {
                 return
             }
         }
     }
 
-    async fn handle_touch(&self, phase: TouchPhase, id: u64, touch_x: f32, touch_y: f32) {
+    async fn handle_touch(&self, phase: TouchPhase, id: u64, touch_pos: Point) {
         let sg = self.sg.lock().await;
 
         for child_id in get_child_nodes_ordered(&sg, self.node_id) {
             let node = sg.get_node(child_id).unwrap();
             let obj = get_ui_object(node);
-            if obj.handle_touch(&sg, phase, id, touch_x, touch_y).await {
+            if obj.handle_touch(&sg, phase, id, &touch_pos).await {
                 return
             }
         }