-
Notifications
You must be signed in to change notification settings - Fork 295
Open
Milestone
Description
Currently the story for making a widget draggable isn't great.
- The user can only specify a draggable rectangle, whereas it would probably make more sense to allow the user to specify a function which returns a
bool
for whether or not some point being pressed should begin a drag. - Once a widget specifies a draggable area, its position cannot be updated any other way than by dragging the widget. E.g. if the widget is initially positioned relateively to its parent widget and its parent widget moves, the draggable widget will remain in the same place.
These problems mostly derive from the current, super simple implementation of dragging which basically works as follows:
- Check if the widget specifies a draggable area.
- If so, check if it already has a position. If not, calculate it the normal way, otherwise
- Check if the widget has received any left mouse button drag events.
- Check if the events began within the specified drag area.
- Some the total drag delta onto the current widget position.
Instead, dragging should probably work something like this:
- Allow the widget to specify the
Id
of some widget that when pressed with the left mouse button begins a drag. In many cases this might just be theId
of the widget itself, in others it might be theId
of one of its child widgets (e.g. the title bar of the canvas widget). - Check for drag events on the specified widget. Store the total dragged delta as a field within the widget's state. Each time the widget is dragged, sum on the new delta.
- Calculate the new position of the widget using the regular
Ui::calc_xy
method summed with the total dragged delta.
This should allow widgets to be dragged while also allowing them to retain their position relative to some parent/sibling widgets. E.g. if a widget is dragged and then the canvas upon which it was initially placed is moved, it will still follow its parent's movement.
Metadata
Metadata
Assignees
Labels
No labels