From 810ec6e16c178036b8a4c965a5720ec932f4cb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20R=C5=AF=C5=BEi=C4=8Dka?= Date: Wed, 26 Mar 2025 18:34:20 +0100 Subject: [PATCH] key and drag pass events to child --- src/views/drag.rs | 18 +++++++++++++----- src/views/key.rs | 14 +++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/views/drag.rs b/src/views/drag.rs index cc93ed1..a36fdb7 100644 --- a/src/views/drag.rs +++ b/src/views/drag.rs @@ -26,8 +26,10 @@ pub struct DragFunc { pub f: F, } -impl) -> A + Clone> DragFn - for DragFunc +impl< + A: 'static, + F: Fn(&mut Context, LocalOffset, GestureState, Option) -> A + Clone, + > DragFn for DragFunc { fn call( &self, @@ -47,8 +49,10 @@ pub struct DragFuncP { pub f: F, } -impl) -> A + Clone> DragFn - for DragFuncP +impl< + A: 'static, + F: Fn(&mut Context, LocalPoint, GestureState, Option) -> A + Clone, + > DragFn for DragFuncP { fn call( &self, @@ -183,7 +187,11 @@ where ); } } - _ => (), + _ => { + path.push(0); + self.child.process(event, path, cx, actions); + path.pop(); + } } } diff --git a/src/views/key.rs b/src/views/key.rs index 288fafa..839bc5b 100644 --- a/src/views/key.rs +++ b/src/views/key.rs @@ -47,19 +47,27 @@ where fn process( &self, event: &Event, - _path: &mut IdPath, + path: &mut IdPath, cx: &mut Context, actions: &mut Vec>, ) { match self.kind { KeyViewKind::Pressed => { if let Event::Key(key) = &event { - actions.push(Box::new((self.func)(cx, key.clone()))); + actions.push(Box::new((self.func)(cx, *key))); + } else { + path.push(0); + self.child.process(event, path, cx, actions); + path.pop(); } } KeyViewKind::Released => { if let Event::KeyReleased(key) = &event { - actions.push(Box::new((self.func)(cx, key.clone()))); + actions.push(Box::new((self.func)(cx, *key))); + } else { + path.push(0); + self.child.process(event, path, cx, actions); + path.pop(); } } }