switch to GridWrap widget in Fyne instead of Fyne-x
This commit is contained in:
+28
-4
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
xwidget "fyne.io/x/fyne/widget"
|
||||
)
|
||||
|
||||
const batchFetchSize = 6
|
||||
@@ -75,7 +74,7 @@ type GridView struct {
|
||||
fetchCancel context.CancelFunc
|
||||
GridViewState
|
||||
|
||||
grid *xwidget.GridWrap
|
||||
grid *unfocusableGridWrap
|
||||
menu *widget.PopUpMenu
|
||||
menuGridViewItemId string
|
||||
}
|
||||
@@ -197,7 +196,7 @@ func (g *GridView) ScrollToOffset(offs float32) {
|
||||
}
|
||||
|
||||
func (g *GridView) createGridWrap() {
|
||||
g.grid = xwidget.NewGridWrap(
|
||||
g.grid = NewUnfocusableGridWrap(
|
||||
func() int {
|
||||
return g.lenItems()
|
||||
},
|
||||
@@ -221,7 +220,7 @@ func (g *GridView) createGridWrap() {
|
||||
return card
|
||||
},
|
||||
// update func
|
||||
func(itemID xwidget.GridWrapItemID, obj fyne.CanvasObject) {
|
||||
func(itemID widget.GridWrapItemID, obj fyne.CanvasObject) {
|
||||
ac := obj.(*GridViewItem)
|
||||
g.doUpdateItemCard(int(itemID), ac)
|
||||
},
|
||||
@@ -369,3 +368,28 @@ func (g *GridView) onPlay(itemID string, shuffle bool) {
|
||||
func (g *GridView) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(g.grid)
|
||||
}
|
||||
|
||||
type unfocusableGridWrap struct {
|
||||
widget.GridWrap
|
||||
}
|
||||
|
||||
func NewUnfocusableGridWrap(len func() int, create func() fyne.CanvasObject, update func(widget.GridWrapItemID, fyne.CanvasObject)) *unfocusableGridWrap {
|
||||
g := &unfocusableGridWrap{
|
||||
GridWrap: widget.GridWrap{
|
||||
Length: len,
|
||||
CreateItem: create,
|
||||
UpdateItem: update,
|
||||
},
|
||||
}
|
||||
g.ExtendBaseWidget(g)
|
||||
return g
|
||||
}
|
||||
|
||||
// a disabled widget is not considered focusable by the focus manager
|
||||
var _ fyne.Disableable = (*unfocusableGridWrap)(nil)
|
||||
|
||||
func (g *unfocusableGridWrap) Disabled() bool { return true }
|
||||
|
||||
func (g *unfocusableGridWrap) Disable() {}
|
||||
|
||||
func (g *unfocusableGridWrap) Enable() {}
|
||||
|
||||
@@ -216,3 +216,13 @@ func (g *GridViewItem) ItemID() string {
|
||||
func (g *GridViewItem) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(g.container)
|
||||
}
|
||||
|
||||
// steal hover events from underlying GridWrap to prevent unwanted
|
||||
// hover rectangle backgrounds
|
||||
var _ desktop.Hoverable = (*GridViewItem)(nil)
|
||||
|
||||
func (g *GridViewItem) MouseIn(e *desktop.MouseEvent) {}
|
||||
|
||||
func (g *GridViewItem) MouseOut() {}
|
||||
|
||||
func (g *GridViewItem) MouseMoved(e *desktop.MouseEvent) {}
|
||||
|
||||
Reference in New Issue
Block a user