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

fix!: Add DisplacementEvent to fix delta coordinate transformations for drag events #2871

Merged
merged 13 commits into from
Nov 30, 2023

Conversation

luanpotter
Copy link
Member

@luanpotter luanpotter commented Nov 26, 2023

Description

This adds DisplacementEvent to fix delta coordinate transformations for drag events, to be used instead of PositionEvent.
Drag Events now expose the start and end position, as well as the delta, correctly transformed by the camera and zoom.
This also ensures that drag events, once starts, do not get lost if the drag update leaves the component bounds.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Migration instructions

  • if you are using DragUpdateEvent events, the devicePosition, canvasPosition, localPosition, and delta are deprecated as they are unclear.
  • use xStartPosition to get the position at the start of the drag event ("from")
  • use xEndPosition to get the position at the end of the drag event ("to")
  • if you want the delta, use localDelta. it now already considers the camera zoom. no need to manually account for that
  • now you keep receiving drag events for the same component even if the mouse leaves the component (breaking)

Related Issues

This fixes #2843

@luanpotter luanpotter force-pushed the luan.spydon.fix-delta branch 3 times, most recently from f6d2ba1 to 2b8d1bb Compare November 26, 2023 17:07
);

final int pointerId;
final Duration timestamp;
final Vector2 delta;

static final _nanPoint = Vector2.all(double.nan);
Copy link
Member Author

Choose a reason for hiding this comment

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

yay!

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

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

Lgtm, just one comment

@luanpotter luanpotter marked this pull request as ready for review November 30, 2023 15:03
@spydon spydon merged commit 63994eb into main Nov 30, 2023
8 checks passed
@spydon spydon deleted the luan.spydon.fix-delta branch November 30, 2023 15:40
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.

Correctly project drag deltas in the DragEvents
2 participants