ensure clicking anywhere outside tracklists can unselect all

This commit is contained in:
Drew Weymouth
2024-12-15 15:52:21 -08:00
parent 46153f5fe3
commit 1d342bf413
9 changed files with 113 additions and 48 deletions
+28 -3
View File
@@ -38,7 +38,7 @@ type MainWindow struct {
theme *theme.MyTheme
haveSystemTray bool
alreadyConnected bool // tracks if we have already connected to a server before
container *fyne.Container
content *mainWindowContent
// needs to bes shown/hidden when switching between servers based on whether they support radio
radioBtn fyne.CanvasObject
@@ -68,6 +68,7 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
m.Controller.CurPageFunc = m.BrowsingPane.CurrentPage
m.Controller.RefreshPageFunc = m.BrowsingPane.RefreshPage
m.Controller.SelectAllPageFunc = m.BrowsingPane.SelectAll
m.Controller.UnselectAllPageFunc = m.BrowsingPane.UnselectAll
if runtime.GOOS == "darwin" {
// Fyne will extract out an "About" menu item and
@@ -136,8 +137,9 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
m.BrowsingPane.DisableNavigationButtons()
m.addShortcuts()
m.container = container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane)
m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.container, m.Window.Canvas()))
m.content = newMainWindowContent(container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane),
m.Controller.UnselectAll)
m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.content, m.Window.Canvas()))
m.setInitialSize()
m.Window.SetCloseIntercept(func() {
m.SaveWindowSize()
@@ -433,3 +435,26 @@ func (m *MainWindow) SaveWindowSize() {
&m.App.Config.Application.WindowWidth,
&m.App.Config.Application.WindowHeight)
}
// widget just so we can catch a tap event that doesn't land anywhere else
// and call BrowsingPane.UnselectAll()
type mainWindowContent struct {
widget.BaseWidget
content fyne.CanvasObject
onTapped func()
}
func newMainWindowContent(content fyne.CanvasObject, onTapped func()) *mainWindowContent {
w := &mainWindowContent{content: content, onTapped: onTapped}
w.ExtendBaseWidget(w)
return w
}
func (m *mainWindowContent) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(m.content)
}
func (m *mainWindowContent) Tapped(*fyne.PointEvent) {
m.onTapped()
}