Skip to content

Proposal for fixing drag logic #1088

@mitchmindtree

Description

@mitchmindtree

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:

  1. Check if the widget specifies a draggable area.
  2. If so, check if it already has a position. If not, calculate it the normal way, otherwise
  3. Check if the widget has received any left mouse button drag events.
  4. Check if the events began within the specified drag area.
  5. Some the total drag delta onto the current widget position.

Instead, dragging should probably work something like this:

  1. 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 the Id of the widget itself, in others it might be the Id of one of its child widgets (e.g. the title bar of the canvas widget).
  2. 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.
  3. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions