-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Some SVG resources don't update appearance correctly with the theme #3900
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
Comments
I have the same bug with some SVGs (in addition to the non-correctly displayed at all SVGs...), and I noticed that svg with grayish stroke are OK, while black stroke no. I don't know what does that mean though... Zero experience with SVG |
me too |
It would be helpful if you can provide more data, such as the icon you are trying to use. "Me too" doesn't help us fix the issue. |
Only use theme.xxxIcon() to correspond to the theme![]() is code demopackage main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("ico.demo")
// me diy
diySvgToContent := `<svg viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 24C4 35.0457 12.9543 44 24 44V44C35.0457 44 44 35.0457 44 24C44 12.9543 35.0457 4 24 4" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M36 24C36 17.3726 30.6274 12 24 12C17.3726 12 12 17.3726 12 24C12 30.6274 17.3726 36 24 36V36" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>`
diySvgToResource := fyne.NewStaticResource("logo.svg", []byte(diySvgToContent))
// copy fyne's home.svg filepath'code to svgContentToFyne : /gopath/pkg/mod/fyne.io/fyne/[email protected]/theme/icons/home.svg
fyneSvgToContent := `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/><path d="M0 0h24v24H0z" fill="none"/></svg>`
fyneSvgToResource := fyne.NewStaticResource("home.svg", []byte(fyneSvgToContent))
//
a := widget.NewButtonWithIcon("diySvg", diySvgToResource, nil)
b := widget.NewButtonWithIcon("fyne's Icon", theme.DownloadIcon(), nil)
c := widget.NewButtonWithIcon("fyne's Svg", fyneSvgToResource, nil)
//
layouta := container.NewHBox(a, b, c)
layout := container.NewVBox(layouta)
myWindow.SetContent(layout)
myWindow.Resize(fyne.NewSize(600, 400))
myWindow.ShowAndRun()
} |
I found a solution use "theme.NewThemedResource()" but only fyne's svg c := widget.NewButtonWithIcon("fyne's Svg", theme.NewThemedResource(fyneSvgToResource), nil) |
That is how it is supposed to work, with ThemedResource. |
In other words, fyne's icon is acceptable, but user-defined icons are not. The requirement is that user-defined icons must have the same effect to solve the problem. |
Try how to make the icon here also successful |
i found a problem stroke="#333" To "stroke="#fff"" will default to white diySvgToContent := `<svg viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4 24C4 35.0457 12.9543 44 24 44V44C35.0457 44 44 35.0457 44 24C44 12.9543 35.0457 4 24 4" stroke="#fff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M36 24C36 17.3726 30.6274 12 24 12C17.3726 12 12 17.3726 12 24C12 30.6274 17.3726 36 24 36V36" stroke="#fff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
</svg>` Explain that fyne's theme tool does not uniformly process the color of svg |
It seems that the way to deal with custom svg colors here needs to be adjusted. User-defined svg is not in the fyne framework, which is special// Name returns the underlying resource name (used for caching).
func (res *ThemedResource) Name() string {
prefix := res.ColorName
if prefix == "" {
prefix = "foreground_"
} else {
prefix += "_"
}
return string(prefix) + res.source.Name()
}
// Content returns the underlying content of the resource adapted to the current text color.
func (res *ThemedResource) Content() []byte {
name := res.ColorName
if name == "" {
name = ColorNameForeground
}
return svg.Colorize(res.source.Content(), safeColorLookup(name, currentVariant()))
} |
No, this is incorrect and unhelpful. You will see many apps that use custom icons and they theme correctly. It has been extensively tested with the extended material design icon set. |
I found 2 very similar icons from google's material icons set, one works well, the other is not even displayed Good Bad |
I cannot replicate with simple icon load. It seems like this relates to the themed resource code not the SVG loader. |
Fixed on develop for next release |
What if you remove the CSS (which we don't support)? |
Pretty sure it was the CSS was the issue as I haven't seen this repro with any other icons |
Another case of incorrect SVG behaviour. var resourceGameIconSvg = &fyne.StaticResource{
StaticName: "GameIcon.svg",
StaticContent: []byte(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<svg\n version=\"1.1\"\n width=\"32\"\n height=\"16\"\n viewBox=\"0 0 32 16\"\n xml:space=\"preserve\"\n id=\"svg9\"\n sodipodi:docname=\"Game Icon - test.svg\"\n inkscape:version=\"1.3.2 (091e20ef0f, 2023-11-25)\"\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\"><sodipodi:namedview\n id=\"namedview9\"\n pagecolor=\"#ffffff\"\n bordercolor=\"#000000\"\n borderopacity=\"0.25\"\n inkscape:showpageshadow=\"2\"\n inkscape:pageopacity=\"0.0\"\n inkscape:pagecheckerboard=\"true\"\n inkscape:deskcolor=\"#d1d1d1\"\n inkscape:zoom=\"42.90625\"\n inkscape:cx=\"16.011653\"\n inkscape:cy=\"7.6212673\"\n inkscape:window-width=\"1920\"\n inkscape:window-height=\"1020\"\n inkscape:window-x=\"0\"\n inkscape:window-y=\"0\"\n inkscape:window-maximized=\"1\"\n inkscape:current-layer=\"svg9\" />\n<desc\n id=\"desc1\">Created with Fabric.js 5.3.0</desc>\n<defs\n id=\"defs1\">\n</defs>\n<path\n id=\"path1\"\n style=\"stroke:rgb(71, 194, 187);stroke-width:0;stroke-dasharray:none;stroke-linecap:butt;stroke-dashoffset:0;stroke-linejoin:miter;stroke-miterlimit:4;fill:rgb(0, 0, 0);fill-rule:nonzero;opacity:1\"\n inkscape:label=\"Controller Body\"\n d=\"M -1.7416139 -1.7419103 C -2.3825695 -1.7419103 -2.9027694 -0.96161059 -2.9027694 -0.00017722134 C -2.9027694 0.96125615 -2.3825695 1.7415558 -1.7416139 1.7415558 L 1.7418524 1.7415558 C 2.3828081 1.7415558 2.9030079 0.96125615 2.9030079 -0.00017722134 C 2.9030079 -0.96161059 2.3828081 -1.7419103 1.7418524 -1.7419103 L -1.7416139 -1.7419103 z M -1.5545137 -1.306477 L -1.0597375 -1.306477 C -1.0359914 -1.306477 -1.0166477 -1.2774639 -1.0166477 -1.2418424 L -1.0166477 -0.43561048 L -0.47915977 -0.43561048 C -0.45541202 -0.43561048 -0.43607002 -0.4065949 -0.43607002 -0.37097586 L -0.43607002 0.37118838 C -0.43607002 0.40680746 -0.45541202 0.43525604 -0.47915977 0.43525604 L -1.0166477 0.43525604 L -1.0166477 1.2420549 C -1.0166477 1.2776765 -1.0359914 1.3061226 -1.0597375 1.3061226 L -1.5545137 1.3061226 C -1.5782598 1.3061226 -1.5972255 1.2776765 -1.5972255 1.2420549 L -1.5972255 0.43525604 L -2.1350914 0.43525604 C -2.1588391 0.43525604 -2.1778032 0.40680746 -2.1778032 0.37118838 L -2.1778032 -0.37097586 C -2.1778032 -0.4065949 -2.1588391 -0.43561048 -2.1350914 -0.43561048 L -1.5972255 -0.43561048 L -1.5972255 -1.2418424 C -1.5972255 -1.2774639 -1.5782598 -1.306477 -1.5545137 -1.306477 z M 1.4515635 -1.306477 C 1.611802 -1.306477 1.7418524 -1.1114013 1.7418524 -0.87104374 C 1.7418524 -0.63068614 1.611802 -0.43561048 1.4515635 -0.43561048 C 1.2913251 -0.43561048 1.1612747 -0.63068614 1.1612747 -0.87104374 C 1.1612747 -1.1114013 1.2913251 -1.306477 1.4515635 -1.306477 z M 0.87098582 -0.43561048 C 1.0312242 -0.43561048 1.1612747 -0.24053483 1.1612747 -0.00017722134 C 1.1612747 0.24018039 1.0312242 0.43525604 0.87098582 0.43525604 C 0.71074741 0.43525604 0.58069696 0.24018039 0.58069696 -0.00017722134 C 0.58069696 -0.24053483 0.71074741 -0.43561048 0.87098582 -0.43561048 z M 2.0321413 -0.43561048 C 2.1923797 -0.43561048 2.3224301 -0.24053483 2.3224301 -0.00017722134 C 2.3224301 0.24018039 2.1923797 0.43525604 2.0321413 0.43525604 C 1.8719029 0.43525604 1.7418524 0.24018039 1.7418524 -0.00017722134 C 1.7418524 -0.24053483 1.8719029 -0.43561048 2.0321413 -0.43561048 z M 1.4515635 0.43525604 C 1.611802 0.43525604 1.7418524 0.63033172 1.7418524 0.8706893 C 1.7418524 1.1110469 1.611802 1.3061226 1.4515635 1.3061226 C 1.2913251 1.3061226 1.1612747 1.1110469 1.1612747 0.8706893 C 1.1612747 0.63033172 1.2913251 0.43525604 1.4515635 0.43525604 z \"\n transform=\"matrix(5.1672668,0,0,3.4448448,15.751337,7.742798)\" />\n\n\n\n\n\n\n\n\n</svg>\n"),
} Location of source svg: https://github.com/rad756/PlayLog/blob/main/Icons/GameIcon.svg How SVG was created: |
Another example of a SVG that triggers the bug (from #4712):
|
While building a Material Design Icon viewer using Fyne I ran into the same issue with all 7447 icons. None of them have CSS or other weird stuff in them. Example:
Loading them with package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
func main() {
a := app.New()
w := a.NewWindow("Hello themed SVG issue")
r := &fyne.StaticResource{
StaticName: "headphones.svg",
StaticContent: []byte(`<svg xmlns="http://www.w3.org/2000/svg" id="mdi-headphones" viewBox="0 0 24 24"><path d="M12,1C7,1 3,5 3,10V17A3,3 0 0,0 6,20H9V12H5V10A7,7 0 0,1 12,3A7,7 0 0,1 19,10V12H15V20H18A3,3 0 0,0 21,17V10C21,5 16.97,1 12,1Z" /></svg>`),
}
w.SetContent(container.NewHBox(
widget.NewIcon(r),
widget.NewIcon(theme.NewThemedResource(r)),
))
w.ShowAndRun()
} The weird thing is that in another project I am using some of the same material design icons in a bundle I created, using |
After my comment I started comparing the example SVG with how the SVGs in my other project look like, and I could make it work by adding width and height parameters to the above example. Hope that helps. |
Thanks. Yes it seems that the library we use cannot find a sensible default for the width/height parameters if they are omitted. |
Thanks @sdassow for the additional fix - according to my testing this is now resolved in |
Checklist
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
Example code
Fyne version
2.3.4
Go compiler version
go1.19.4 darwin/amd64
Operating system and version
Mac OS
Additional Information
No response
The text was updated successfully, but these errors were encountered: