Skip to content

Some SVG resources don't update appearance correctly with the theme #3900

@dweymouth

Description

@dweymouth

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

I have some SVG resources that aren't displaying properly with the NewThemedResource wrapper. Rather than updating the fill color appropriately, it seems that the fill is becoming transparent and the SVG is not drawing at all. They draw normally without the themed resource wrapper but using the original fill color.

How to reproduce

run the example app and switch the OS theme from light to dark. observe that the Fyne app updates its theming but one button themes correctly and the other doesn't show its icon at all

Screenshots

Screen Shot 2023-05-20 at 10 23 37 AM Screen Shot 2023-05-20 at 10 23 54 AM

Example code

package main

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

var ResDiscSvg = &fyne.StaticResource{
	StaticName: "disc.svg",
	StaticContent: []byte(
		"<svg fill=\"#000000\" version=\"1.1\" id=\"Capa_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \r\n\t width=\"800px\" height=\"800px\" viewBox=\"0 0 547.74 547.74\"\r\n\t xml:space=\"preserve\">\r\n<g>\r\n\t<g>\r\n\t\t<path d=\"M273.87,547.74c151.256,0,273.87-122.617,273.87-273.87S425.126,0,273.87,0S0,122.617,0,273.87\r\n\t\t\tS122.614,547.74,273.87,547.74z M354.122,46.31c40.318,14.217,75.723,38.847,102.987,70.662L356.255,219.99\r\n\t\t\tc-9.939-15.166-23.954-27.421-40.487-35.208L354.122,46.31z M314.626,35.144l-11.539,143.704\r\n\t\t\tc-5.33-1.625-10.783-2.794-16.288-3.498L268.062,31.824C283.656,31.429,299.256,32.543,314.626,35.144z M273.87,228.735\r\n\t\t\tc24.927,0,45.135,20.208,45.135,45.135s-20.208,45.135-45.135,45.135s-45.135-20.208-45.135-45.135\r\n\t\t\tS248.943,228.735,273.87,228.735z M211.709,350.22c14.18,11.53,31.294,18.854,49.269,21.246l-49.177,135.519\r\n\t\t\tc-40.481-10.799-78.015-32.045-108.291-62.229L211.709,350.22z\"/>\r\n\t</g>\r\n</g>\r\n</svg>\r\n"),
}

var ResFilterSvg = &fyne.StaticResource{
	StaticName: "filter.svg",
	StaticContent: []byte(
		"<svg fill=\"#000000\" version=\"1.1\" id=\"Capa_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \r\n\t width=\"800px\" height=\"800px\" viewBox=\"0 0 971.986 971.986\"\r\n\t xml:space=\"preserve\">\r\n<g>\r\n\t<path d=\"M370.216,459.3c10.2,11.1,15.8,25.6,15.8,40.6v442c0,26.601,32.1,40.101,51.1,21.4l123.3-141.3\r\n\t\tc16.5-19.8,25.6-29.601,25.6-49.2V500c0-15,5.7-29.5,15.8-40.601L955.615,75.5c26.5-28.8,6.101-75.5-33.1-75.5h-873\r\n\t\tc-39.2,0-59.7,46.6-33.1,75.5L370.216,459.3z\"/>\r\n</g>\r\n</svg>\r\n"),
}

func main() {
	myApp := app.New()
	myWindow := myApp.NewWindow("Themed SVG bug")

	discSvg := theme.NewThemedResource(ResDiscSvg)
	filterSvg := theme.NewThemedResource(ResFilterSvg)

	content := container.New(layout.NewFormLayout(),
		widget.NewLabel("without themed wrapper"),
		container.NewHBox(
			widget.NewButtonWithIcon("", ResDiscSvg, nil),
			widget.NewButtonWithIcon("", ResFilterSvg, nil),
		),
		widget.NewLabel("with themed wrapper"),
		container.NewHBox(
			widget.NewButtonWithIcon("", discSvg, nil),
			widget.NewButtonWithIcon("", filterSvg, nil),
		),
	)
	myWindow.SetContent(content)
	myWindow.ShowAndRun()
}

Fyne version

2.3.4

Go compiler version

go1.19.4 darwin/amd64

Operating system and version

Mac OS

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions