在fyne中检测拖拽

huangapple go评论93阅读模式
英文:

Detecting drag in fyne

问题

如何在小部件中检测拖动事件?我尝试了以下代码:

    type drawRect struct {
        widget.Card
    }

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

但是当我拖动它时,它并没有被调用。

英文:

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.

答案1

得分: 0

对于拖动一个项目,您需要实现完整的Draggable接口(您错过了DragEnd)https://developer.fyne.io/api/v2.0/draggable.html。

然而,您描述的可能是一个放置事件(属于操作系统拖放生命周期的一部分),目前还不支持。可拖动行为是为用户在您的UI中拖动对象的功能而设计的。

英文:

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.

huangapple
  • 本文由 发表于 2021年12月20日 12:32:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/70417406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定