switch to fyne-lyrics viewer

This commit is contained in:
Drew Weymouth
2024-05-16 18:23:51 -07:00
parent 06780e110b
commit 220d523f88
3 changed files with 34 additions and 42 deletions
+6 -5
View File
@@ -1,9 +1,9 @@
module github.com/dweymouth/supersonic
go 1.21
go 1.21.1
require (
fyne.io/fyne/v2 v2.4.4
fyne.io/fyne/v2 v2.4.5
github.com/20after4/configdir v0.1.1
github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1
github.com/dweymouth/go-jellyfin v0.0.0-20240330010648-fb02c0b3878e
@@ -24,13 +24,14 @@ require (
github.com/alessio/shellescape v1.4.1 // indirect
github.com/danieljoos/wincred v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dweymouth/fyne-lyrics v0.0.0-20240517003322-3c47c48b1751 // indirect
github.com/fredbi/uri v1.0.0 // indirect
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240306074159-ea2d69986ecb // indirect
github.com/go-text/render v0.1.0 // indirect
github.com/go-text/typesetting v0.1.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
@@ -47,4 +48,4 @@ require (
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
)
replace fyne.io/fyne/v2 v2.4.4 => github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240418162613-9e56d7882130
replace fyne.io/fyne/v2 v2.4.5 => github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240418162613-9e56d7882130
+8 -6
View File
@@ -69,6 +69,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1 h1:mGvOb3zxl4vCLv+dbf7JA6CAaM2UH/AGP1KX4DsJmTI=
github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1/go.mod h1:ZNCLJfehvEf34B7BbLKjgpsL9lyW7q938w/GY1XgV4E=
github.com/dweymouth/fyne-lyrics v0.0.0-20240517003322-3c47c48b1751 h1:siUJZlGbTAzpIUDGDkzM3KD5g1oOHsJRUeGEW/hDHnw=
github.com/dweymouth/fyne-lyrics v0.0.0-20240517003322-3c47c48b1751/go.mod h1:wfA5DWb0Udzq4K7MkzK+EzrM7xAyGyUpNO2HbWBPNvs=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240418162613-9e56d7882130 h1:HLnkaB2GRPMDaNgQ/HaEDKChU18UnLzJaq29dsfuGEA=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240418162613-9e56d7882130/go.mod h1:VyrxAOZ3NRZRWBvNIJbfqoKOG4DdbewoPk7ozqJKNPY=
github.com/dweymouth/go-jellyfin v0.0.0-20240330010648-fb02c0b3878e h1:89N7tfmGPA3kB3JPhm0UYbc2fjIMUgHPryj9jeuaeTg=
@@ -103,14 +105,14 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8 h1:VkKnvzbvHqgEfm351rfr8Uclu5fnwq8HP2ximUzJsBM=
github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8/go.mod h1:h29xCucjNsDcYb7+0rJokxVwYAq+9kQ19WiFuBKkYtc=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240306074159-ea2d69986ecb h1:S9I8pIVT5JHKDvmI1vQ0qs5fqxzUfhcZm/YbUC/8k1k=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240306074159-ea2d69986ecb/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-text/render v0.1.0 h1:osrmVDZNHuP1RSu3pNG7Z77Sd2xSbcb/xWytAj9kyVs=
github.com/go-text/render v0.1.0/go.mod h1:jqEuNMenrmj6QRnkdpeaP0oKGFLDNhDkVKwGjsWWYU4=
github.com/go-text/typesetting v0.1.0 h1:vioSaLPYcHwPEPLT7gsjCGDCoYSbljxoHJzMnKwVvHw=
github.com/go-text/typesetting v0.1.0/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI=
github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04 h1:zBx+p/W2aQYtNuyZNcTfinWvXBQwYtDfme051PR/lAY=
github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
github.com/go-text/typesetting-utils v0.0.0-20240329101916-eee87fb235a3 h1:levTnuLLUmpavLGbJYLJA7fQnKeS7P1eCdAlM+vReXk=
github.com/go-text/typesetting-utils v0.0.0-20240329101916-eee87fb235a3/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
+20 -31
View File
@@ -4,62 +4,51 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
fynelyrics "github.com/dweymouth/fyne-lyrics"
"github.com/dweymouth/supersonic/backend/mediaprovider"
)
type LyricsViewer struct {
widget.BaseWidget
noLyricsLabel widget.Label
unsyncedViewer *widget.RichText
noLyricsLabel widget.Label
viewer *fynelyrics.LyricsViewer
container *container.Scroll
currentView lyricView
container *fyne.Container
isEmpty bool
}
type lyricView int
const (
lyricViewEmpty lyricView = iota
lyricViewUnsynced
lyricViewSynced
)
func NewLyricsViewer() *LyricsViewer {
l := &LyricsViewer{noLyricsLabel: widget.Label{
Text: "Lyrics not available",
}}
}, isEmpty: true}
l.ExtendBaseWidget(l)
l.container = container.NewVScroll(&l.noLyricsLabel)
l.container = container.NewStack(&l.noLyricsLabel)
return l
}
func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
if lyrics == nil || len(lyrics.Lines) == 0 {
if l.currentView != lyricViewEmpty {
l.container.Content = &l.noLyricsLabel
l.currentView = lyricViewEmpty
if !l.isEmpty {
l.container.Objects[0] = &l.noLyricsLabel
l.isEmpty = true
l.Refresh()
}
return
}
if l.unsyncedViewer == nil {
l.unsyncedViewer = widget.NewRichText()
l.unsyncedViewer.Wrapping = fyne.TextWrapWord
if l.viewer == nil {
l.viewer = fynelyrics.NewLyricsViewer()
l.viewer.ActiveLyricPosition = fynelyrics.ActiveLyricPositionTopThird
}
l.unsyncedViewer.Segments = nil
for _, line := range lyrics.Lines {
ts := &widget.TextSegment{Text: line.Text}
ts.Style.Alignment = fyne.TextAlignCenter
ts.Style.SizeName = widget.RichTextStyleSubHeading.SizeName
ts.Style.Inline = false
l.unsyncedViewer.Segments = append(l.unsyncedViewer.Segments, ts)
lines := make([]string, len(lyrics.Lines))
for i, line := range lyrics.Lines {
lines[i] = line.Text
}
l.unsyncedViewer.Refresh()
if l.currentView != lyricViewUnsynced {
l.container.Content = l.unsyncedViewer
l.currentView = lyricViewUnsynced
l.viewer.SetLyrics(lines, false /*synced*/)
if l.isEmpty {
l.container.Objects[0] = l.viewer
l.isEmpty = false
l.Refresh()
}
}