Skip to content

Commit

Permalink
Updates dweymouth#116: add tool tips to buttons and various UI elements
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Aug 3, 2024
1 parent 7fcbfdd commit 7c94a4c
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 44 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1
github.com/dweymouth/fyne-advanced-list v0.0.0-20240623145729-9c6b8f99bcfe
github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64
github.com/dweymouth/fyne-tooltip v0.1.1
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645
github.com/dweymouth/go-mpv v0.0.0-20240724002347-c5e5b36f1bbf
github.com/dweymouth/go-subsonic v0.0.0-20240726004217-2e8e348ad417
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ github.com/dweymouth/fyne-advanced-list v0.0.0-20240623145729-9c6b8f99bcfe h1:ow
github.com/dweymouth/fyne-advanced-list v0.0.0-20240623145729-9c6b8f99bcfe/go.mod h1:sbOhla4VcfFb4OjXiUFTLXMPTnhRUlVrDMhB8HtWR4o=
github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64 h1:RUIrnGY034rDMlcOui/daurwX5b+52KdUKhH9aXaDSg=
github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64/go.mod h1:3YrjFDHMlhCsSZ/OvmJCxWm9QHSgOVWZBxnraZz9Z7c=
github.com/dweymouth/fyne-tooltip v0.1.1 h1:NmRZLlxftWHUStx3lvx/oHOc2Yg0nNdNsYHdImAq33Y=
github.com/dweymouth/fyne-tooltip v0.1.1/go.mod h1:zEgy7p9tSVIuy2GufFbOCoK3Q04zhyDPOotlU4G3Ma4=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240728183020-7abcad1f4139 h1:JNOd+yJlurYrdAuOiibR6/EYl+/+idFkk+wwyXiNwIQ=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240728183020-7abcad1f4139/go.mod h1:9D4oT3NWeG+MLi/lP7ItZZyujHC/qqMJpoGTAYX5Uqc=
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645 h1:KzqSaQwG3HsTZQlEtkp0BeUy9vmYZ0rq0B15qIPSiBs=
Expand Down
8 changes: 8 additions & 0 deletions res/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"Authentication failed": "Authentication failed",
"Auto": "Auto",
"Autoselect device": "Autoselect device",
"Back": "Back",
"Bit rate": "Bit rate",
"BPM": "BPM",
"Broadcast": "Broadcast",
Expand Down Expand Up @@ -73,14 +74,17 @@
"Field Recording": "Field Recording",
"File path": "File path",
"File size": "File size",
"Filter albums": "Filter albums",
"Filter genres": "Filter genres",
"Foreward": "Foreward",
"Frequently Played": "Frequently Played",
"General": "General",
"Genre": "Genre",
"Genres": "Genres",
"Github page": "Github page",
"Go to release page": "Go to release page",
"Hide": "Hide",
"Home": "Home",
"Home Page": "Home Page",
"hr": "hr",
"hrs": "hrs",
Expand All @@ -95,9 +99,11 @@
"Login to Server": "Login to Server",
"Lyrics": "Lyrics",
"Lyrics not available": "Lyrics not available",
"Menu": "Menu",
"min": "min",
"minutes of track have been played": "minutes of track have been played",
"Mixtape": "Mixtape",
"Mute": "Mute",
"My Server": "My Server",
"Name": "Name",
"Name (A-Z)": "Name (A-Z)",
Expand Down Expand Up @@ -139,6 +145,7 @@
"Recently Added": "Recently Added",
"Recently Played": "Recently Played",
"Related": "Related",
"Reload": "Reload",
"Remix": "Remix",
"Remove from playlist": "Remove from playlist",
"ReplayGain mode": "ReplayGain mode",
Expand All @@ -163,6 +170,7 @@
"Show": "Show",
"Show info": "Show info",
"Show notification on track change": "Show notification on track change",
"Show play queue": "Show play queue",
"Show year in album grid cards": "Show year in album grid cards",
"Shuffle": "Shuffle",
"Shuffle albums": "Shuffle albums",
Expand Down
40 changes: 25 additions & 15 deletions ui/browsing/browsingpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package browsing
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/lang"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
Expand All @@ -11,6 +12,8 @@ import (
"github.com/dweymouth/supersonic/ui/controller"
"github.com/dweymouth/supersonic/ui/layouts"
myTheme "github.com/dweymouth/supersonic/ui/theme"

ttwidget "github.com/dweymouth/fyne-tooltip/widget"
)

