Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Gesture Detector #3

Open
toiglak opened this issue Oct 21, 2022 · 1 comment
Open

Gesture Detector #3

toiglak opened this issue Oct 21, 2022 · 1 comment

Comments

@toiglak
Copy link
Member

toiglak commented Oct 21, 2022

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.

@toiglak
Copy link
Member Author

toiglak commented Nov 7, 2022

PointerListener and PointerRegion were implemented in #10.

@toiglak toiglak changed the title Pointer events Gesture Detector Nov 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant