英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论