-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add CanvasPointer API #308
Merged
Merged
Conversation
This file contains 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
Replaces previous impls. which only worked on some items, and were triggered when unexpected e.g. clicking a node that hadn't been moved. Update test expectations
Marks as deprecated
Add TS strict types Add final click drag distance math Add option to retain events
Unused, not maintained.
Remove live_mode reference
Incomplete impl. - unused. Superceded by selectedItems
LGraphNode.getWidgetOnPos
- Rewrites most pointer handling to use CanvasPointer callbacks - All callbacks are declared ahead of time during the initial pointerdown event, logically grouped together - Drastically simplifies the alteration or creation of new click / drag interactions - Click events are all clicks, rather than some processed on mouse down, others on mouse up - Functions return instead of setting and repeatedly checking multiple state vars - Removes all lines that needed THIRTEEN tab indents
Replaces original workarounds with final types
- Centralises cursor set behaviour - Provides simple downstream override
Old behaviour was to disconnect, then recreate a new link on drop.
huchenlei
approved these changes
Nov 16, 2024
Do note that |
This was referenced Nov 20, 2024
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.
Default behaviour changes
This is a fundamental change to the way Litegraph handles pointer interaction. Each pointer event is now tracked and managed by a
CanvasPointer
, created by the canvas asLGraphCanvas.pointer
.Bug fixes
For users, a lot of the change will be subtle, but it should "feel" more like a stable, native app. It should also result in fewer unexpected changes in the future.
For devs, the process to add / change click & drag actions has been drastically simplified.
Selecting multiple items
Ctrl + drag
- Begin multi-selectCtrl + Shift + drag
- Add to selectionCtrl + drag
,Shift
- Alternate add to selectionCtrl + drag
,Alt
- Remove from selectionClick "drift"
A small amount of buffering is performed between down/up events to prevent accidental micro-drag events. If either of the two controls are exceeded, the event will be considered a drag event, not a click.
buffterTime
is the maximum time that tiny movements can be ignored (Default: 150ms)maxClickDrift
controls how far a click can drift from its down event before it is considered a drag (Default: 6)Double-click
When double clicking, the double click callback is executed shortly after one normal click callback (if present). At present, dragging from the second click simply invalidates the event - nothing will happen.
doubleClickTime
is the maximum time between twodown
events for them to be considered a double click (Default: 300ms)3 * maxClickDrift
Configuration
All above configuration is via class static. Could be converted to instance-based.
Implementing
Clicking, double-clicking, and dragging can now all be configured during the initial
pointerdown
event, and the correct callback(s) will be executed.A click event can be as simple as:
Full usage can be seen in the old
processMouseDown
handler, which is still in place (several monkey patches in the wild).Registering a click or drag event
Example usage:
Hovering over
Adds API for downstream consumers to handle custom cursors. A bitwise enum of items,
Removed public interfaces
All are unused and incomplete. Have bugs beyond just typescript typing, and are (currently) not worth maintaining. If any of these features are desired down the track, they can be reimplemented.
dragged_node