core icon indicating copy to clipboard operation
core copied to clipboard

Background image does not render in yaegi

Open kkoreilly opened this issue 5 months ago • 3 comments

Describe the bug

s.Background = img does not result in the image being rendered.

How to reproduce

See https://www.cogentcore.org/core/colors#image

Example code


Relevant output


Platform

macOS

kkoreilly avatar Jul 12 '25 23:07 kkoreilly

that same code works fine when compiled directly, in my debug project. on mac and web. So it is something with the yaegi environment..

//go:embed image.png
var myImage embed.FS

func main() {
	b := core.NewBody()

	fr := core.NewFrame(b)
	img, _, err := imagex.OpenFS(myImage, "image.png")
	errors.Log(err)
	fr.Styler(func(s *styles.Style) {
		s.Background = img
		s.Min.Set(units.Em(10))
	})

	b.RunMainWindow()
}

rcoreilly avatar Jul 15 '25 07:07 rcoreilly

it might be that yaegicore is out of date but I can't rebuild right now due to go version automatically changing to 1.24.5 on me.

rcoreilly avatar Jul 15 '25 08:07 rcoreilly

reminder to self: look in the go.work file for the version number there -- goscript was inflating mine..

no progress after rebuilding yaegi -- clearly it has the image good and proper -- tried this in the docs:

fr := core.NewFrame(b)
img, _, err := imagex.OpenFS(myImage, "image.png")
errors.Log(err)
fmt.Printf("%T\n", img)
rimg := imagex.AsRGBA(img)
fmt.Printf("%T %v %v\n", rimg, rimg.Bounds(), rimg.At(50,50))
fr.Styler(func(s *styles.Style) {
	s.Background = rimg
	s.Min.Set(units.Em(10))
})

output:

*image.NRGBA
*image.RGBA (0,0)-(128,128) {251 189 14 255}

Interesting that we keep getting these NRGBA guys everywhere. but converting to an RGA obviously doesn't help.

rcoreilly avatar Jul 15 '25 10:07 rcoreilly