-
-
Notifications
You must be signed in to change notification settings - Fork 380
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
feat: Add fill attribute to image widget for custom/dynamic svg color #1146
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
breaks image functionality for this svg (the first one i tried) without even using the new attribute
the image disappears when using the new function, same behavior as a wrong path being supplied
NOTE: `:image-height` is ignored even if `:image-width` is declared, this is a default behavior of `set_size` method
d39e0ee
to
906497e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the fill logic should only be invoked if the attribute is set, otherwise defaulting to the already existing code seems like a better option for performance reasons
in order to achieve that, it might help to mark the attribute as optional instead of relying on a default value
also, don't forget to document everything ^^
Move svg_to_pixbuf functionality inside image widget block Preserve the aspect ratio if one of least image-width/image-height is defined Don't set default size
By the way, I forgot to mention that I previously made the mistake of defining image_height and instead I set image_width twice, which made me believe that set_size ignored the height value but that is not the case, and set_size is only work if both fields are greater than 0, so I added code to preserve the aspect ratio in case one of the two attributes is used. Sorry for the delay of this message, I've been busy |
That's the result with last code update Example (box
:orientation "v"
(image :fill "red" :image-height 36 :path "./src/rect.svg")
(image :image-height 36 :path "./src/rect.svg")
) Example 2 (box
:orientation "v"
(image :fill "red" :path "./src/rect.svg")
(image :path "./src/rect.svg")
)
<svg fill="blue" width="130" height="300" viewBox="0 0 130 300" xmlns="http://www.w3.org/2000/svg">
<rect width="130" height="300" x="0" y="0" rx="20" ry="20" />
</svg> |
the following code produces two differently sized icons, which shouldn't happen.
also, i've looked into the gtk docs for this now, using the pixbufloader is not necessary here since it's purpose is incremental loading, but we have the full data available when constructing it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code results in the same scaling behavior when using and not using the fill attribute.
it also allows for easier maintenance, should, for example, a preserve-aspect-ratio
property be added (which i might look into, since it seems to be rather easy judging from the gtk docs)
the second if's purpose is to decide how the pixbuf will be populated, which can be extended if needed, i've pulled it inside the first one since the first one decides whether to handle an animation or a static image.
since all data is known, we can, after altering the svg, directly load it from a memory stream, no need for the complicated incremental loader here.
also, if you think this suggestion is good, you can commit it directly from the github web interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
superseded by #1148 now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be closed now that #1148 has been merged
Description
Added fill attribute to image widget for custom/dynamic svg color.
Note
This option is only for svg images
Usage
Showcase
Additional Notes
Anything else you want to add, such as remaining questions or explanations.
Checklist
Please make sure you can check all the boxes that apply to this PR.
docs/content/main
directory has been adjusted to reflect my changes.cargo fmt
to automatically format all code before committing