frui
frui copied to clipboard
Gesture Detector
Frui needs an easy way to handle pointer events. In this issue I wanted to document the overall API I am planning.
✅ Pointer Listener
Widget that responds to low-level pointer events.
PointerListener::builder()
.on_pointer_down(|e| { ... })
.on_pointer_up(|e| { ... })
.on_pointer_scroll(|e| { ... })
✅ Pointer Region
Widget that responds to pointer entering child's widget region. It also allows changing cursor icon (e.g. to a pointer icon when hovering over a button).
PointerRegion::builder()
.cursor(Cursor::Pointer)
.on_enter(|e| { ... })
.on_move(|e| { ... })
.on_exit(|e| { ... })
Gesture Detector
Widget that distinguishes between different high-level gestures.
GestureDetector::builder()
.on_tap(|e| { ... })
.on_double_tap(|e| { ... })
.on_vertical_drag(|e| { ... })
// ...
I was thinking about adding an ability to directly extend that widget with custom gestures:
fn add_gesture<G: Gesture>(self, gesture: G, callback: impl Fn(G::Event)) -> Self {
// ...
}
Above builder method could then be abstracted using extension trait and used like:
GestureDetector::builder()
.on_tap(|_| { ... })
.on_my_custom_gesture(|_| { ... })
As of now, I am working on implementing PointerListener
and KeyboardListener
(other issue).
GestureDetector
is a little bit tricky to implement and not that useful on PC, so I plan to implement it later when we will focus on supporting mobile devices. For now, PointerListener
and PointerRegion
should be enough for handling input on PC.
PointerListener
and PointerRegion
were implemented in https://github.com/fruiframework/frui/pull/10.