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

Use Pointer Lock For Scrubbing #6239

Merged
merged 7 commits into from
Aug 21, 2024

Conversation

seanparsons
Copy link
Contributor

@seanparsons seanparsons commented Aug 19, 2024

Problem:
Utopia input labels are scrubbable, but this scrubbing suffers from a number of issues:

  • it is slow to update the inspector and canvas
  • since the inspector is close to the edge of the screen, it sometimes means you run out of room (esp for large positive numbers like left)
  • the mouse can trigger hover effects on the canvas or other inputs, which looks unprofessional

Fix:
The previous scrubbing implementation has been completely replaced in favour of an implementation which uses pointer locking to achieve the same effect. This has resulted in some slightly more complicated handling around tracking the accumulated movement.

Handling the "cleanup" of event handlers is also a little more complicated than before because it repeatedly tended towards callbacks that were circularly referenced.

Commit Details:

  • Changed some const functions to regular functions.
  • Removed the redundant y dragging for scrubbing as it wasn't used.
  • Added some additional React refs to help keep track of what has occurred.
  • Reworked the old scrub event handlers with the pointer lock based event handlers.

Manual Tests:
I hereby swear that:

  • I opened a hydrogen project and it loaded
  • I could navigate to various routes in Preview mode

Fixes #6196

- Changed some const functions to regular functions.
- Removed the redundant y dragging for scrubbing as it wasn't used.
- Added some additional React refs to help keep track of what has
  occurred.
- Reworked the old scrub event handlers with the pointer lock based
  event handlers.
Copy link
Contributor

github-actions bot commented Aug 19, 2024

Try me

Copy link

relativeci bot commented Aug 19, 2024

#13892 Bundle Size — 62.49MiB (~+0.01%).

bf83092(current) vs 6339ece master#13891(baseline)

Warning

Bundle contains 70 duplicate packages – View duplicate packages

Bundle metrics  Change 3 changes Regression 1 regression
                 Current
#13892
     Baseline
#13891
Regression  Initial JS 45.63MiB(+0.01%) 45.62MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 21.52% 22.16%
No change  Chunks 30 30
No change  Assets 33 33
No change  Modules 4373 4373
No change  Duplicate Modules 519 519
Change  Duplicate Code 31.65%(+0.03%) 31.64%
No change  Packages 472 472
No change  Duplicate Packages 70 70
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
#13892
     Baseline
#13891
Regression  JS 62.48MiB (~+0.01%) 62.48MiB
Improvement  HTML 11.05KiB (-0.33%) 11.09KiB

Bundle analysis reportBranch refactor/use-pointer-lock-for-sc...Project dashboard


Generated by RelativeCIDocumentationReport issue

Comment on lines +423 to +431
scrubbingCleanupCallbacks.current.push(() => {
window.removeEventListener('mouseup', scrubOnMouseUp)
})
scrubbingCleanupCallbacks.current.push(() => {
window.removeEventListener('mousemove', scrubOnMouseMove)
})
scrubbingCleanupCallbacks.current.push(() => {
document.removeEventListener('pointerlockchange', checkPointerLockChange, true)
})
Copy link
Contributor

@Rheeseyb Rheeseyb Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to push these callbacks to a ref of an array like this? It seems to me that in both cleanup sites (checkPointerLockChange and scrubOnMouseUp) we could just call a single function that removes these 3 event listeners regardless of the circumstances

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I referenced this in the description, the issue was that I kept ending up with circular references between the callbacks, as their dependencies need to be declared before the callbacks which use them. This means that the function which triggers the cleanup doesn't depend on the event listeners, which snips a convenient gap in the circle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhh.... ew.... ok, can you add that in a comment here please too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8e2c64b.

Copy link
Contributor

@ruggi ruggi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but there's an issue that I'm not sure whether should be addressed in this PR or in an upcoming one (I'd say the latter tbh): if while scrubbing a value the cursor ends up over another scrubbable input, the scrubbing bails

@Rheeseyb
Copy link
Contributor

lgtm, but there's an issue that I'm not sure whether should be addressed in this PR or in an upcoming one (I'd say the latter tbh): if while scrubbing a value the cursor ends up over another scrubbable input, the scrubbing bails

That to me sounds like it should be addressed before merging this PR, as I don't believe that's an issue with the existing implementation (though I may be wrong)

@seanparsons
Copy link
Contributor Author

lgtm, but there's an issue that I'm not sure whether should be addressed in this PR or in an upcoming one (I'd say the latter tbh): if while scrubbing a value the cursor ends up over another scrubbable input, the scrubbing bails

Interesting, definitely should be addressed in this, I don't remember ever seeing this but I wonder if the browser is still tracking the real position and I've coincidentally dragged around the other fields.

@seanparsons
Copy link
Contributor Author

lgtm, but there's an issue that I'm not sure whether should be addressed in this PR or in an upcoming one (I'd say the latter tbh): if while scrubbing a value the cursor ends up over another scrubbable input, the scrubbing bails

I've created a new bug for this as it's a pre-existing issue and can be triggered in other ways: #6249

@seanparsons seanparsons merged commit 274c47c into master Aug 21, 2024
@seanparsons seanparsons deleted the refactor/use-pointer-lock-for-scrubbing branch August 21, 2024 14:04
liady pushed a commit that referenced this pull request Dec 13, 2024
- Changed some const functions to regular functions.
- Removed the redundant y dragging for scrubbing as it wasn't used.
- Added some additional React refs to help keep track of what has
occurred.
- Reworked the old scrub event handlers with the pointer lock based
event handlers.
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

Successfully merging this pull request may close these issues.

Label scrubbing should use pointerLock and wrap around the screen
3 participants