Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for various mouse APIs, useMouseOver, 'useMouseOffset', etc #206

Open
esDotDev opened this issue Dec 21, 2020 · 4 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@esDotDev
Copy link

Is your feature request related to a problem? Please describe.
It's cumbersome to manually create desktop effects for the mouse cursor. We need to either use a StatefulWidget w/ MouseRegion widget 2 event listeners, and an internal _isMouseDown bool, or some combination of nested Build widgets.

Similarly, getting the mouse position is a fairly verbose process of using MouseRegion, some local Offset, and maybe a globalToLocal call on the context.

Describe the solution you'd like
bool isMouseOver = useMouseOver();
Offset mousePos = useMouseOffset();
Offset localMousePos = useMouseOffset(local: true);

@esDotDev esDotDev added enhancement New feature or request needs triage labels Dec 21, 2020
@rrousselGit
Copy link
Owner

It's feasible but needs adding support for mounting RenderObjects using hooks.

Doable, but requires a bit of work.

@esDotDev
Copy link
Author

esDotDev commented Dec 22, 2020

Nice! I took a stab at it, but am really out of my depth when trying to use gesture detection manually without a widget. Cant find a clear code example anywhere on how this would actually be setup.

@davidmartos96
Copy link
Contributor

It's feasible but needs adding support for mounting RenderObjects using hooks.

Doable, but requires a bit of work.

Would such addition provide the possibility to create a hook like useConstraints, the equivalent to a LayoutBuilder?
That would be very useful for responsive UI related hooks and extract common logic in the app.

For example a custom hook like:
useAvailableSpace(). It could return an enum (narrow, medium, wide) by using the constraints hook under the hood.

@rrousselGit
Copy link
Owner

LayoutBuilder is special

I don't think it's feasible to implement as a hook. The main issue is, it invokes its builder asynchronously. So hooks wouldn't be able to synchronously get the value

@rrousselGit rrousselGit self-assigned this May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants