use disabled list to avoid builtin focus handling

This commit is contained in:
Drew Weymouth
2023-11-02 19:24:52 -07:00
parent af95d150e8
commit b24321ee40
6 changed files with 51 additions and 18 deletions
+2 -2
View File
@@ -144,7 +144,7 @@ type GenreList struct {
columnsLayout *layouts.ColumnsLayout
hdr *widgets.ListHeader
list *widget.List
list *widgets.DisabledList
container *fyne.Container
}
@@ -184,7 +184,7 @@ func NewGenreList(sorting widgets.ListHeaderSort) *GenreList {
{"Name", fyne.TextAlignLeading, false}, {"Album Count", fyne.TextAlignTrailing, false}, {"Track Count", fyne.TextAlignTrailing, false}}, a.columnsLayout)
a.hdr.SetSorting(sorting)
a.hdr.OnColumnSortChanged = a.onSorted
a.list = widget.NewList(
a.list = widgets.NewDisabledList(
func() int { return len(a.genres) },
func() fyne.CanvasObject {
r := NewGenreListRow(a.columnsLayout)
+2 -2
View File
@@ -289,7 +289,7 @@ type PlaylistList struct {
columnsLayout *layouts.ColumnsLayout
header *widgets.ListHeader
list *widget.List
list *widgets.DisabledList
container *fyne.Container
}
@@ -299,7 +299,7 @@ func NewPlaylistList(initialSort widgets.ListHeaderSort) *PlaylistList {
columnsLayout: layouts.NewColumnsLayout([]float32{-1, -1, 200, 125}),
}
a.buildHeader()
a.list = widget.NewList(
a.list = widgets.NewDisabledList(
func() int {
return len(a.playlists)
},
+2 -2
View File
@@ -217,7 +217,7 @@ type GenreFilterSubsection struct {
noneBtn *widget.Button
listModelMutex sync.RWMutex
genreListViewModel []string
genreListView *widget.List
genreListView *DisabledList
container *fyne.Container
}
@@ -233,7 +233,7 @@ func NewGenreFilterSubsection(onChanged func([]string), initialSelectedGenres []
g.selectedGenres[genre] = nil
}
g.genreListView = widget.NewList(
g.genreListView = NewDisabledList(
func() int {
g.listModelMutex.RLock()
defer g.listModelMutex.RUnlock()
+33
View File
@@ -0,0 +1,33 @@
package widgets
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
)
// DisabledList extends List to be disabled so that the
// focus manager considers it unfocusable.
// This is needed since we handle row focusability ourselves.
type DisabledList struct {
widget.List
}
func NewDisabledList(len func() int, create func() fyne.CanvasObject, update func(widget.GridWrapItemID, fyne.CanvasObject)) *DisabledList {
g := &DisabledList{
List: widget.List{
Length: len,
CreateItem: create,
UpdateItem: update,
},
}
g.ExtendBaseWidget(g)
return g
}
var _ fyne.Disableable = (*DisabledList)(nil)
func (g *DisabledList) Disabled() bool { return true }
func (g *DisabledList) Disable() {}
func (g *DisabledList) Enable() {}
+10 -10
View File
@@ -74,7 +74,7 @@ type GridView struct {
fetchCancel context.CancelFunc
GridViewState
grid *unfocusableGridWrap
grid *disabledGridWrap
menu *widget.PopUpMenu
menuGridViewItemId string
}
@@ -196,7 +196,7 @@ func (g *GridView) ScrollToOffset(offs float32) {
}
func (g *GridView) createGridWrap() {
g.grid = NewUnfocusableGridWrap(
g.grid = NewDisabledGridWrap(
func() int {
return g.lenItems()
},
@@ -369,12 +369,13 @@ func (g *GridView) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(g.grid)
}
type unfocusableGridWrap struct {
// a disabled widget is not considered focusable by the focus manager
type disabledGridWrap struct {
widget.GridWrap
}
func NewUnfocusableGridWrap(len func() int, create func() fyne.CanvasObject, update func(widget.GridWrapItemID, fyne.CanvasObject)) *unfocusableGridWrap {
g := &unfocusableGridWrap{
func NewDisabledGridWrap(len func() int, create func() fyne.CanvasObject, update func(widget.GridWrapItemID, fyne.CanvasObject)) *disabledGridWrap {
g := &disabledGridWrap{
GridWrap: widget.GridWrap{
Length: len,
CreateItem: create,
@@ -385,11 +386,10 @@ func NewUnfocusableGridWrap(len func() int, create func() fyne.CanvasObject, upd
return g
}
// a disabled widget is not considered focusable by the focus manager
var _ fyne.Disableable = (*unfocusableGridWrap)(nil)
var _ fyne.Disableable = (*disabledGridWrap)(nil)
func (g *unfocusableGridWrap) Disabled() bool { return true }
func (g *disabledGridWrap) Disabled() bool { return true }
func (g *unfocusableGridWrap) Disable() {}
func (g *disabledGridWrap) Disable() {}
func (g *unfocusableGridWrap) Enable() {}
func (g *disabledGridWrap) Enable() {}
+2 -2
View File
@@ -99,7 +99,7 @@ type Tracklist struct {
nowPlayingID string
colLayout *layouts.ColumnsLayout
hdr *ListHeader
list *widget.List
list *DisabledList
ctxMenu *fyne.Menu
container *fyne.Container
}
@@ -132,7 +132,7 @@ func NewTracklist(tracks []*mediaprovider.Track) *Tracklist {
playIcon.ColorName = theme.ColorNamePrimary
playingIcon := container.NewCenter(container.NewHBox(util.NewHSpace(2), widget.NewIcon(playIcon)))
t.list = widget.NewList(
t.list = NewDisabledList(
t.lenTracks,
func() fyne.CanvasObject {
tr := NewTrackRow(t, playingIcon)