feat: scroll constraints refactor#720
Open
barnabasmolnar wants to merge 26 commits into
Open
Conversation
* Allow clicking links in non-interactive mode. * better embed ux when interactivity=false --------- Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
75e6d68 to
3ef8ea0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Real flesh & blood human summary. A bit lengthy but more context:
This PR is a refactor of the
scrollConstraintsfeature. Its main aims are as follows:scrollToContent()with an optionalscrollLockmode (especially useful for presentations on E+)scrollConstraintsare set539244896-6ac91709-6fb7-44ba-a96a-28357384e340.mp4
This behaviour occurs, as far as I can tell, because zooming in non-centre points can easily produce a state in which the constrained area will go out of bounds of the viewport. When you place your mouse cursor somewhere in the scene, that essentially becomes your zoom anchor. In a normal, non-constrained scenario, that's perfectly fine. Here, we have to recalculate the constraints on every zoom level in order to keep the constrained area in the viewport. The original implementation does this in the following way:
My proposed solution for this is to adjust the zoom anchor when a zoom would otherwise produce an out-of-bounds state. This does mean that your mouse cursor will not always be the true anchor for zooming. Initially, I was somewhat worried that it would feel unnatural. But after playing around with it for quite a while, I'm finding this much more preferable and natural to the snapping/yanking back behaviour demonstrated in the video.
These changes will enable the following use cases:
An example of the presentation use case can be seen in this video:
Code.Q0cqgjsfrq.mp4
AI Summary of changes, short and sweet
This PR adds an opt-in way to lock
scrollToContent()to the content it just framed, and it also improvesscrollConstraintsso constrained zooming/panning feels stable instead of snapping the viewport around when the zoom anchor would otherwise move the camera out of bounds.What changed
scrollToContent()now supports an optionalscrollLockmodescrollToContent()derives its constraints from the same viewport calculation used to frame the target contentscrollConstraintsnow keep the viewport stable by adjusting the zoom anchor when a zoom would otherwise produce an out-of-bounds stateWhy
For presentations, host apps often need to:
Before this change, host apps had to combine
scrollToContent()andsetScrollConstraints()manually, which could lead to race conditions and slightly mismatched zoom levels.At the same time, constrained zooming could feel janky because zooming near the boundary could pull the viewport away from the user’s intended focus. This happened because the previous implementation first applied the normal zoom anchor and only then corrected the viewport back into bounds, which could result in visible snapping near the edges of the constrained area.
This PR makes that flow much smoother:
scrollToContent()can now frame and lock in one step