switch to simpler way of themeing PNG icons
This commit is contained in:
@@ -32,12 +32,10 @@ func (f *FavoriteButton) Tapped(e *fyne.PointEvent) {
|
||||
}
|
||||
|
||||
func (f *FavoriteButton) Refresh() {
|
||||
var iconName fyne.ThemeIconName
|
||||
if f.IsFavorited {
|
||||
iconName = theme.IconNameFavorite
|
||||
f.Icon = theme.FavoriteIcon
|
||||
} else {
|
||||
iconName = theme.IconNameNotFavorite
|
||||
f.Icon = theme.NotFavoriteIcon
|
||||
}
|
||||
f.Icon = fyne.CurrentApp().Settings().Theme().Icon(iconName)
|
||||
f.Button.Refresh()
|
||||
}
|
||||
|
||||
@@ -6,34 +6,6 @@ import (
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
type ThemedIconButton struct {
|
||||
widget.Button
|
||||
|
||||
IconName fyne.ThemeIconName
|
||||
}
|
||||
|
||||
func NewThemedIconButton(iconName fyne.ThemeIconName, text string, action func()) *ThemedIconButton {
|
||||
b := &ThemedIconButton{
|
||||
IconName: iconName,
|
||||
Button: widget.Button{
|
||||
Text: text,
|
||||
OnTapped: action,
|
||||
},
|
||||
}
|
||||
b.updateIcon()
|
||||
b.ExtendBaseWidget(b)
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *ThemedIconButton) updateIcon() {
|
||||
b.Icon = fyne.CurrentApp().Settings().Theme().Icon(b.IconName)
|
||||
}
|
||||
|
||||
func (b *ThemedIconButton) Refresh() {
|
||||
b.updateIcon()
|
||||
b.Button.Refresh()
|
||||
}
|
||||
|
||||
type ThemedRectangle struct {
|
||||
widget.BaseWidget
|
||||
|
||||
@@ -61,21 +33,3 @@ func (t *ThemedRectangle) Refresh() {
|
||||
func (t *ThemedRectangle) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(t.rect)
|
||||
}
|
||||
|
||||
type ThemedTappableIcon struct {
|
||||
TappableIcon
|
||||
|
||||
IconName fyne.ThemeIconName
|
||||
}
|
||||
|
||||
func NewThemedTappableIcon(iconName fyne.ThemeIconName) *ThemedTappableIcon {
|
||||
t := &ThemedTappableIcon{IconName: iconName}
|
||||
t.ExtendBaseWidget(t)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *ThemedTappableIcon) Refresh() {
|
||||
icon := fyne.CurrentApp().Settings().Theme().Icon(t.IconName)
|
||||
t.TappableIcon.Icon.Resource = icon
|
||||
t.TappableIcon.Refresh()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"supersonic/sharedutil"
|
||||
"supersonic/ui/layouts"
|
||||
"supersonic/ui/os"
|
||||
@@ -524,7 +526,7 @@ func NewTrackRow(tracklist *Tracklist, playingIcon fyne.CanvasObject) *TrackRow
|
||||
t.album.OnTapped = func() { tracklist.onAlbumTapped(t.albumID) }
|
||||
t.dur = newTrailingAlignRichText()
|
||||
t.year = newTrailingAlignRichText()
|
||||
favorite := NewThemedTappableIcon(myTheme.IconNameNotFavorite)
|
||||
favorite := NewTappbaleIcon(myTheme.NotFavoriteIcon)
|
||||
favorite.OnTapped = t.toggleFavorited
|
||||
t.favorite = container.NewCenter(favorite)
|
||||
t.rating = NewStarRating()
|
||||
@@ -623,10 +625,10 @@ func (t *TrackRow) Update(tr *subsonic.Child, rowNum int) {
|
||||
// Render favorite column
|
||||
if tr.Starred.IsZero() {
|
||||
t.isFavorite = false
|
||||
t.favorite.Objects[0].(*ThemedTappableIcon).IconName = myTheme.IconNameNotFavorite
|
||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.NotFavoriteIcon
|
||||
} else {
|
||||
t.isFavorite = true
|
||||
t.favorite.Objects[0].(*ThemedTappableIcon).IconName = myTheme.IconNameFavorite
|
||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.FavoriteIcon
|
||||
}
|
||||
|
||||
t.rating.Rating = tr.UserRating
|
||||
@@ -648,12 +650,12 @@ func (t *TrackRow) Update(tr *subsonic.Child, rowNum int) {
|
||||
|
||||
func (t *TrackRow) toggleFavorited() {
|
||||
if t.isFavorite {
|
||||
t.favorite.Objects[0].(*ThemedTappableIcon).IconName = myTheme.IconNameNotFavorite
|
||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.NotFavoriteIcon
|
||||
t.favorite.Refresh()
|
||||
t.isFavorite = false
|
||||
t.tracklist.onSetFavorite(t.trackID, false)
|
||||
} else {
|
||||
t.favorite.Objects[0].(*ThemedTappableIcon).IconName = myTheme.IconNameFavorite
|
||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.FavoriteIcon
|
||||
t.favorite.Refresh()
|
||||
t.isFavorite = true
|
||||
t.tracklist.onSetFavorite(t.trackID, true)
|
||||
|
||||
Reference in New Issue
Block a user