image popup aspect ratio matches that of image

This commit is contained in:
Drew Weymouth
2023-02-06 20:19:37 -08:00
parent 3584888924
commit 87ae3e940f
2 changed files with 20 additions and 2 deletions
+14 -2
View File
@@ -227,8 +227,20 @@ func (a *AlbumPageHeader) showPopUpCover() {
im.FillMode = canvas.ImageFillContain
pop := a.page.popUpProvider.CreatePopUp(im)
s := a.page.popUpProvider.WindowSize()
pop.Resize(fyne.NewSize(s.Width*0.8, s.Height*0.8))
pop.ShowAtPosition(fyne.NewPos(0.1*s.Width, 0.1*s.Height))
var popS fyne.Size
if asp := util.ImageAspect(cover); s.Width/s.Height > asp {
// window height is limiting factor
h := s.Height * 0.8
popS = fyne.NewSize(h*asp, h)
} else {
w := s.Width * 0.8
popS = fyne.NewSize(w, w*(1/asp))
}
pop.Resize(popS)
pop.ShowAtPosition(fyne.NewPos(
(s.Width-popS.Width)/2,
(s.Height-popS.Height)/2,
))
}
func formatMiscLabelStr(a *subsonic.AlbumID3) string {
+6
View File
@@ -2,6 +2,7 @@ package util
import (
"fmt"
"image"
"math"
"strings"
@@ -20,6 +21,11 @@ func SecondsToTimeString(s float64) string {
return fmt.Sprintf("%d:%02d", min, sec)
}
func ImageAspect(im image.Image) float32 {
b := im.Bounds()
return float32(b.Max.X-b.Min.X) / float32(b.Max.Y-b.Min.Y)
}
func RichTextSegsFromHTMLString(s string) []widget.RichTextSegment {
tokr := html.NewTokenizer(strings.NewReader(s))
var segs []widget.RichTextSegment