2019-04-10 00:35:44 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
// DragDrop is a state machine to manage draggable UI components.
|
|
|
|
type DragDrop struct {
|
|
|
|
isDragging bool
|
2020-04-07 05:57:28 +00:00
|
|
|
|
|
|
|
// If the subject of the drag is a widget, it can store itself here.
|
|
|
|
widget Widget
|
2019-04-10 00:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewDragDrop initializes the DragDrop struct. Normally your Supervisor
|
|
|
|
// will manage the drag/drop object, but you can use your own if you don't
|
|
|
|
// use a Supervisor.
|
|
|
|
func NewDragDrop() *DragDrop {
|
|
|
|
return &DragDrop{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsDragging returns whether the drag state is active.
|
|
|
|
func (dd *DragDrop) IsDragging() bool {
|
|
|
|
return dd.isDragging
|
|
|
|
}
|
|
|
|
|
2020-04-07 05:57:28 +00:00
|
|
|
// SetWidget attaches the widget to the drag state, but does not start the
|
|
|
|
// drag; you call Start() after this if the subject is a widget.
|
|
|
|
func (dd *DragDrop) SetWidget(w Widget) {
|
|
|
|
dd.widget = w
|
|
|
|
}
|
|
|
|
|
|
|
|
// Widget returns the attached widget or nil.
|
|
|
|
func (dd *DragDrop) Widget() Widget {
|
|
|
|
return dd.widget
|
|
|
|
}
|
|
|
|
|
2019-04-10 00:35:44 +00:00
|
|
|
// Start the drag state.
|
|
|
|
func (dd *DragDrop) Start() {
|
|
|
|
dd.isDragging = true
|
|
|
|
}
|
|
|
|
|
2020-04-07 05:57:28 +00:00
|
|
|
// Stop dragging. This will also clear the stored widget, if any.
|
2019-04-10 00:35:44 +00:00
|
|
|
func (dd *DragDrop) Stop() {
|
|
|
|
dd.isDragging = false
|
2020-04-07 05:57:28 +00:00
|
|
|
dd.widget = nil
|
2019-04-10 00:35:44 +00:00
|
|
|
}
|