-
Notifications
You must be signed in to change notification settings - Fork 569
SVG widget #353
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
SVG widget #353
Conversation
Very cool! Initial thought is that for stuff that increases bloat but which not all clients will use, a feature flag is appropriate, though I'm sure we'll use this in Runebender. I would file an issue against clippy. It feels like making a recommendation which breaks the code should be considered a bug. In the meantime, of course suppress the warning. |
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.
Could this perhaps be a standalone crate that implements SVG drawing for piet, with an optional feature for a druid widget? I'd love to be able to easily pull in SVGs as part of more advanced custom rendering, which would be difficult to do when the logic's hardwired into a widget.
Happy to make a standalone crate if that's what people prefer. In the meantime I could refactor this so the hardworking svg-to-piet functions are available without using the widget? |
Sounds like a good idea to me! |
Turns out this specific borrow situation is a known problem with clippy: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return |
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.
Okay a few little observations but this is very cool!
I think everything is addressed. Only issue is that CI doesn't know about this feature flag. If it did it would notice those two (unrelated) clippy lints that show up when running with this flag. |
hmm, I guess we can't do |
I think it tries to run all the platform-specific stuff, so it has a ton of errors on my system. |
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 looks reasonable to me. We'll want to revisit at some point when we support other image types, but I think this is a great addition.
druid/src/widget/svg.rs
Outdated
phantom: Default::default(), | ||
}, | ||
Err(err) => { | ||
error!("{}", err); |
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 this is reasonable until we figure out a better error handling story. 🤷♀
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.
Is there a good reason not to return Result
?
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.
not a great reason, but my thinking right now is that no other widget constructors are failable, and it feels weird to start here.
My long-term vision for this is that you shouldn't be loading data directly from the file system; there should be a 'resource bundle' that druid exposes that contains various types of resources (image files, font files, localization files) and that is validated at compile time, so that at runtime getting a resource looks something like,
let my_svg: SvgData = env.get_bundle_resource(MY_SVG_IDENTIFIER);
or maybe even in a very fancy world there's a build phase that generates per-app marker 'keys' (like env::Key
) for each of the resources in this app's bundle?
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 can open an issue for this if you'd like?
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.
sure!
8af7d29
to
b29cb6a
Compare
this looks good to me. @Ralith this is blocked on your requested changes, so if you want to take another look then we can merge on your ✅ |
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.
Couple style nits, looks good otherwise!
} | ||
|
||
/// Measure the SVG's size | ||
#[allow(clippy::needless_return)] |
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.
Why not use conventional style here?
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.
The borrow checker disagrees with clippy on the "needless" aspect: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
Sad, but reasonable. I just wanted to note that PS: Fun fuct: I wrote cargo-bloat for resvg/usvg. |
I didn't mean this as a criticism of usvg! Just in comparison to the average PR. Thank you for making this widget so straightforward to implement! |
I was correct, this was a lot of fun. The downside: it's a bloat monster because I'm relying on
usvg
to parse and simplify the incoming SVG for me. So perhaps it should be behind a feature flag?One other caveat: clippy doesn't like the explicit
return
keyword inget_size()
, but if I don't do that then the borrow checker gets mad about how long the*root.borrow()
might live for.