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

Allow views to detect if they are being painted for drag and drop #458

Merged
merged 2 commits into from
May 22, 2024

Conversation

timboudreau
Copy link
Contributor

Rationale: The default painting behavior of components which are being dragged is not always ideal:

  • The only way (that I have found, anyway) for a View to receive drag events when the drag moves outside the view or window bounds is to call View.draggable().
  • That has the side-effect of altering the painting behavior to paint the component twice, with one copy under the mouse cursor.
  • There was (up until now) no way to detect whether a view was being painted because of a drag operation in progress (or the rebound on an unaccepted drag), or painting normally - or differentiate them if you expect to need normal repaints during the drag operation, but you do not want paint a second copy of your component at all (or want to paint something else) only for the drag-based invocations of View.paint()
  • Getting rid of the drag image entirely still involves some non-intuitive steps * Use this new call to detect drag paints and return from the paint method without painting at all * Set a drag style of Background : Color::TRANSPARENT on the View at initialization (otherwise you'll drag a background-colored rectangle around the screen instead)

Ideally it might be useful to have one or both of

  • A way for a View to signal don't paint a drag image of me at all - probably as something you can set on the style - but being able to paint an alterative rendering of the component is useful as well, OR
  • A way for a View to lock itself into the set of recipients of mouse motion events until the next mouse up, without any implications about OS-level drag and drop

but this both solves the problem and is useful. I'll try to contribute an example of combining this with the undecorated window patches I submitted earlier to demonstrate the sort of thing it's good for, along the lines of this.

Rationale: The default painting behavior of components which are being dragged is
not always ideal:

* The only way (that I have found, anyway) for a View to receive drag events *when
  the drag moves outside the view or window bounds* is to call `View.draggable()`.
* That has the side-effect of altering the painting behavior to paint the component
  twice, with one copy under the mouse cursor.
* There was (up until now) no way to detect whether a view was being painted because
  of a drag operation in progress (or the rebound on an unaccepted drag), or painting
  normally - or differentiate them if you expect to need normal repaints during the
  drag operation, but you do not want paint a second copy of your component *at all*
  (or want to paint something else) only for the drag-based invocations of `View.paint()`
* Getting rid of the drag image entirely still involves some non-intuitive steps
    * Use this new call to detect drag paints and return from the paint method without
      painting at all
    * Set a drag style of `Background : Color::TRANSPARENT` on the `View` at initialization
      (otherwise you'll drag a background-colored rectangle around the screen instead)

Ideally it might be useful to have one or both of

 * A way for a `View` to signal *don't paint a drag image of me at all* - probably as
   something you can set on the style - but being able to paint an alterative rendering
   of the component is useful as well, OR
 * A way for a `View` to *lock* itself into the set of recipients of mouse motion events
   until the next mouse up, without any implications about OS-level drag and drop

but this both solves the problem and is useful.  I'll try to contribute an example of
combining this with the undecorated window patches I submitted earlier to demonstrate
the sort of thing it's good for, along the lines of
[this](https://github.com/timboudreau/colorchooser).
@dzhou121 dzhou121 merged commit 06c5527 into lapce:main May 22, 2024
7 checks passed
@timboudreau timboudreau deleted the custom_drag_paint branch May 30, 2024 16:02
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.

2 participants