From 2da39523dcfaea8bf2acfbf8607a63b2fa6bedaf Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Sat, 21 Dec 2024 21:30:29 +0700 Subject: [PATCH] Implements RuntimeWindow::on_cursor_left (#1195) --- gui/src/rt/mod.rs | 40 +++++++++++++++++++++--------------- gui/src/rt/window.rs | 1 + gui/src/ui/backend/window.rs | 5 +++++ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/gui/src/rt/mod.rs b/gui/src/rt/mod.rs index 003848b3c..176160ddc 100644 --- a/gui/src/rt/mod.rs +++ b/gui/src/rt/mod.rs @@ -198,7 +198,7 @@ impl ApplicationHandler for Runtime { // Process the event. let e = match event { WindowEvent::Resized(v) => match self.dispatch_window(el, id, |w| w.on_resized(v)) { - Some(Err(e)) => RuntimeError::UpdateWindowSize(e), + Some(Err(e)) => RuntimeError::Resized(e), _ => return, }, WindowEvent::CloseRequested => { @@ -212,27 +212,32 @@ impl ApplicationHandler for Runtime { return; } WindowEvent::Focused(v) => match self.dispatch_window(el, id, |w| w.on_focused(v)) { - Some(Err(e)) => RuntimeError::ChangeActiveWindow(e), + Some(Err(e)) => RuntimeError::Focused(e), _ => return, }, WindowEvent::CursorMoved { device_id: dev, position: pos, } => match self.dispatch_window(el, id, move |w| w.on_cursor_moved(dev, pos)) { - Some(Err(e)) => RuntimeError::UpdateWindowCursor(e), + Some(Err(e)) => RuntimeError::CursorMoved(e), _ => return, }, - WindowEvent::CursorLeft { device_id } => todo!(), + WindowEvent::CursorLeft { device_id: dev } => { + match self.dispatch_window(el, id, move |w| w.on_cursor_left(dev)) { + Some(Err(e)) => RuntimeError::CursorLeft(e), + _ => return, + } + } WindowEvent::ScaleFactorChanged { scale_factor: new, inner_size_writer: sw, } => match self.dispatch_window(el, id, move |w| w.on_scale_factor_changed(new, sw)) { - Some(Err(e)) => RuntimeError::UpdateWindowScaleFactor(e), + Some(Err(e)) => RuntimeError::ScaleFactorChanged(e), _ => return, }, WindowEvent::RedrawRequested => { match self.dispatch_window(el, id, |w| w.on_redraw_requested()) { - Some(Err(e)) => RuntimeError::RedrawWindow(e), + Some(Err(e)) => RuntimeError::RedrawRequested(e), _ => return, } } @@ -266,18 +271,21 @@ pub enum RuntimeError { #[error("couldn't create runtime window")] CreateRuntimeWindow(#[source] Box), - #[error("couldn't update window size")] - UpdateWindowSize(#[source] Box), + #[error("couldn't handle window resized")] + Resized(#[source] Box), + + #[error("couldn't handle window focused")] + Focused(#[source] Box), - #[error("couldn't change active window")] - ChangeActiveWindow(#[source] Box), + #[error("couldn't handle cursor moved")] + CursorMoved(#[source] Box), - #[error("couldn't update window cursor")] - UpdateWindowCursor(#[source] Box), + #[error("couldn't handle cursor left")] + CursorLeft(#[source] Box), - #[error("couldn't update window scale factor")] - UpdateWindowScaleFactor(#[source] Box), + #[error("couldn't handle scale factor changed")] + ScaleFactorChanged(#[source] Box), - #[error("couldn't redraw the window")] - RedrawWindow(#[source] Box), + #[error("couldn't handle redraw requested")] + RedrawRequested(#[source] Box), } diff --git a/gui/src/rt/window.rs b/gui/src/rt/window.rs index c7ba0cc01..5eb8606d5 100644 --- a/gui/src/rt/window.rs +++ b/gui/src/rt/window.rs @@ -13,6 +13,7 @@ pub trait RuntimeWindow { dev: DeviceId, pos: PhysicalPosition, ) -> Result<(), Box>; + fn on_cursor_left(&self, dev: DeviceId) -> Result<(), Box>; fn on_scale_factor_changed( &self, new: f64, diff --git a/gui/src/ui/backend/window.rs b/gui/src/ui/backend/window.rs index d5deec6ce..d3d55dcf5 100644 --- a/gui/src/ui/backend/window.rs +++ b/gui/src/ui/backend/window.rs @@ -72,6 +72,11 @@ impl RuntimeWindow for Window { Ok(()) } + fn on_cursor_left(&self, _: DeviceId) -> Result<(), Box> { + self.slint.dispatch_event(WindowEvent::PointerExited); + Ok(()) + } + fn on_scale_factor_changed( &self, new: f64,