Skip to content

Commit cbcf581

Browse files
authored
Merge pull request #79 from ruza-net/main
key and drag pass events to child
2 parents 97fbdef + 810ec6e commit cbcf581

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/views/drag.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ pub struct DragFunc<F> {
2626
pub f: F,
2727
}
2828

29-
impl<A: 'static, F: Fn(&mut Context, LocalOffset, GestureState, Option<MouseButton>) -> A + Clone> DragFn
30-
for DragFunc<F>
29+
impl<
30+
A: 'static,
31+
F: Fn(&mut Context, LocalOffset, GestureState, Option<MouseButton>) -> A + Clone,
32+
> DragFn for DragFunc<F>
3133
{
3234
fn call(
3335
&self,
@@ -47,8 +49,10 @@ pub struct DragFuncP<F> {
4749
pub f: F,
4850
}
4951

50-
impl<A: 'static, F: Fn(&mut Context, LocalPoint, GestureState, Option<MouseButton>) -> A + Clone> DragFn
51-
for DragFuncP<F>
52+
impl<
53+
A: 'static,
54+
F: Fn(&mut Context, LocalPoint, GestureState, Option<MouseButton>) -> A + Clone,
55+
> DragFn for DragFuncP<F>
5256
{
5357
fn call(
5458
&self,
@@ -183,7 +187,11 @@ where
183187
);
184188
}
185189
}
186-
_ => (),
190+
_ => {
191+
path.push(0);
192+
self.child.process(event, path, cx, actions);
193+
path.pop();
194+
}
187195
}
188196
}
189197

src/views/key.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,27 @@ where
4747
fn process(
4848
&self,
4949
event: &Event,
50-
_path: &mut IdPath,
50+
path: &mut IdPath,
5151
cx: &mut Context,
5252
actions: &mut Vec<Box<dyn Any>>,
5353
) {
5454
match self.kind {
5555
KeyViewKind::Pressed => {
5656
if let Event::Key(key) = &event {
57-
actions.push(Box::new((self.func)(cx, key.clone())));
57+
actions.push(Box::new((self.func)(cx, *key)));
58+
} else {
59+
path.push(0);
60+
self.child.process(event, path, cx, actions);
61+
path.pop();
5862
}
5963
}
6064
KeyViewKind::Released => {
6165
if let Event::KeyReleased(key) = &event {
62-
actions.push(Box::new((self.func)(cx, key.clone())));
66+
actions.push(Box::new((self.func)(cx, *key)));
67+
} else {
68+
path.push(0);
69+
self.child.process(event, path, cx, actions);
70+
path.pop();
6371
}
6472
}
6573
}

0 commit comments

Comments
 (0)