Add GTK application implementation
This commit is contained in:
parent
d1bb505e0a
commit
b7c0307f6b
29 changed files with 2564 additions and 266 deletions
42
internal/gui/albumheaderbar.go
Normal file
42
internal/gui/albumheaderbar.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/diamondburned/gotk4-adwaita/pkg/adw"
|
||||
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
||||
"suruatoel.xyz/mcg/data"
|
||||
"suruatoel.xyz/mcg/internal/common"
|
||||
)
|
||||
|
||||
type albumHeaderbar struct {
|
||||
*adw.Bin
|
||||
titleLabel *gtk.Label
|
||||
artistLabel *gtk.Label
|
||||
closeButton *gtk.Button
|
||||
}
|
||||
|
||||
func newAlbumHeaderbar() *albumHeaderbar {
|
||||
bar := albumHeaderbar{}
|
||||
bar.loadWidgets()
|
||||
|
||||
return &bar
|
||||
}
|
||||
|
||||
func (b *albumHeaderbar) loadWidgets() {
|
||||
builder := gtk.NewBuilderFromString(data.AlbumHeaderbarXML)
|
||||
|
||||
b.Bin = builder.GetObject("McgAlbumHeaderbar").Cast().(*adw.Bin)
|
||||
b.titleLabel = builder.GetObject("standalone_title").Cast().(*gtk.Label)
|
||||
b.artistLabel = builder.GetObject("standalone_artist").Cast().(*gtk.Label)
|
||||
b.closeButton = builder.GetObject("close_button").Cast().(*gtk.Button)
|
||||
}
|
||||
|
||||
func (b *albumHeaderbar) SetAlbum(album *common.Album) {
|
||||
b.titleLabel.SetText(album.Title())
|
||||
b.artistLabel.SetText(strings.Join(album.Artists(), ", "))
|
||||
}
|
||||
|
||||
func (b *albumHeaderbar) ConnectClose(callback func()) {
|
||||
b.closeButton.ConnectClicked(callback)
|
||||
}
|
||||
Loading…
Reference in a new issue