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

Mouse enter/exit events, and full click behavior #198

Open
monodop opened this issue Jan 14, 2025 · 1 comment
Open

Mouse enter/exit events, and full click behavior #198

monodop opened this issue Jan 14, 2025 · 1 comment

Comments

@monodop
Copy link
Contributor

monodop commented Jan 14, 2025

In many user interfaces, a "click" on an element only occurs if the mouse was pressed and released within the bounds of the element, even if the mouse has moved outside of that element:

click example

I'm not really sure how to replicate this behavior with clay today. OnHover fires only if the cursor is within the bounds of the element, which means that you could replicate most of the functionality with what we have today:

mostly click example

However, to achieve this required manually tracking whether or not the click started within the element, as well as extra logic in the layout phase to reset the clickStarted state if hover ends (which is not actually desired, since we really want the click to continue until the next time the mouse is released)

Some ideas that might help:

  • OnMouseEnter and OnMouseExit events that are called when the mouse enters or exits the region
  • A built-in OnClick event that tracks pointer start and stop for you, so that we don't have to store this extra state for each element
  • Being able to request the element id (or list of element ids) that the click originated on, and perhaps the coordinates of that click
@StartForKiller
Copy link

StartForKiller commented Jan 25, 2025

In many user interfaces, a "click" on an element only occurs if the mouse was pressed and released within the bounds of the element, even if the mouse has moved outside of that element:

click example click example

I'm not really sure how to replicate this behavior with clay today. OnHover fires only if the cursor is within the bounds of the element, which means that you could replicate most of the functionality with what we have today:

mostly click example mostly click example

However, to achieve this required manually tracking whether or not the click started within the element, as well as extra logic in the layout phase to reset the clickStarted state if hover ends (which is not actually desired, since we really want the click to continue until the next time the mouse is released)

Some ideas that might help:

  • OnMouseEnter and OnMouseExit events that are called when the mouse enters or exits the region
  • A built-in OnClick event that tracks pointer start and stop for you, so that we don't have to store this extra state for each element
  • Being able to request the element id (or list of element ids) that the click originated on, and perhaps the coordinates of that click

We could create some macros, but OnMouseEnter is really just checking the hover, thats actually implemented. For checking the clocked "button", just store a variable yourself when pointerInfo.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME inside the onhover callback of an element. Clay allows both of the above described behaviours, it's program side task to handle it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants