-
Notifications
You must be signed in to change notification settings - Fork 211
Add kurbo conversions to scene API #171
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
Changes from 4 commits
94f7b51
e600bdb
a20dd43
7f37355
938d6fc
39b773c
d30750e
5252a33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,11 +23,13 @@ pub use builder::{build_fragment, build_scene, Builder}; | |
| pub use style::*; | ||
|
|
||
| use super::brush::*; | ||
| use super::geometry::{Affine, Point, Rect}; | ||
| use super::geometry::{Affine, Point}; | ||
| use super::path::Element; | ||
| use super::resource::ResourceContext; | ||
|
|
||
| use core::ops::Range; | ||
|
|
||
| /// Raw data streams describing an encoded scene. | ||
| #[derive(Default)] | ||
| pub struct SceneData { | ||
| pub transform_stream: Vec<Affine>, | ||
|
|
@@ -83,6 +85,13 @@ pub struct Scene { | |
| } | ||
|
|
||
| impl Scene { | ||
| /// Creates a new builder for filling the scene. Any current content in | ||
| /// the scene is cleared. | ||
| pub fn build<'a>(&'a mut self, rcx: &'a mut ResourceContext) -> Builder<'a> { | ||
|
||
| build_scene(self, rcx) | ||
| } | ||
|
|
||
| /// Returns the raw encoded scene data streams. | ||
| pub fn data(&self) -> &SceneData { | ||
| &self.data | ||
| } | ||
|
|
@@ -96,9 +105,17 @@ pub struct Fragment { | |
| } | ||
|
|
||
| impl Fragment { | ||
| /// Returns the underlying stream of points that defined all encoded path | ||
| /// segments. | ||
| pub fn points(&self) -> &[Point] { | ||
| bytemuck::cast_slice(&self.data.pathseg_stream) | ||
| } | ||
|
|
||
| /// Creates a new builder for filling the fragment. Any current content in | ||
| /// the fragment is cleared. | ||
| pub fn build<'a>(&'a mut self) -> Builder<'a> { | ||
| build_fragment(self) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
|
|
||
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 is ergonomic but doesn't exactly follow Rust conventions - usually
Fromis for lossless conversions, so there's f32->f64 but not the other way around. There was a proposal for a standard lossy conversion trait but I'm not sure it went anywhere. I think this is good enough for now but want to check with a Rust expert to see if there is a better pattern. In any case, we can change it later.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.
Good point. If you'd feel better with explicit to_kurbo/from_kurbo methods, I actually don't mind going that direction. I found that
impl Intoin the builder interface isn't all that useful anyway due to these types being mostly buried in options and iterators.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 ->kurbo direction is fine. If "into" is not actually a big ergonomic win in practice then I think having an explicit method is a better choice.
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.
Removed the
Fromimpls and replaced them withfrom_kurbomethods for the lossy conversions.