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

[Feature Request] Automatically move the viewport when dragging a node close to the canvas borders #516

Open
2 tasks done
LotzF opened this issue Feb 10, 2025 · 0 comments

Comments

@LotzF
Copy link

LotzF commented Feb 10, 2025

Is there an existing issue for this?

What would your feature do ?

The moment a user drags an item/link connector close to the border of the canvas the viewport should start moving in the same direction.

Screencast.from.2025-02-10.20-04-47.mp4

Proposed workflow

  1. Drag a node close to the edges of the viewport
  2. Update the viewport and node position based on the mouse location using the draw tick and delta time
  3. Expose threshold and speed multiplier inside the UI settings

Implementation

Update using DeltaT:
Instead of purely updating the position based on the tick/draw event we use delta T to make sure the movement stays consistent otherwise the speed would vary depending on the fps

Poor mans normalized Vector2:
Instead of using an actual normalized Vector2 we'll clamp the calculated vector to a range between [-1,1].
There's no need for a real unit vector. This way we save a sqrt calculation to increase the performance.

Updates when dragging a Positionable or Link connector:
Due to the function adding to the draw loop we'll only run it when dragging around an object but it could be used for general panning as well by setting it active when pressing the middle mouse button (panning mode)

TODO: Add movement multiplier and threshold to UI settings

PS: I tried to adapt as many of your code conventions as possible but I might have overdone it with the code comments/descriptions. Please let me know what you think.

Cheers,
Leo

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

1 participant