diff --git a/README.md b/README.md index 72ca2b4..c0dfedc 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,10 @@ Slightly outdated screenshots of Supersonic running against the Navidrome 0 { + if ts, ok := segs[0].(*widget.TextSegment); ok && strings.TrimSpace(ts.Text) != "" { + a.biographyDisp.Segments = segs + a.biographyDisp.Refresh() + } + } } /** TODO: if len(info.SimilarArtist) > 0 { @@ -208,13 +216,13 @@ func NewMissingArtistImage() *MissingArtistImage { img := canvas.NewImageFromResource(res.ResPeopleInvertPng) img.FillMode = canvas.ImageFillContain img.SetMinSize(fyne.NewSize(64, 64)) - rect := canvas.NewRectangle(color.Transparent) + rect := canvas.NewRectangle(theme.BackgroundColor()) rect.StrokeColor = color.Black rect.StrokeWidth = 3 rect.SetMinSize(fyne.NewSize(225, 225)) m.container = container.NewMax( - container.NewCenter(img), rect, + container.NewCenter(img), ) return m } diff --git a/ui/util/util.go b/ui/util/util.go index aa2481b..e5f3b83 100644 --- a/ui/util/util.go +++ b/ui/util/util.go @@ -3,6 +3,10 @@ package util import ( "fmt" "math" + "strings" + + "fyne.io/fyne/v2/widget" + "golang.org/x/net/html" ) func SecondsToTimeString(s float64) string { @@ -15,3 +19,31 @@ func SecondsToTimeString(s float64) string { return fmt.Sprintf("%3d:%02d", min, sec) } + +func RichTextSegsFromHTMLString(s string) []widget.RichTextSegment { + tokr := html.NewTokenizer(strings.NewReader(s)) + var segs []widget.RichTextSegment + + var isLink bool + var done bool + for !done { + tt := tokr.Next() + switch { + case tt == html.ErrorToken: + done = true + case tt == html.StartTagToken: + t := tokr.Token() + isLink = t.Data == "a" + case tt == html.EndTagToken: + isLink = false + case tt == html.TextToken: + t := tokr.Token() + // for now, skip displaying Navidrome's "Read more on Last.FM" link + if !isLink { + segs = append(segs, &widget.TextSegment{Text: t.Data}) + } + } + } + + return segs +}