Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window improperly sized if contains image with ImageFillOriginal and setFixedSize is set #2800

Closed
kheyse-oqton opened this issue Feb 21, 2022 · 12 comments
Labels
bug Something isn't working

Comments

@kheyse-oqton
Copy link

kheyse-oqton commented Feb 21, 2022

Describe the bug:

Regression where window does not take image size into account if setfixedsize is true.

The regression is blocking us from upgrading to v2.1. Same code worked on v2.0

To Reproduce:

Run the app

Screenshots:

v2.0
Screenshot 2022-02-18 at 11 12 36
v2.1
Screenshot 2022-02-18 at 11 12 08

Example code:

	header := canvas.NewImageFromResource(resourceHeaderSvg)
	header.FillMode = canvas.ImageFillOriginal

	w.SetContent(container.NewVBox(
		header,
	))

	w.SetFixedSize(true)

	w.ShowAndRun()

Device (please complete the following information):

  • OS: Mac os
  • Version: 12.2.1 on an M1
  • Go version: 1.17.6
  • Fyne version: 2.1.2
@kheyse-oqton kheyse-oqton added the unverified A bug that has been reported but not verified label Feb 21, 2022
@andydotxyz andydotxyz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels Feb 28, 2022
@andydotxyz
Copy link
Member

This relates to the MinSize of FillOriginal is not known until the image is loaded after initial render request.

@andydotxyz andydotxyz changed the title Window improperly sized if contains image and setFixedSize is set Window improperly sized if contains image with ImageFillOriginal and setFixedSize is set Mar 7, 2022
@kheyse-oqton
Copy link
Author

This relates to the MinSize of FillOriginal is not known until the image is loaded after initial render request.

is there a workaround? because this blocks us from upgrading from 2.0

@andydotxyz
Copy link
Member

In general it is a bad idea to prop windows open using ImageFillOriginal - the results will be very different depending on device (i.e. with a 3* pixel density on iPhone or Retina/HiDPI on PC the window will be 1/3 or 1/2 of the expected size.
You should, wherever possible, use Fyne coordinates to describe size. Therefore in this instance Window.Resize would be a more platform-safe approach.

@kheyse-oqton
Copy link
Author

kheyse-oqton commented Mar 7, 2022

I tried adding my image without ImageFillOriginal
but I always get a squashed image that is nearly invisible
image

I use a Resize() on the image and i tried any FillMode. only ImageFillOriginal shows the whole image. Is that expected?

package main

import (
	"fmt"
	"image/color"
	"log"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/container"
)

func main() {
	grey := color.NRGBA{R: 141, G: 140, B: 139, A: 255}

	a := app.New()
	w := a.NewWindow("app")

	header := canvas.NewImageFromResource(resourceHeaderSvg)
	header.FillMode = canvas.ImageFillContain
	header.Resize(fyne.NewSize(450, 90))

	versionText := fmt.Sprintf("Version %s", "123")
	versionLabel := canvas.NewText(versionText, grey)
	versionLabel.TextSize = 9

	w.SetContent(container.NewVBox(
		header,
		versionLabel,
	))

	w.SetFixedSize(true)
	w.Resize(fyne.NewSize(460, 180))

	w.ShowAndRun()

	log.Println("Exiting")
}

@andydotxyz
Copy link
Member

I tried adding my image without ImageFillOriginal
but I always get a squashed image that is nearly invisible

Yes, as an image which is pixel based has no innate size in a vector world the default is basically 1x1.
The right thing to do is to figure out how much space you want to allocate to your image and then fill it (the default mode).
If you want to fill remaining space in your window then a border layout may be all you need, with the image filling the central space.

@andydotxyz
Copy link
Member

It looks like this and #2819 were more related than I thought, If you get a chance please test #2829 - I think it resolves this issue as well.

@kheyse-oqton
Copy link
Author

I'd like to test it when i have some time, but i haven't yet been able to test my code with an unreleased version of the fyne library. Do you know of instructions on how to do that? Sorry, go is not my main development platform.

@Jacalz
Copy link
Member

Jacalz commented Mar 10, 2022

I usually download the zip file for the given branch (https://github.com/andydotxyz/fyne/archive/refs/heads/fix/2819.zip in this case) and then copy the reproduction code into cmd/hello/main.go. It is certainly not the most elegant solution, but it gets the job done :)

@kheyse-oqton
Copy link
Author

Thanks for the help.

With the code from the zip file included above, and this test code:

package main

import (
	"fmt"
	"image/color"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/container"
)

var resourceHeaderSvg = &fyne.StaticResource{
	StaticName: "header.svg",
	StaticContent: []byte(
		"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<svg\n   version=\"1.1\"\n   x=\"0px\"\n   y=\"0px\"\n   viewBox=\"0 0 451.02 90.05\"\n   id=\"svg103\"\n   sodipodi:docname=\"header.svg\"\n   inkscape:version=\"1.1.1 (c3084ef, 2021-09-22)\"\n   xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n   xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\n   xmlns=\"http://www.w3.org/2000/svg\"\n   xmlns:svg=\"http://www.w3.org/2000/svg\">\n  <defs\n     id=\"defs107\" />\n  <sodipodi:namedview\n     id=\"namedview105\"\n     pagecolor=\"#ffffff\"\n     bordercolor=\"#666666\"\n     borderopacity=\"1.0\"\n     inkscape:pageshadow=\"2\"\n     inkscape:pageopacity=\"0.0\"\n     inkscape:pagecheckerboard=\"0\"\n     showgrid=\"false\"\n     borderlayer=\"true\"\n     inkscape:zoom=\"1.0729879\"\n     inkscape:cx=\"257.22564\"\n     inkscape:cy=\"176.60963\"\n     inkscape:window-width=\"1662\"\n     inkscape:window-height=\"1053\"\n     inkscape:window-x=\"1966\"\n     inkscape:window-y=\"182\"\n     inkscape:window-maximized=\"0\"\n     inkscape:current-layer=\"svg103\" />\n  <rect\n     width=\"1000\"\n     height=\"1000\"\n     x=\"-200\"\n     y=\"-200\"\n     fill=\"#e63231\"\n     id=\"rect75\"\n     sodipodi:insensitive=\"true\" />\n  \n</svg>\n"),
}

func main() {
	grey := color.NRGBA{R: 141, G: 140, B: 139, A: 255}

	a := app.New()
	w := a.NewWindow("Hello")

	header := canvas.NewImageFromResource(resourceHeaderSvg)
	header.FillMode = canvas.ImageFillOriginal

	versionText := fmt.Sprintf("Version %s", "123")
	versionLabel := canvas.NewText(versionText, grey)
	versionLabel.TextSize = 9

	w.SetContent(container.NewVBox(
		header,
		versionLabel,
	))

	w.SetFixedSize(true)

	w.ShowAndRun()
}

i get this output:
image
A window with just the text and nearly invisible image.
Adding header.Resize(fyne.NewSize(450, 90)) also gives the same result

@andydotxyz
Copy link
Member

Sorry it isn't fixed. My simpler test code looked good, but there's still more to do.
The bug fix is still useful, but removed the note that it fixes this as well.

@andydotxyz andydotxyz added this to the Fixes (v2.1.x) milestone Mar 10, 2022
andydotxyz added a commit to andydotxyz/fyne that referenced this issue Mar 14, 2022
@andydotxyz
Copy link
Member

I think that linked PR (#2846) resolves it. Sorry for the regression!

Once this is landed and a couple of smaller items we will get 2.1.4 underway.

andydotxyz added a commit that referenced this issue Mar 14, 2022
@andydotxyz
Copy link
Member

Fix landed for v2.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants