add open animation for pop up images
This commit is contained in:
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/dweymouth/supersonic/ui/widgets"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/lang"
|
||||
@@ -64,7 +63,7 @@ type Controller struct {
|
||||
popUpQueue *widget.PopUp
|
||||
popUpQueueList *widgets.PlayQueueList
|
||||
popUpQueueLastUsed int64
|
||||
escapablePopUp *widget.PopUp
|
||||
escapablePopUp fyne.CanvasObject
|
||||
haveModal bool
|
||||
runOnModalClosed func()
|
||||
}
|
||||
@@ -128,7 +127,7 @@ func (m *Controller) NavigateTo(route Route) {
|
||||
m.NavHandler(route)
|
||||
}
|
||||
|
||||
func (m *Controller) ClosePopUpOnEscape(pop *widget.PopUp) {
|
||||
func (m *Controller) ClosePopUpOnEscape(pop fyne.CanvasObject) {
|
||||
m.escapablePopUp = pop
|
||||
}
|
||||
|
||||
@@ -232,9 +231,6 @@ func (m *Controller) ShowPopUpPlayQueue() {
|
||||
}
|
||||
|
||||
func (m *Controller) ShowPopUpImage(img image.Image) {
|
||||
im := canvas.NewImageFromImage(img)
|
||||
im.FillMode = canvas.ImageFillContain
|
||||
pop := widget.NewPopUp(im, m.MainWindow.Canvas())
|
||||
s := m.MainWindow.Canvas().Size()
|
||||
var popS fyne.Size
|
||||
if asp := util.ImageAspect(img); s.Width/s.Height > asp {
|
||||
@@ -245,12 +241,11 @@ func (m *Controller) ShowPopUpImage(img image.Image) {
|
||||
w := s.Width * 0.8
|
||||
popS = fyne.NewSize(w, w*(1/asp))
|
||||
}
|
||||
|
||||
pop := widgets.NewImagePopUp(img, m.MainWindow.Canvas(), popS)
|
||||
|
||||
m.ClosePopUpOnEscape(pop)
|
||||
pop.Resize(popS)
|
||||
pop.ShowAtPosition(fyne.NewPos(
|
||||
(s.Width-popS.Width)/2,
|
||||
(s.Height-popS.Height)/2,
|
||||
))
|
||||
pop.Show()
|
||||
}
|
||||
|
||||
func (m *Controller) GetArtistTracks(artistID string) []*mediaprovider.Track {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"image"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
const (
|
||||
imagePopUpLowRezDim = 128
|
||||
)
|
||||
|
||||
type ImagePopUp struct {
|
||||
widget.PopUp
|
||||
|
||||
img image.Image
|
||||
desiredSize fyne.Size
|
||||
aspect float64
|
||||
}
|
||||
|
||||
func NewImagePopUp(img image.Image, canv fyne.Canvas, size fyne.Size) *ImagePopUp {
|
||||
i := &ImagePopUp{
|
||||
img: img,
|
||||
desiredSize: size,
|
||||
PopUp: widget.PopUp{
|
||||
Canvas: canv,
|
||||
Content: canvas.NewImageFromImage(img),
|
||||
},
|
||||
}
|
||||
i.ExtendBaseWidget(i)
|
||||
return i
|
||||
}
|
||||
|
||||
func (i *ImagePopUp) Show() {
|
||||
i.Content.(*canvas.Image).FillMode = canvas.ImageFillContain
|
||||
i.Content.(*canvas.Image).ScaleMode = canvas.ImageScaleFastest
|
||||
canvSize := i.Canvas.Size()
|
||||
i.ShowAtPosition(fyne.NewPos(
|
||||
canvSize.Width/2,
|
||||
canvSize.Height/2,
|
||||
))
|
||||
anim := fyne.NewAnimation(canvas.DurationShort, func(f float32) {
|
||||
if f == 1 {
|
||||
i.Content.(*canvas.Image).ScaleMode = canvas.ImageScaleSmooth
|
||||
}
|
||||
size := fyne.NewSize(i.desiredSize.Width*f, i.desiredSize.Height*f)
|
||||
i.Content.(*canvas.Image).SetMinSize(size)
|
||||
size = i.Content.MinSize()
|
||||
i.Resize(size)
|
||||
i.Move(fyne.NewPos(
|
||||
(canvSize.Width-size.Width)/2,
|
||||
(canvSize.Height-size.Height)/2,
|
||||
))
|
||||
})
|
||||
anim.Start()
|
||||
}
|
||||
Reference in New Issue
Block a user