Skip to content

Commit

Permalink
Match aspect lookup against resource name not pointer
Browse files Browse the repository at this point in the history
Also update to check file path before image pointer
  • Loading branch information
andydotxyz committed Dec 9, 2020
1 parent cc012e8 commit 3bca1ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/painter/image.go
Expand Up @@ -64,7 +64,7 @@ func PaintImage(img *canvas.Image, c fyne.Canvas, width, height int) image.Image

icon.SetTarget(0, 0, float64(texW), float64(texH))
// this is used by our render code, so let's set it to the file aspect
aspects[img.Resource] = aspect
aspects[name] = aspect
// if the image specifies it should be original size we need at least that many pixels on screen
if img.FillMode == canvas.ImageFillOriginal {
if !checkImageMinSize(img, c, origW, origH) {
Expand Down Expand Up @@ -97,7 +97,7 @@ func PaintImage(img *canvas.Image, c fyne.Canvas, width, height int) image.Image
}
origSize := pixels.Bounds().Size()
// this is used by our render code, so let's set it to the file aspect
aspects[img] = float32(origSize.X) / float32(origSize.Y)
aspects[name] = float32(origSize.X) / float32(origSize.Y)
// if the image specifies it should be original size we need at least that many pixels on screen
if img.FillMode == canvas.ImageFillOriginal {
if !checkImageMinSize(img, c, origSize.X, origSize.Y) {
Expand Down
8 changes: 7 additions & 1 deletion internal/painter/svg_cache.go
Expand Up @@ -32,7 +32,13 @@ func init() {

// GetAspect looks up an aspect ratio of an image
func GetAspect(img *canvas.Image) float32 {
aspect := aspects[img.Resource]
aspect := float32(0.0)
if img.Resource != nil {
aspect = aspects[img.Resource.Name()]
} else if img.File != "" {
aspect = aspects[img.File]
}

if aspect == 0 {
aspect = aspects[img]
}
Expand Down
2 changes: 1 addition & 1 deletion theme/icons.go
Expand Up @@ -42,7 +42,7 @@ func (res *ThemedResource) Content() []byte {
return colorizeResource(res.source, clr)
}

// Error resturns a different resource for indicating an error.
// Error returns a different resource for indicating an error.
func (res *ThemedResource) Error() *ErrorThemedResource {
return NewErrorThemedResource(res)
}
Expand Down

0 comments on commit 3bca1ce

Please sign in to comment.