User interface toolkit for Go with support for SDL2 and HTML Canvas render targets.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 lines
1.0 KiB

  1. package ui
  2. // DragDrop is a state machine to manage draggable UI components.
  3. type DragDrop struct {
  4. isDragging bool
  5. // If the subject of the drag is a widget, it can store itself here.
  6. widget Widget
  7. }
  8. // NewDragDrop initializes the DragDrop struct. Normally your Supervisor
  9. // will manage the drag/drop object, but you can use your own if you don't
  10. // use a Supervisor.
  11. func NewDragDrop() *DragDrop {
  12. return &DragDrop{}
  13. }
  14. // IsDragging returns whether the drag state is active.
  15. func (dd *DragDrop) IsDragging() bool {
  16. return dd.isDragging
  17. }
  18. // SetWidget attaches the widget to the drag state, but does not start the
  19. // drag; you call Start() after this if the subject is a widget.
  20. func (dd *DragDrop) SetWidget(w Widget) {
  21. dd.widget = w
  22. }
  23. // Widget returns the attached widget or nil.
  24. func (dd *DragDrop) Widget() Widget {
  25. return dd.widget
  26. }
  27. // Start the drag state.
  28. func (dd *DragDrop) Start() {
  29. dd.isDragging = true
  30. }
  31. // Stop dragging. This will also clear the stored widget, if any.
  32. func (dd *DragDrop) Stop() {
  33. dd.isDragging = false
  34. dd.widget = nil
  35. }