Noah Petherbridge
7d9ba79cd2
* Adds Window Manager support to the Supervisor, so that Window widgets can be dragged by their title bar, clicked to focus, etc. * Create a ui.Window as normal, but instead of Packing or Placing it into a parent container as before, you call .Supervise() and give it your Supervisor. The window registers itself to be managed and drawn by the Supervisor itself. * Supervisor manages the focused window order using a doubly linked list. When a window takes focus it moves to the top of the list. Widgets in the active window take event priority. * Extended DragDrop API to support holding a widget pointer in the drag operation. * Changed widget event Handle functions to return an error: so that they could return ErrStopPropagation to prevent events going to more widgets once handled (for important events). Some bugs remain around overlapping windows and event propagation.
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package ui
|
|
|
|
// DragDrop is a state machine to manage draggable UI components.
|
|
type DragDrop struct {
|
|
isDragging bool
|
|
|
|
// If the subject of the drag is a widget, it can store itself here.
|
|
widget Widget
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// Start the drag state.
|
|
func (dd *DragDrop) Start() {
|
|
dd.isDragging = true
|
|
}
|
|
|
|
// Stop dragging. This will also clear the stored widget, if any.
|
|
func (dd *DragDrop) Stop() {
|
|
dd.isDragging = false
|
|
dd.widget = nil
|
|
}
|