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

⚡ Improve window.setDraggableRegion and add options to allow native-feeling behavior. #120

Merged
merged 2 commits into from
Aug 10, 2024

Conversation

CosmoMyzrailGorynych
Copy link
Contributor

Closes neutralinojs/neutralinojs#1301

  • Fixes implementation errors so that the pointer is always captured after traveling N pixels
  • Adds configuration options to tweak the behavior for bulletproof, native-looking drag behavior. Fully backwards-compatible.
  • Fixes one TODO: comment.
  • Also fixes explicit any for the changed methods.

New call signature: setDraggableRegion(domElementOrId: string | HTMLElement, options: DraggableRegionOptions = {})

DraggableRegionOptions is

export type DraggableRegionOptions = {
    /**
     * If set to `true`, the region will always capture the pointer,
     * ensuring dragging doesn't break on fast pointer movement.
     * Note that it prevents child elements from receiving any pointer events.
     * Defaults to `false`.
     */
    alwaysCapture?: boolean;
    /**
     * Minimum distance between cursor's starting and current position
     * after which dragging is started. This helps prevent accidental dragging
     * while interacting with child elements.
     * Defaults to `10`. (In pixels.)
     */
    dragMinDistance?: number;
}

Before:

draggableRegion
Yellow circle indicates mouse clicks. Note how the window misbehaves after releasing the mouse button outside the window.

After, with no options:

toolbarFixUnaggressive
Better capture overall but can still break it with flicking near the window's edge.

I can't accept mediocrity, so I added an option to capture the pointer immediately when pressing the drag area. This disables any pointer events on children elements and thus requires layout changes for custom titlebars, so it is opt-in only.

After, with alwaysCapture: true

toolbarFix
Best results: can't break it. Flicking near the edges still captures the pointer.

Copy link
Member

@shalithasuranga shalithasuranga left a comment

Choose a reason for hiding this comment

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

Thanks so much for sending this improvement with a detailed explanation with previews 🎉

Thanks so much for helping us to improve Neutralinojs. Would you like to display your name and GitHub profile link on: https://neutralino.js.org/docs/contributing/committers ?

We often update this list with active contributors 🎉 Thanks :)

@shalithasuranga shalithasuranga merged commit 6c1fef9 into neutralinojs:main Aug 10, 2024
2 checks passed
@CosmoMyzrailGorynych
Copy link
Contributor Author

Thanks so much for helping us to improve Neutralinojs. Would you like to display your name and GitHub profile link on: https://neutralino.js.org/docs/contributing/committers ?

Should I make a PR? x)

@shalithasuranga
Copy link
Member

Thanks so much for helping us to improve Neutralinojs. Would you like to display your name and GitHub profile link on: https://neutralino.js.org/docs/contributing/committers ?

Should I make a PR? x)

Sure 🎉 -- thanks 🎉

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.

window.setDraggableRegion loses point capture
2 participants