Skip to content

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

Merged
merged 10 commits into from
Dec 12, 2019
Merged

SVG widget #353

merged 10 commits into from
Dec 12, 2019

Conversation

futurepaul
Copy link
Collaborator

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 in get_size(), but if I don't do that then the borrow checker gets mad about how long the *root.borrow() might live for.

@raphlinus
Copy link
Contributor

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.

Copy link
Collaborator

@Ralith Ralith left a 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.

@futurepaul
Copy link
Collaborator Author

Could this perhaps be a standalone crate that implements SVG drawing for piet

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?

@Ralith
Copy link
Collaborator

Ralith commented Nov 30, 2019

Sounds like a good idea to me!

@futurepaul
Copy link
Collaborator Author

Turns out this specific borrow situation is a known problem with clippy: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

Copy link
Member

@cmyr cmyr left a 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!

@futurepaul
Copy link
Collaborator Author

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.

@cmyr
Copy link
Member

cmyr commented Dec 3, 2019

hmm, I guess we can't do cargo test --all-features?

@futurepaul
Copy link
Collaborator Author

I think it tries to run all the platform-specific stuff, so it has a ton of errors on my system.

Copy link
Member

@cmyr cmyr left a 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.

phantom: Default::default(),
},
Err(err) => {
error!("{}", err);
Copy link
Member

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. 🤷‍♀

Copy link
Collaborator

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?

Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

@cmyr
Copy link
Member

cmyr commented Dec 12, 2019

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 ✅

Copy link
Collaborator

@Ralith Ralith left a 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)]
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

@futurepaul futurepaul merged commit cbf377b into linebender:master Dec 12, 2019
@RazrFalcon
Copy link

RazrFalcon commented Dec 31, 2019

The downside: it's a bloat monster because I'm relying on usvg

Sad, but reasonable. I just wanted to note that usvg is absolutely stripped down. There are nothing to remove. The bloat comes mainly from harfbuzz bindings and there is nothing I can do about it. SVG is hard, text is hard.

PS: Fun fuct: I wrote cargo-bloat for resvg/usvg.

@futurepaul
Copy link
Collaborator Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants