config panel, kuwo source, playlist operation, bug fix @6, panic handling

This commit is contained in:
Aynakeya
2022-06-25 14:08:50 -07:00
parent 9f75839ebc
commit 0a53e8220e
40 changed files with 920 additions and 3992 deletions

View File

@@ -7,9 +7,36 @@ import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
type playlistOperationButton struct {
widget.Button
Index int
menu *fyne.Menu
}
func (b *playlistOperationButton) Tapped(e *fyne.PointEvent) {
widget.ShowPopUpMenuAtPosition(b.menu, fyne.CurrentApp().Driver().CanvasForObject(b), e.AbsolutePosition)
}
func newPlaylistOperationButton() *playlistOperationButton {
b := &playlistOperationButton{Index: 0}
deleteItem := fyne.NewMenuItem("Delete", func() {
fmt.Println("delete", b.Index)
})
topItem := fyne.NewMenuItem("Top", func() {
controller.UserPlaylist.Move(b.Index, 0)
})
m := fyne.NewMenu("", deleteItem, topItem)
b.menu = m
b.Text = ""
b.Icon = theme.MoreHorizontalIcon()
b.ExtendBaseWidget(b)
return b
}
type PlaylistContainer struct {
Playlist *player.Playlist
List *widget.List
@@ -22,28 +49,31 @@ func createPlaylist() fyne.CanvasObject {
UserPlaylist.List = widget.NewList(
func() int {
//debug.PrintStack()
// todo: @4
//todo: @4
return UserPlaylist.Playlist.Size()
},
func() fyne.CanvasObject {
return container.NewBorder(nil, nil, widget.NewLabel("index"), widget.NewLabel("user"),
container.NewGridWithColumns(2,
return container.NewBorder(nil, nil, widget.NewLabel("index"), newPlaylistOperationButton(),
container.NewGridWithColumns(3,
newLabelWithWrapping("title", fyne.TextTruncate),
newLabelWithWrapping("artist", fyne.TextTruncate)))
newLabelWithWrapping("artist", fyne.TextTruncate),
newLabelWithWrapping("user", fyne.TextTruncate)))
},
func(id widget.ListItemID, object fyne.CanvasObject) {
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Label).SetText(
UserPlaylist.Playlist.Playlist[id].Title)
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*widget.Label).SetText(
UserPlaylist.Playlist.Playlist[id].Artist)
object.(*fyne.Container).Objects[0].(*fyne.Container).Objects[2].(*widget.Label).SetText(
UserPlaylist.Playlist.Playlist[id].ToUser().Name)
object.(*fyne.Container).Objects[1].(*widget.Label).SetText(fmt.Sprintf("%d", id))
object.(*fyne.Container).Objects[2].(*widget.Label).SetText(UserPlaylist.Playlist.Playlist[id].ToUser().Name)
object.(*fyne.Container).Objects[2].(*playlistOperationButton).Index = id
})
registerPlaylistHandler()
return container.NewBorder(
container.NewBorder(nil, nil,
widget.NewLabel("#"), widget.NewLabel("User"),
container.NewGridWithColumns(2, widget.NewLabel("Title"), widget.NewLabel("Artist"))),
widget.NewLabel("#"), widget.NewLabel("OPs"),
container.NewGridWithColumns(3, widget.NewLabel("Title"), widget.NewLabel("Artist"), widget.NewLabel("User"))),
widget.NewSeparator(),
nil, nil,
UserPlaylist.List,
@@ -52,6 +82,9 @@ func createPlaylist() fyne.CanvasObject {
func registerPlaylistHandler() {
UserPlaylist.Playlist.Handler.RegisterA(player.EventPlaylistUpdate, "gui.playlist.update", func(event *event.Event) {
// @6 Read lock Playlist when updating free after updating.
UserPlaylist.Playlist.Lock.RLock()
UserPlaylist.List.Refresh()
UserPlaylist.Playlist.Lock.RUnlock()
})
}