type Page interface {
Expand Down Expand Up @@ -60,14 +63,14 @@ type BrowsingPane struct {

curPage Page

home *widget.Button
forward *widget.Button
back *widget.Button
reload *widget.Button
home *ttwidget.Button
forward *ttwidget.Button
back *ttwidget.Button
reload *ttwidget.Button
history []SavedPage
historyIdx int

settingsBtn *widget.Button
settingsBtn *ttwidget.Button
settingsMenu *fyne.Menu
navBtnsContainer *fyne.Container
pageContainer *fyne.Container
Expand All @@ -78,22 +81,28 @@ type BrowsingPane struct {
func NewBrowsingPane(app *backend.App, contr *controller.Controller, onGoHome func()) *BrowsingPane {
b := &BrowsingPane{app: app}
b.ExtendBaseWidget(b)
b.home = widget.NewButtonWithIcon("", theme.HomeIcon(), onGoHome)
b.back = widget.NewButtonWithIcon("", theme.NavigateBackIcon(), b.GoBack)
b.forward = widget.NewButtonWithIcon("", theme.NavigateNextIcon(), b.GoForward)
b.reload = widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), b.Reload)
b.home = ttwidget.NewButtonWithIcon("", theme.HomeIcon(), onGoHome)
b.home.SetToolTip(lang.L("Home"))
b.back = ttwidget.NewButtonWithIcon("", theme.NavigateBackIcon(), b.GoBack)
b.back.SetToolTip(lang.L("Back"))
b.forward = ttwidget.NewButtonWithIcon("", theme.NavigateNextIcon(), b.GoForward)
b.forward.SetToolTip(lang.L("Forward"))
b.reload = ttwidget.NewButtonWithIcon("", theme.ViewRefreshIcon(), b.Reload)
b.reload.SetToolTip("Reload")
b.app.PlaybackManager.OnSongChange(b.onSongChange)
b.app.PlaybackManager.OnPlayTimeUpdate(b.onPlayTimeUpdate)
b.app.PlaybackManager.OnQueueChange(b.onQueueChange)
bkgrnd := myTheme.NewThemedRectangle(myTheme.ColorNamePageBackground)
b.pageContainer = container.NewStack(bkgrnd, layout.NewSpacer())
b.settingsBtn = widget.NewButtonWithIcon("", theme.SettingsIcon(), func() {
b.settingsBtn = ttwidget.NewButtonWithIcon("", theme.SettingsIcon(), func() {
p := widget.NewPopUpMenu(b.settingsMenu,
fyne.CurrentApp().Driver().CanvasForObject(b.settingsBtn))
p.ShowAtPosition(fyne.NewPos(b.Size().Width-p.MinSize().Width+4,
b.navBtnsContainer.MinSize().Height+theme.Padding()))
})
quickSearchBtn := widget.NewButtonWithIcon("", theme.SearchIcon(), contr.ShowQuickSearch)
b.settingsBtn.SetToolTip("Menu")
quickSearchBtn := ttwidget.NewButtonWithIcon("", theme.SearchIcon(), contr.ShowQuickSearch)
quickSearchBtn.SetToolTip("Search Everywhere")
b.settingsMenu = fyne.NewMenu("")
b.navBtnsContainer = container.NewHBox()
b.navBtnsPageMap = map[controller.PageName]fyne.Resource{}
Expand Down Expand Up @@ -146,24 +155,25 @@ func (b *BrowsingPane) AddSettingsMenuSeparator() {
fyne.NewMenuItemSeparator())
}

func (b *BrowsingPane) AddNavigationButton(icon fyne.Resource, pageName controller.PageName, action func()) *widget.Button {
func (b *BrowsingPane) AddNavigationButton(icon fyne.Resource, pageName controller.PageName, action func()) *ttwidget.Button {
// make a copy of the icon, because it can change the color
browsingPaneIcon := theme.NewThemedResource(icon)
btn := widget.NewButtonWithIcon("", browsingPaneIcon, action)
btn := ttwidget.NewButtonWithIcon("", browsingPaneIcon, action)
btn.SetToolTip(lang.L(pageName.String()))
b.navBtnsContainer.Add(btn)
b.navBtnsPageMap[pageName] = browsingPaneIcon
return btn
}

func (b *BrowsingPane) DisableNavigationButtons() {
for _, obj := range b.navBtnsContainer.Objects {
obj.(*widget.Button).Disable()
obj.(fyne.Disableable).Disable()
}
}

func (b *BrowsingPane) EnableNavigationButtons() {
for _, obj := range b.navBtnsContainer.Objects {
obj.(*widget.Button).Enable()
obj.(fyne.Disableable).Enable()
}
}

Expand Down
3 changes: 3 additions & 0 deletions ui/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"sync"
"time"

fynetooltip "github.com/dweymouth/fyne-tooltip"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/backend/player"
Expand Down Expand Up @@ -528,8 +529,10 @@ func (c *Controller) ShowSettingsDialog(themeUpdateCallbk func(), themeFiles map
}
dlg.OnPageNeedsRefresh = c.RefreshPageFunc
pop := widget.NewModalPopUp(dlg, c.MainWindow.Canvas())
fynetooltip.AddPopUpToolTipLayer(pop)
dlg.OnDismiss = func() {
pop.Hide()
fynetooltip.DestroyPopUpToolTipLayer(pop)
c.doModalClosed()
c.App.SaveConfigFile()
}
Expand Down
31 changes: 31 additions & 0 deletions ui/controller/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,37 @@ const (
Radios
)

func (p PageName) String() string {
switch p {
case Album:
return "Album"
case Albums:
return "Albums"
case Artist:
return "Artist"
case Artists:
return "Artists"
case Genre:
return "Genre"
case Genres:
return "Genres"
case Favorites:
return "Favorites"
case NowPlaying:
return "Now Playing"
case Playlist:
return "Playlist"
case Playlists:
return "Playlists"
case Tracks:
return "All Tracks"
case Radios:
return "Internet Radio Stations"
default:
return ""
}
}

type Route struct {
Page PageName
Arg string
Expand Down
53 changes: 34 additions & 19 deletions ui/dialogs/graphicequalizer.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package dialogs

import (
"fmt"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
ttwidget "github.com/dweymouth/fyne-tooltip/widget"
"github.com/dweymouth/supersonic/ui/layouts"
myTheme "github.com/dweymouth/supersonic/ui/theme"
"github.com/dweymouth/supersonic/ui/util"
Expand All @@ -17,7 +20,8 @@ type GraphicEqualizer struct {
OnChanged func(band int, gain float64)
OnPreampChanged func(gain float64)

container *fyne.Container
bandSliders []*eqSlider
container *fyne.Container
}

func NewGraphicEqualizer(preamp float64, bandFreqs []string, bandGains []float64) *GraphicEqualizer {
Expand All @@ -36,32 +40,37 @@ func (g *GraphicEqualizer) buildSliders(preamp float64, bands []string, bandGain
layout.NewSpacer(),
newCaptionTextSizeLabel("-12", fyne.TextAlignTrailing),
)
bandSliders := container.New(layouts.NewGridLayoutWithColumnsAndPadding(len(bands)+2, -16))
g.bandSliders = make([]*eqSlider, len(bands))
bandSlidersCtr := container.New(layouts.NewGridLayoutWithColumnsAndPadding(len(bands)+2, -16))
pre := newCaptionTextSizeLabel("Pre", fyne.TextAlignCenter)
preampSlider := newEQSlider()
preampSlider.SetValue(preamp)
preampSlider.OnChanged = func(f float64) {
if g.OnPreampChanged != nil {
g.OnPreampChanged(f)
}
preampSlider.UpdateToolTip()
}
bandSliders.Add(container.NewBorder(nil, pre, nil, nil, preampSlider))
bandSliders.Add(container.NewBorder(nil, widget.NewLabel(""), nil, nil, rng))
preampSlider.UpdateToolTip()
bandSlidersCtr.Add(container.NewBorder(nil, pre, nil, nil, preampSlider))
bandSlidersCtr.Add(container.NewBorder(nil, widget.NewLabel(""), nil, nil, rng))
for i, band := range bands {
s := newEQSlider()
if i < len(bandGains) {
s.SetValue(bandGains[i])
s.UpdateToolTip()
}
s.OnChanged = func(i int) func(float64) {
return func(f float64) {
if g.OnChanged != nil {
g.OnChanged(i, f)
}
_i := i
s.OnChanged = func(f float64) {
if g.OnChanged != nil {
g.OnChanged(_i, f)
}
}(i)
g.bandSliders[_i].UpdateToolTip()
}
l := newCaptionTextSizeLabel(band, fyne.TextAlignCenter)
c := container.NewBorder(nil, l, nil, nil, s)
bandSliders.Add(c)
bandSlidersCtr.Add(c)
g.bandSliders[i] = s
}
g.container = container.NewStack(
container.NewBorder(nil, widget.NewLabel(""), nil, nil,
Expand All @@ -73,7 +82,7 @@ func (g *GraphicEqualizer) buildSliders(preamp float64, bands []string, bandGain
),
),
),
bandSliders,
bandSlidersCtr,
)
}

Expand All @@ -90,23 +99,29 @@ func (g *GraphicEqualizer) CreateRenderer() fyne.WidgetRenderer {
}

type eqSlider struct {
widget.Slider
tappedAt int64
ttwidget.Slider
}

func newEQSlider() *eqSlider {
s := &eqSlider{
Slider: widget.Slider{
Orientation: widget.Vertical,
Min: -12,
Max: 12,
Step: 0.1,
Slider: ttwidget.Slider{
Slider: widget.Slider{
Orientation: widget.Vertical,
Min: -12,
Max: 12,
Step: 0.1,
},
},
}
s.UpdateToolTip()
s.ExtendBaseWidget(s)
return s
}

func (s *eqSlider) UpdateToolTip() {
s.SetToolTip(fmt.Sprintf("%0.1f dB", s.Value))
}

// We implement our own double tapping so that the Tapped behavior
// can be triggered instantly.
func (s *eqSlider) DoubleTapped(e *fyne.PointEvent) {
Expand Down
13 changes: 9 additions & 4 deletions ui/mainwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

fynetooltip "github.com/dweymouth/fyne-tooltip"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/res"
Expand Down Expand Up @@ -40,7 +41,7 @@ type MainWindow struct {
container *fyne.Container

// needs to bes shown/hidden when switching between servers based on whether they support radio
radioBtn *widget.Button
radioBtn fyne.CanvasObject
}

func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string, app *backend.App) MainWindow {
Expand All @@ -49,6 +50,7 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
Window: fyneApp.NewWindow(displayAppName),
theme: theme.NewMyTheme(&app.Config.Theme, app.ThemesDir()),
}
fynetooltip.SetToolTipTextSizeName(theme.SizeNameSubText)

m.theme.NormalFont = app.Config.Application.FontNormalTTF
m.theme.BoldFont = app.Config.Application.FontBoldTTF
Expand Down Expand Up @@ -80,7 +82,7 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,

m.BottomPanel = NewBottomPanel(app.PlaybackManager, app.ImageManager, m.Controller)
m.container = container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane)
m.Window.SetContent(m.container)
m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.container, m.Window.Canvas()))
m.setInitialSize()
app.PlaybackManager.OnSongChange(func(item mediaprovider.MediaItem, _ *mediaprovider.Track) {
if item == nil {
Expand Down Expand Up @@ -191,8 +193,11 @@ func (m *MainWindow) RunOnServerConnectedTasks(app *backend.App, displayAppName
}

_, supportsRadio := m.App.ServerManager.Server.(mediaprovider.RadioProvider)
m.radioBtn.Hidden = !supportsRadio
m.radioBtn.Refresh()
if supportsRadio {
m.radioBtn.Show()
} else {
m.radioBtn.Hide()
}

m.App.SaveConfigFile()

Expand Down
Loading

0 comments on commit 7c94a4c

Please sign in to comment.