Skip to content

Commit

Permalink
Add tool tips to tracklist names, etc + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Aug 6, 2024
1 parent 7c94a4c commit 66b8d4b
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 84 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +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/fyne-tooltip v0.2.0
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 Expand Up @@ -54,4 +54,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace fyne.io/fyne/v2 v2.5.0 => github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240728183020-7abcad1f4139
replace fyne.io/fyne/v2 v2.5.0 => github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240805144743-24df77c3cc7e
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ 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/fyne-tooltip v0.2.0 h1:6Zy3gryctuPoQfYf8Xp3tjenioebMt11NBGW/QXIvxE=
github.com/dweymouth/fyne-tooltip v0.2.0/go.mod h1:zEgy7p9tSVIuy2GufFbOCoK3Q04zhyDPOotlU4G3Ma4=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240805144743-24df77c3cc7e h1:FSTLNY9xV0+4/x9jKPXqUpwPZfhkAMz5ZnzLBkRirMw=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240805144743-24df77c3cc7e/go.mod h1:9D4oT3NWeG+MLi/lP7ItZZyujHC/qqMJpoGTAYX5Uqc=
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645 h1:KzqSaQwG3HsTZQlEtkp0BeUy9vmYZ0rq0B15qIPSiBs=
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645/go.mod h1:fcUagHBaQnt06GmBAllNE0J4O/7064zXRWdqnTTtVjI=
github.com/dweymouth/go-mpv v0.0.0-20240724002347-c5e5b36f1bbf h1:QVjXWx7XGkSPOCEu5EL9QVY3fkdDSnG5KEkok5o1svM=
Expand Down
67 changes: 39 additions & 28 deletions ui/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ type Controller struct {
RefreshPageFunc func()

popUpQueueMutex sync.Mutex
popUpQueue *widgets.PlayQueueList
popUpQueue *widget.PopUp
popUpQueueList *widgets.PlayQueueList
popUpQueueLastUsed int64
escapablePopUp *widget.PopUp
haveModal bool
Expand All @@ -65,18 +66,22 @@ func New(app *backend.App, appVersion string, mainWindow fyne.Window) *Controlle
}
c.initVisualizations()
c.App.PlaybackManager.OnQueueChange(func() {
c.popUpQueueMutex.Lock()
defer c.popUpQueueMutex.Unlock()
if c.popUpQueue != nil {
c.popUpQueue.SetItems(c.App.PlaybackManager.GetPlayQueue())
c.popUpQueueList.SetItems(c.App.PlaybackManager.GetPlayQueue())
}
})
c.App.PlaybackManager.OnSongChange(func(track mediaprovider.MediaItem, _ *mediaprovider.Track) {
c.popUpQueueMutex.Lock()
defer c.popUpQueueMutex.Unlock()
if c.popUpQueue == nil {
return
}
if track == nil {
c.popUpQueue.SetNowPlaying("")
c.popUpQueueList.SetNowPlaying("")
} else {
c.popUpQueue.SetNowPlaying(track.Metadata().ID)
c.popUpQueueList.SetNowPlaying(track.Metadata().ID)
}
})
return c
Expand Down Expand Up @@ -116,10 +121,28 @@ func (m *Controller) HaveModal() bool {
func (m *Controller) ShowPopUpPlayQueue() {
m.popUpQueueMutex.Lock()
if m.popUpQueue == nil {
m.popUpQueue = widgets.NewPlayQueueList(m.App.ImageManager, false)
m.popUpQueue.Reorderable = true
m.popUpQueue.SetItems(m.App.PlaybackManager.GetPlayQueue())
m.ConnectPlayQueuelistActions(m.popUpQueue)
m.popUpQueueList = widgets.NewPlayQueueList(m.App.ImageManager, false)
m.popUpQueueList.Reorderable = true
m.popUpQueueList.SetItems(m.App.PlaybackManager.GetPlayQueue())
m.ConnectPlayQueuelistActions(m.popUpQueueList)

title := widget.NewRichTextWithText(lang.L("Play Queue"))
title.Segments[0].(*widget.TextSegment).Style.Alignment = fyne.TextAlignCenter
title.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = true
ctr := container.NewBorder(title, nil, nil, nil,
container.NewPadded(m.popUpQueueList),
)
m.popUpQueue = widget.NewPopUp(ctr, m.MainWindow.Canvas())
fynetooltip.AddPopUpToolTipLayer(m.popUpQueue)

container.NewThemeOverride(m.popUpQueue, myTheme.WithColorTransformOverride(
theme.ColorNameOverlayBackground,
func(c color.Color) color.Color {
c_ := c.(color.NRGBA)
c_.A = 245
return c_
},
))

// free popUpQueue if it hasn't been used in awhile
go func() {
Expand All @@ -128,7 +151,9 @@ func (m *Controller) ShowPopUpPlayQueue() {
m.popUpQueueMutex.Lock()
now := time.Now().UnixMilli()
if m.popUpQueueLastUsed < now-120_000 /*2 min*/ {
fynetooltip.DestroyPopUpToolTipLayer(m.popUpQueue)
m.popUpQueue = nil
m.popUpQueueList = nil
m.popUpQueueLastUsed = 0
m.popUpQueueMutex.Unlock()
t.Stop()
Expand All @@ -139,31 +164,17 @@ func (m *Controller) ShowPopUpPlayQueue() {
}()
}
m.popUpQueueLastUsed = time.Now().UnixMilli()
popUpQueue := m.popUpQueue
popUpQueueList := m.popUpQueueList
pop := m.popUpQueue
m.popUpQueueMutex.Unlock()

npID := ""
if np := m.App.PlaybackManager.NowPlaying(); np != nil {
npID = np.Metadata().ID
}
popUpQueue.SetNowPlaying(npID)
popUpQueue.UnselectAll()

title := widget.NewRichTextWithText(lang.L("Play Queue"))
title.Segments[0].(*widget.TextSegment).Style.Alignment = fyne.TextAlignCenter
title.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = true
ctr := container.NewBorder(title, nil, nil, nil,
container.NewPadded(m.popUpQueue),
)
pop := widget.NewPopUp(ctr, m.MainWindow.Canvas())
container.NewThemeOverride(pop, myTheme.WithColorTransformOverride(
theme.ColorNameOverlayBackground,
func(c color.Color) color.Color {
c_ := c.(color.NRGBA)
c_.A = 245
return c_
},
))
popUpQueueList.SetNowPlaying(npID)
popUpQueueList.UnselectAll()

m.ClosePopUpOnEscape(pop)
minSize := fyne.NewSize(300, 400)
maxSize := fyne.NewSize(800, 1000)
Expand All @@ -172,7 +183,7 @@ func (m *Controller) ShowPopUpPlayQueue() {
fyne.NewSize(canvasSize.Width*0.4, canvasSize.Height*0.5),
))
pop.Resize(size)
popUpQueue.ScrollToNowPlaying() // must come after resize
popUpQueueList.ScrollToNowPlaying() // must come after resize
pop.ShowAtPosition(fyne.NewPos(
canvasSize.Width-size.Width-10,
canvasSize.Height-size.Height-100,
Expand Down
22 changes: 22 additions & 0 deletions ui/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/lang"
"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/backend/mediaprovider"
"github.com/dweymouth/supersonic/res"
"github.com/dweymouth/supersonic/sharedutil"
Expand Down Expand Up @@ -252,6 +254,18 @@ func NewTruncatingLabel() *widget.Label {
return rt
}

func NewTruncatingTooltipRichText() *ttwidget.RichText {
rt := ttwidget.NewRichTextWithText("")
rt.Truncation = fyne.TextTruncateEllipsis
return rt
}

func NewTruncatingTooltipLabel() *ttwidget.Label {
rt := ttwidget.NewLabel("")
rt.Truncation = fyne.TextTruncateEllipsis
return rt
}

func NewTrailingAlignLabel() *widget.Label {
rt := widget.NewLabel("")
rt.Alignment = fyne.TextAlignTrailing
Expand All @@ -269,6 +283,14 @@ func LocalizeSlice(s []string) []string {
return sharedutil.MapSlice(s, func(s string) string { return lang.L(s) })
}

type ToolTipRichText struct {
ttwidget.RichText

OnMouseIn func(e *desktop.MouseEvent)
OnMouseOut func()
OnTapped func(e *fyne.PointEvent)
}

type HSpace struct {
widget.BaseWidget

Expand Down
68 changes: 50 additions & 18 deletions ui/widgets/focuslist.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package widgets

import (
"image/color"
"sync"
"time"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"

Expand Down Expand Up @@ -72,6 +74,7 @@ func (g *FocusList) FocusNeighbor(curItem widget.ListItemID, up bool) {
var _ fyne.Tappable = (*FocusListRowBase)(nil)
var _ fyne.Widget = (*FocusListRowBase)(nil)
var _ fyne.Focusable = (*FocusListRowBase)(nil)
var _ desktop.Hoverable = (*FocusListRowBase)(nil)

// Base type used for all list rows in widgets such as Tracklist, etc.
type FocusListRowBase struct {
Expand All @@ -81,14 +84,16 @@ type FocusListRowBase struct {
Content fyne.CanvasObject
Selected bool
Focused bool
hovered bool

OnTapped func()
OnDoubleTapped func()
OnFocusNeighbor func(up bool) //TODO: func(up, selecting bool)

tappedAt int64 // unixMillis
focusedRect *canvas.Rectangle
selectionRect *canvas.Rectangle
focusedRect canvas.Rectangle
selectionRect canvas.Rectangle
hoverRect canvas.Rectangle
}

func (l *FocusListRowBase) SetOnTapped(f func()) {
Expand Down Expand Up @@ -139,12 +144,14 @@ func (l *FocusListRowBase) Tapped(*fyne.PointEvent) {

func (l *FocusListRowBase) FocusGained() {
l.Focused = true
l.Refresh()
l.focusedRect.FillColor = theme.HoverColor()
l.focusedRect.Refresh()
}

func (l *FocusListRowBase) FocusLost() {
l.Focused = false
l.Refresh()
l.focusedRect.FillColor = color.Transparent
l.focusedRect.Refresh()
}

func (l *FocusListRowBase) TypedKey(e *fyne.KeyEvent) {
Expand Down Expand Up @@ -180,26 +187,51 @@ func (l *FocusListRowBase) TypedKey(e *fyne.KeyEvent) {
func (l *FocusListRowBase) TypedRune(r rune) {
}

func (l *FocusListRowBase) MouseIn(e *desktop.MouseEvent) {
l.hovered = true
l.hoverRect.FillColor = theme.HoverColor()
l.hoverRect.Refresh()
}

func (l *FocusListRowBase) MouseMoved(e *desktop.MouseEvent) {
}

func (l *FocusListRowBase) MouseOut() {
l.hovered = false
l.hoverRect.FillColor = color.Transparent
l.hoverRect.Refresh()
}

func (l *FocusListRowBase) Refresh() {
l.focusedRect.FillColor = theme.HoverColor()
l.focusedRect.Hidden = !l.Focused
l.selectionRect.FillColor = theme.SelectionColor()
l.selectionRect.Hidden = !l.Selected
l.updateBackgroundRendering()
l.BaseWidget.Refresh()
}

func (l *FocusListRowBase) CreateRenderer() fyne.WidgetRenderer {
if l.selectionRect == nil {
l.selectionRect = canvas.NewRectangle(theme.SelectionColor())
l.selectionRect.CornerRadius = theme.SelectionRadiusSize()
l.selectionRect.Hidden = !l.Selected
func (l *FocusListRowBase) updateBackgroundRendering() {
if l.Selected {
l.selectionRect.FillColor = theme.SelectionColor()
} else {
l.selectionRect.FillColor = color.Transparent
}
if l.focusedRect == nil {
l.focusedRect = canvas.NewRectangle(theme.HoverColor())
l.focusedRect.CornerRadius = theme.SelectionRadiusSize()
l.focusedRect.Hidden = !l.Focused
if l.Focused {
l.focusedRect.FillColor = theme.HoverColor()
} else {
l.focusedRect.FillColor = color.Transparent
}
if l.hovered {
l.hoverRect.FillColor = theme.HoverColor()
} else {
l.hoverRect.FillColor = color.Transparent
}
}

func (l *FocusListRowBase) CreateRenderer() fyne.WidgetRenderer {
l.selectionRect.CornerRadius = theme.SelectionRadiusSize()
l.focusedRect.CornerRadius = theme.SelectionRadiusSize()
l.hoverRect.CornerRadius = theme.SelectionRadiusSize()
l.updateBackgroundRendering()

return widget.NewSimpleRenderer(
container.NewStack(l.selectionRect, l.focusedRect, l.Content),
container.NewStack(&l.selectionRect, &l.focusedRect, &l.hoverRect, l.Content),
)
}
6 changes: 4 additions & 2 deletions ui/widgets/gridviewitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"

ttwidget "github.com/dweymouth/fyne-tooltip/widget"
"github.com/dweymouth/supersonic/res"
myTheme "github.com/dweymouth/supersonic/ui/theme"
"github.com/dweymouth/supersonic/ui/util"
Expand Down Expand Up @@ -142,7 +143,7 @@ type GridViewItem struct {

itemID string
secondaryIDs []string
primaryText *widget.Hyperlink
primaryText *ttwidget.Hyperlink
secondaryText *MultiHyperlink
suffix string
container *fyne.Container
Expand All @@ -165,7 +166,7 @@ type GridViewItem struct {

func NewGridViewItem(placeholderResource fyne.Resource) *GridViewItem {
g := &GridViewItem{
primaryText: widget.NewHyperlink("", nil),
primaryText: ttwidget.NewHyperlink("", nil),
secondaryText: NewMultiHyperlink(),
Cover: newCoverImage(placeholderResource),
}
Expand Down Expand Up @@ -220,6 +221,7 @@ func (g *GridViewItem) Update(model GridViewItemModel) {
g.itemID = model.ID
g.secondaryIDs = model.SecondaryIDs
g.primaryText.SetText(model.Name)
g.primaryText.SetToolTip(model.Name)
g.secondaryText.BuildSegments(model.Secondary, model.SecondaryIDs)
if g.ShowSuffix {
g.secondaryText.Suffix = model.Suffix
Expand Down
Loading

0 comments on commit 66b8d4b

Please sign in to comment.