Skip to content

Commit

Permalink
Impl From<Encoding> for Scene.
Browse files Browse the repository at this point in the history
This allows creating a `Scene` with a pre-existing `Encoding`.

Fixes #530.
  • Loading branch information
waywardmonkeys committed Mar 31, 2024
1 parent 45bc031 commit 73abc10
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ use vello_encoding::{Encoding, Glyph, GlyphRun, Patch, Transform};

/// The main datatype for rendering graphics.
///
/// A Scene stores a sequence of drawing commands, their context, and the
/// A `Scene` stores a sequence of drawing commands, their context, and the
/// associated resources, which can later be rendered.
///
/// A `Scene` can be created in a default (empty) state via `Scene::new()`
/// or via `Default`. It can also be created from a pre-existing [`Encoding`]
/// using `From`.
#[derive(Clone, Default)]
pub struct Scene {
encoding: Encoding,
Expand Down Expand Up @@ -219,6 +223,17 @@ impl Scene {
}
}

impl From<Encoding> for Scene {
fn from(encoding: Encoding) -> Self {
// TODO: Properly update the estimator for the encoding.
Self {
encoding,
#[cfg(feature = "bump_estimate")]
estimator: vello_encoding::BumpEstimator::default(),
}
}
}

/// Builder for encoding a glyph run.
pub struct DrawGlyphs<'a> {
encoding: &'a mut Encoding,
Expand Down

0 comments on commit 73abc10

Please sign in to comment.