Extending widgets

Extending widgets

I'm trying to combine the Selectable and Draggable widgets to allow elements to be selected and then all of the selected elements to be dragged somewhere.

I've created a widget which applies Selectable to a container, and then applies Draggable to the elements of that container.  The result is:

  • An individual element can be dragged.
  • Elements can be selected by dragging a lasso around them.

So to extend this, I need to add some functionality:

  1. Elements should still be selected on mousedown.
  2. Dragging should drag the whole selection, not just the element the mouse is over.

So for (1) I'm catching the mousedown event and would like to programmatically select the element being clicked, and expected to be able to just call a "select this element" method in the selectable widget.  However, there is no such method - all the selection logic is wrapped up in a closure within the selectable's _mouseStart handler, so doesn't lend itself to code reuse at all.  However, I figured that I could work around this by just calling _mouseStart() and _mouseStop() directly - I can't figure out any way to do this; or by passing the mousedown and mouseup events directly to the widget - again, no go because the mouseHandled variable gets set, so calling multiple mouse events from within a mouse event isn't going to work.

Moving on to (2), again I figured that the best way would be to trigger a mousedown event on all of the selected draggables; but again, the mouseHandled variable prevents this.

So I'm after a bit of advice as to how best to go about this - all the important functionality just seems to be implemented directly in the various event handlers, rather than being implemented in separate methods.  Since this programming style doesn't lend itself to code reuse, I'm starting to suspect that I'm going to have to reimplement large parts of the existing functionality, which is something I was hoping to avoid.  Any suggestions would be welcome.

Thanks.













    • Topic Participants

    • steve