mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-06 18:32:50 +08:00
config panel, kuwo source, playlist operation, bug fix @6, panic handling
This commit is contained in:
20
gui/config_basic.go
Normal file
20
gui/config_basic.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
)
|
||||
|
||||
type bascicConfig struct{}
|
||||
|
||||
func (b bascicConfig) Title() string {
|
||||
return "Basic"
|
||||
}
|
||||
|
||||
func (b bascicConfig) Description() string {
|
||||
return "Basic configuration"
|
||||
}
|
||||
|
||||
func (b bascicConfig) Create() fyne.CanvasObject {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
55
gui/config_layout.go
Normal file
55
gui/config_layout.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
type TestConfig struct {
|
||||
}
|
||||
|
||||
func (t *TestConfig) Title() string {
|
||||
return "Test Title"
|
||||
}
|
||||
|
||||
func (T *TestConfig) Description() string {
|
||||
return "Test Description"
|
||||
}
|
||||
|
||||
func (t *TestConfig) CreatePanel() fyne.CanvasObject {
|
||||
return widget.NewLabel("asdf")
|
||||
}
|
||||
|
||||
func createConfigLayout() fyne.CanvasObject {
|
||||
content := container.NewMax()
|
||||
entryList := widget.NewList(
|
||||
func() int {
|
||||
return len(ConfigList)
|
||||
},
|
||||
func() fyne.CanvasObject {
|
||||
return widget.NewLabel("AAAAAAAAAAAAAAAA")
|
||||
},
|
||||
func(id widget.ListItemID, object fyne.CanvasObject) {
|
||||
object.(*widget.Label).SetText(ConfigList[id].Title())
|
||||
})
|
||||
entryList.OnSelected = func(id widget.ListItemID) {
|
||||
desc := widget.NewRichTextFromMarkdown("## " + ConfigList[id].Title() + " \n\n" + ConfigList[id].Description())
|
||||
for i := range desc.Segments {
|
||||
if seg, ok := desc.Segments[i].(*widget.TextSegment); ok {
|
||||
seg.Style.Alignment = fyne.TextAlignCenter
|
||||
}
|
||||
}
|
||||
a := container.NewVScroll(ConfigList[id].CreatePanel())
|
||||
content.Objects = []fyne.CanvasObject{
|
||||
container.NewBorder(container.NewVBox(desc, widget.NewSeparator()), nil, nil, nil,
|
||||
a),
|
||||
}
|
||||
|
||||
content.Refresh()
|
||||
}
|
||||
return container.NewBorder(
|
||||
nil, nil,
|
||||
container.NewHBox(entryList, widget.NewSeparator()), nil,
|
||||
content)
|
||||
}
|
||||
14
gui/gui.go
14
gui/gui.go
@@ -12,8 +12,15 @@ import (
|
||||
|
||||
const MODULE_GUI = "GUI"
|
||||
|
||||
type ConfigLayout interface {
|
||||
Title() string
|
||||
Description() string
|
||||
CreatePanel() fyne.CanvasObject
|
||||
}
|
||||
|
||||
var App fyne.App
|
||||
var MainWindow fyne.Window
|
||||
var ConfigList = []ConfigLayout{}
|
||||
|
||||
func l() *logrus.Entry {
|
||||
return logger.Logger.WithField("Module", MODULE_GUI)
|
||||
@@ -37,6 +44,9 @@ func Initialize() {
|
||||
container.NewTabItem("Playlist",
|
||||
newPaddedBoarder(nil, nil, createPlaylists(), nil, createPlaylistMedias()),
|
||||
),
|
||||
container.NewTabItem("Config",
|
||||
newPaddedBoarder(nil, nil, nil, nil, createConfigLayout()),
|
||||
),
|
||||
)
|
||||
|
||||
tabs.SetTabLocation(container.TabLocationTop)
|
||||
@@ -46,3 +56,7 @@ func Initialize() {
|
||||
MainWindow.Resize(fyne.NewSize(960, 480))
|
||||
//MainWindow.SetFixedSize(true)
|
||||
}
|
||||
|
||||
func AddConfigLayout(cfgs ...ConfigLayout) {
|
||||
ConfigList = append(ConfigList, cfgs...)
|
||||
}
|
||||
|
||||
@@ -31,3 +31,46 @@ func createAsyncButton(btn *widget.Button, tapped func()) *widget.Button {
|
||||
btn.OnTapped = createAsyncOnTapped(btn, tapped)
|
||||
return btn
|
||||
}
|
||||
|
||||
type ContextMenuButton struct {
|
||||
widget.Button
|
||||
menu *fyne.Menu
|
||||
}
|
||||
|
||||
func (b *ContextMenuButton) Tapped(e *fyne.PointEvent) {
|
||||
widget.ShowPopUpMenuAtPosition(b.menu, fyne.CurrentApp().Driver().CanvasForObject(b), e.AbsolutePosition)
|
||||
}
|
||||
|
||||
func newContextMenuButton(label string, menu *fyne.Menu) *ContextMenuButton {
|
||||
b := &ContextMenuButton{menu: menu}
|
||||
b.Text = label
|
||||
|
||||
b.ExtendBaseWidget(b)
|
||||
return b
|
||||
}
|
||||
|
||||
type FixedSplitContainer struct {
|
||||
*container.Split
|
||||
}
|
||||
|
||||
func (f *FixedSplitContainer) Dragged(event *fyne.DragEvent) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (f *FixedSplitContainer) DragEnd() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func newFixedSplitContainer(horizontal bool, leading, trailing fyne.CanvasObject) *FixedSplitContainer {
|
||||
s := &container.Split{
|
||||
Offset: 0.5, // Sensible default, can be overridden with SetOffset
|
||||
Horizontal: horizontal,
|
||||
Leading: leading,
|
||||
Trailing: trailing,
|
||||
}
|
||||
fs := &FixedSplitContainer{
|
||||
s,
|
||||
}
|
||||
fs.Split.BaseWidget.ExtendBaseWidget(s)
|
||||
return fs
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func createPlayController() fyne.CanvasObject {
|
||||
buttonsBox := container.NewCenter(
|
||||
container.NewHBox(PlayController.ButtonPrev, PlayController.ButtonSwitch, PlayController.ButtonNext))
|
||||
|
||||
PlayController.Progress = widget.NewSlider(0, 10000)
|
||||
PlayController.Progress = widget.NewSlider(0, 1000)
|
||||
PlayController.CurrentTime = widget.NewLabel("0:00")
|
||||
PlayController.TotalTime = widget.NewLabel("0:00")
|
||||
progressItem := container.NewBorder(nil, nil, PlayController.CurrentTime, PlayController.TotalTime, PlayController.Progress)
|
||||
@@ -113,10 +113,10 @@ func registerPlayControllerHandler() {
|
||||
|
||||
if controller.MainPlayer.ObserveProperty("percent-pos", func(property *mpv.EventProperty) {
|
||||
if property.Data == nil {
|
||||
PlayController.Progress.SetValue(0)
|
||||
return
|
||||
PlayController.Progress.Value = 0
|
||||
} else {
|
||||
PlayController.Progress.Value = property.Data.(mpv.Node).Value.(float64) * 10
|
||||
}
|
||||
PlayController.Progress.Value = property.Data.(mpv.Node).Value.(float64) * 100
|
||||
PlayController.Progress.Refresh()
|
||||
}) != nil {
|
||||
l().Error("fail to register handler for progress bar with property percent-pos")
|
||||
@@ -134,14 +134,14 @@ func registerPlayControllerHandler() {
|
||||
//PlayController.Username.SetText("Username")
|
||||
//PlayController.SetDefaultCover()
|
||||
} else {
|
||||
PlayController.Progress.Max = 10000
|
||||
PlayController.Progress.Max = 1000
|
||||
}
|
||||
}) != nil {
|
||||
l().Error("fail to register handler for progress bar with property idle-active")
|
||||
}
|
||||
|
||||
PlayController.Progress.OnChanged = func(f float64) {
|
||||
controller.Seek(f/100, false)
|
||||
controller.Seek(f/10, false)
|
||||
}
|
||||
|
||||
if controller.MainPlayer.ObserveProperty("time-pos", func(property *mpv.EventProperty) {
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ func createRoomController() fyne.CanvasObject {
|
||||
controller.SetDanmuClient(RoomController.Input.Text)
|
||||
if controller.LiveClient == nil {
|
||||
RoomController.Status.SetText("Set Failed")
|
||||
RoomController.ConnectBtn.Enable()
|
||||
RoomController.Status.Refresh()
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user