add play button to center of album cover in album grid
This commit is contained in:
@@ -44,4 +44,4 @@ require (
|
||||
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
|
||||
)
|
||||
|
||||
replace fyne.io/fyne/v2 v2.2.4 => github.com/dweymouth/fyne/v2 v2.2.5-0.20230110171955-98071d7f072f
|
||||
replace fyne.io/fyne/v2 v2.2.4 => github.com/dweymouth/fyne/v2 v2.2.5-0.20230119024415-238e09217d09
|
||||
|
||||
@@ -72,8 +72,8 @@ github.com/danieljoos/wincred v1.1.0/go.mod h1:XYlo+eRTsVA9aHGp7NGjFkPla4m+DCL7h
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dweymouth/fyne/v2 v2.2.5-0.20230110171955-98071d7f072f h1:Tgz5Tx14yQLkKl4JH5eGWnUpq9J8+cbLTuj8lfzgqG0=
|
||||
github.com/dweymouth/fyne/v2 v2.2.5-0.20230110171955-98071d7f072f/go.mod h1:MBoGuHzLLSXdQOWFAwWhIhYTEMp33zqtGCReSWhaQTA=
|
||||
github.com/dweymouth/fyne/v2 v2.2.5-0.20230119024415-238e09217d09 h1:huJvmT36/E7MsuAVILCK7VPFd0UiPQDpphn215e1rCo=
|
||||
github.com/dweymouth/fyne/v2 v2.2.5-0.20230119024415-238e09217d09/go.mod h1:MBoGuHzLLSXdQOWFAwWhIhYTEMp33zqtGCReSWhaQTA=
|
||||
github.com/dweymouth/go-subsonic v0.0.0-20221214005741-bd8048fa1863 h1:bOWMpFJ9zY839T1EngQ5nxVCiMlatPtpGkg/yHK6szg=
|
||||
github.com/dweymouth/go-subsonic v0.0.0-20221214005741-bd8048fa1863/go.mod h1:fUez6NFiEJiQTZizZ1BThZr5GJXAbigzGYjEPNm4tdI=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -12,6 +12,7 @@ fyne bundle -append -prefix Res icons/musicnotes.png >> bundled.go
|
||||
fyne bundle -append -prefix Res icons/musicnotes-invert.png >> bundled.go
|
||||
fyne bundle -append -prefix Res icons/people.png >> bundled.go
|
||||
fyne bundle -append -prefix Res icons/people-invert.png >> bundled.go
|
||||
fyne bundle -append -prefix Res icons/playbutton.png >> bundled.go
|
||||
fyne bundle -append -prefix Res icons/playlist.png >> bundled.go
|
||||
fyne bundle -append -prefix Res icons/playlist-invert.png >> bundled.go
|
||||
fyne bundle -append -prefix Res icons/podcast.png >> bundled.go
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
+72
-13
@@ -3,14 +3,17 @@ package widgets
|
||||
import (
|
||||
"context"
|
||||
"image"
|
||||
"image/color"
|
||||
"strconv"
|
||||
|
||||
"supersonic/res"
|
||||
"supersonic/ui/layouts"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/driver/desktop"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
@@ -20,45 +23,105 @@ var _ fyne.Widget = (*AlbumCard)(nil)
|
||||
|
||||
var _ fyne.Widget = (*albumCover)(nil)
|
||||
var _ fyne.Tappable = (*albumCover)(nil)
|
||||
var _ fyne.DoubleTappable = (*albumCover)(nil)
|
||||
|
||||
type albumCover struct {
|
||||
widget.BaseWidget
|
||||
|
||||
Im *canvas.Image
|
||||
playbtn *canvas.Image
|
||||
btnCircle *btnCircle
|
||||
OnDoubleTapped func()
|
||||
OnTapped func()
|
||||
}
|
||||
|
||||
type btnCircle struct {
|
||||
canvas.Circle
|
||||
|
||||
Diameter float32
|
||||
}
|
||||
|
||||
func (b *btnCircle) MinSize() fyne.Size {
|
||||
return fyne.NewSize(b.Diameter, b.Diameter)
|
||||
}
|
||||
|
||||
func newAlbumCover() *albumCover {
|
||||
a := &albumCover{}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.Im = &canvas.Image{FillMode: canvas.ImageFillContain}
|
||||
a.Im.SetMinSize(fyne.NewSize(200, 200))
|
||||
a.playbtn = &canvas.Image{FillMode: canvas.ImageFillContain, Resource: res.ResPlaybuttonPng}
|
||||
a.playbtn.SetMinSize(fyne.NewSize(60, 60))
|
||||
a.playbtn.Hidden = true
|
||||
// TODO:
|
||||
a.btnCircle = &btnCircle{
|
||||
Diameter: 63,
|
||||
Circle: canvas.Circle{
|
||||
FillColor: color.Transparent,
|
||||
StrokeColor: theme.PrimaryColor(),
|
||||
StrokeWidth: 2,
|
||||
Hidden: true,
|
||||
},
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *albumCover) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(a.Im)
|
||||
return widget.NewSimpleRenderer(
|
||||
container.NewMax(a.Im, container.NewCenter(a.playbtn), container.NewCenter(a.btnCircle)),
|
||||
)
|
||||
}
|
||||
|
||||
func (a *albumCover) DoubleTapped(e *fyne.PointEvent) {
|
||||
if a.OnDoubleTapped != nil {
|
||||
a.OnDoubleTapped()
|
||||
}
|
||||
func (a *albumCover) Cursor() desktop.Cursor {
|
||||
return desktop.PointerCursor
|
||||
}
|
||||
|
||||
func (a *albumCover) Tapped(e *fyne.PointEvent) {
|
||||
if isInside(a.center(), a.playbtn.Size().Height/2, e.Position) {
|
||||
if a.OnDoubleTapped != nil {
|
||||
a.OnDoubleTapped()
|
||||
}
|
||||
return
|
||||
}
|
||||
if a.OnTapped != nil {
|
||||
a.OnTapped()
|
||||
}
|
||||
}
|
||||
|
||||
func (a *albumCover) MouseIn(*desktop.MouseEvent) {
|
||||
a.playbtn.Hidden = false
|
||||
a.Refresh()
|
||||
}
|
||||
|
||||
func (a *albumCover) MouseOut() {
|
||||
a.playbtn.Hidden = true
|
||||
a.Refresh()
|
||||
}
|
||||
|
||||
// TODO: figure out why circle around play button isn't being displayed
|
||||
func (a *albumCover) MouseMoved(e *desktop.MouseEvent) {
|
||||
if inside := isInside(a.center(), a.btnCircle.Diameter/2, e.Position); inside && !a.btnCircle.Visible() {
|
||||
a.btnCircle.Show()
|
||||
a.Refresh()
|
||||
} else if !inside && a.btnCircle.Visible() {
|
||||
a.btnCircle.Hide()
|
||||
a.Refresh()
|
||||
}
|
||||
}
|
||||
|
||||
func (a *albumCover) center() fyne.Position {
|
||||
return fyne.NewPos(a.Size().Width/2, a.Size().Height/2)
|
||||
}
|
||||
|
||||
func (a *albumCover) SetImage(im image.Image) {
|
||||
a.Im.Image = im
|
||||
a.Refresh()
|
||||
}
|
||||
|
||||
func isInside(origin fyne.Position, radius float32, point fyne.Position) bool {
|
||||
x, y := (point.X - origin.X), (point.Y - origin.Y)
|
||||
return x*x+y*y <= radius*radius
|
||||
}
|
||||
|
||||
type AlbumCard struct {
|
||||
widget.BaseWidget
|
||||
|
||||
@@ -83,12 +146,6 @@ type AlbumCard struct {
|
||||
OnShowArtistPage func()
|
||||
}
|
||||
|
||||
func (a *AlbumCard) MouseIn(*desktop.MouseEvent) {}
|
||||
|
||||
func (a *AlbumCard) MouseOut() {}
|
||||
|
||||
func (a *AlbumCard) MouseMoved(*desktop.MouseEvent) {}
|
||||
|
||||
func NewAlbumCard(showYear bool) *AlbumCard {
|
||||
a := &AlbumCard{
|
||||
title: NewCustomHyperlink(),
|
||||
@@ -103,11 +160,13 @@ func NewAlbumCard(showYear bool) *AlbumCard {
|
||||
a.OnPlay()
|
||||
}
|
||||
}
|
||||
a.title.OnTapped = func() {
|
||||
showAlbumFn := func() {
|
||||
if a.OnShowAlbumPage != nil {
|
||||
a.OnShowAlbumPage()
|
||||
}
|
||||
}
|
||||
a.Cover.OnTapped = showAlbumFn
|
||||
a.title.OnTapped = showAlbumFn
|
||||
a.artist.OnTapped = func() {
|
||||
if a.OnShowArtistPage != nil {
|
||||
a.OnShowArtistPage()
|
||||
|
||||
Reference in New Issue
Block a user