Skip to content

Improve Sense vs drag-and-drop #3841

@emilk

Description

@emilk

When dragging a widget (e.g. a slider), and letting the cursor move outside the slider, egui should not highlight that other widget:

hover-while-dragging

egui implements this by never setting response.hovered for a widget if another widget is being dragged.

There is a weird exception to this though: if the other widget is not interactive (doesn't sense any clicks or drags), then it will still have response.hovered(). This usually doesn't matter, because a widget that that is not interactive has no hover-effect anyway.

This has implications for drag-and-drop: if the drop-target area has Sense::hover() then it will sense hovers while the user is dragging something else, so the user can do if drag_target_response.hovered() { … to highlight the drop-area. But if the drop-area itself is sensitive to clicks and drags, .hovered() will always be false while something is being dragged. This means it is really tricky to implement drag-and-drop reordering of a list, because usually you'd want to implement that by having each list item sense drags and be a drop-target, to sense how to reorder the items.

A work-around it to use ui.rect_contains_pointer instead of response.hovered(), but this feels hacky.

So: we should figure out:

  • Should response.hovered() be true when something else is being dragged or not?
  • Should we have a special drop-target Sense?

Metadata

Metadata

Assignees

Labels

eguirerunDesired for Rerun.io

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions