Search code examples
gofyne

Detecting drag in fyne


How can I detect a drag event in a widget? I've tried this:

    type drawRect struct {
        widget.Card
    }

    func (e *drawRect) Dragged(d *fyne.DragEvent) {
        fmt.Println("A")
    }

but it is not called when I drag over it.


Solution

  • For dragging an item you need to implement the whole Draggable interface (you missed DragEnd) https://developer.fyne.io/api/v2.0/draggable.html.

    However what you describe may be a drop event (part of the OS drag and drop lifecycle) which is not yet supported. The draggable behaviour is for the user feature of dragging an object inside your UI.