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

Showing a disabled menu items with a non-SVG icon generates Fyne error #5557

Closed
2 tasks done
ErikKalkoken opened this issue Feb 26, 2025 · 1 comment
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@ErikKalkoken
Copy link
Contributor

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

When trying to show a disabled menu items with a non-SVG icon we get the following error:

2025/02/26 11:53:13 Fyne error:  
2025/02/26 11:53:13   Cause: could not load SVG, falling back to static content: XML syntax error on line 5: invalid character entity &Ӎ� (no semicolon)
2025/02/26 11:53:13   At: /home/erik/go/fyne-dev/fyne/theme/icons.go:1408

The consequence of this bug is that non-SVG icons can currently not be used for menu items, if they might be disabled. They work fine though, for non-disabled menu items.

How to reproduce

  1. Create a Fyne menu with at least one item
  2. Add a non-SVG type resource as icon to the item (e.g. PNG or JPEG)
  3. Disable the item
  4. Show the menu

Screenshots

No response

Example code

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Menu icon demo")
	icon, err := fyne.LoadResourceFromURLString(
		"https://raw.githubusercontent.com/fyne-io/fyne/refs/heads/master/cmd/fyne_demo/data/assets/fyne.png")
	if err != nil {
		panic(err)
	}
	item := fyne.NewMenuItem("First", func() {})
	item.Icon = icon
	item.Disabled = true
	w.SetContent(container.NewCenter(widget.NewButton("Click me", func() {
		m := widget.NewPopUpMenu(fyne.NewMenu("", item), w.Canvas())
		m.Show()
	})))
	w.Resize(fyne.NewSize(600, 400))
	w.ShowAndRun()
}

Fyne version

2.5.4

Go compiler version

1.23.4

Operating system and version

Ubuntu 22.04

Additional Information

It looks like the bug is caused because Fyne always assuming the icon is a SVG image and tries to applies Disabled-theming to it:

menuItemRenderer.updateIcon()

This could be fixed by first checking if the icon really is a SVG image and leaving it alone if it is.

@ErikKalkoken ErikKalkoken added the unverified A bug that has been reported but not verified label Feb 26, 2025
ErikKalkoken added a commit to ErikKalkoken/fyne that referenced this issue Feb 26, 2025
@andydotxyz andydotxyz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels Feb 26, 2025
@andydotxyz andydotxyz added this to the "F" release, Early 2025 milestone Feb 26, 2025
@ErikKalkoken
Copy link
Contributor Author

Fix merged into develop: #5560

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

2 participants