add unsynced lyrics view (not tested yet)
This commit is contained in:
@@ -1,15 +1,51 @@
|
||||
package widgets
|
||||
|
||||
import "fyne.io/fyne/v2/widget"
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
)
|
||||
|
||||
type LyricsViewer struct {
|
||||
widget.Label
|
||||
widget.BaseWidget
|
||||
|
||||
noLyricsLabel widget.Label
|
||||
unsyncedViewer *widget.RichText
|
||||
|
||||
container *container.Scroll
|
||||
}
|
||||
|
||||
func NewLyricsViewer() *LyricsViewer {
|
||||
l := &LyricsViewer{Label: widget.Label{
|
||||
l := &LyricsViewer{noLyricsLabel: widget.Label{
|
||||
Text: "Lyrics not available",
|
||||
}}
|
||||
l.ExtendBaseWidget(l)
|
||||
l.container = container.NewVScroll(&l.noLyricsLabel)
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *LyricsViewer) SetLyrics(lyrics *mediaprovider.Lyrics) {
|
||||
if lyrics == nil {
|
||||
l.container.Content = &l.noLyricsLabel
|
||||
l.Refresh()
|
||||
return
|
||||
}
|
||||
|
||||
if l.unsyncedViewer == nil {
|
||||
l.unsyncedViewer = widget.NewRichText()
|
||||
}
|
||||
l.unsyncedViewer.Segments = l.unsyncedViewer.Segments[:0]
|
||||
for _, line := range lyrics.Lines {
|
||||
ts := &widget.TextSegment{Text: line.Text}
|
||||
ts.Style.Alignment = fyne.TextAlignCenter
|
||||
ts.Style.Inline = false
|
||||
l.unsyncedViewer.Segments = append(l.unsyncedViewer.Segments, ts)
|
||||
}
|
||||
l.container.Content = l.unsyncedViewer
|
||||
l.Refresh()
|
||||
}
|
||||
|
||||
func (l *LyricsViewer) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(l.container)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user