mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 12:41:30 +11:00
fix longstanding annoying in SceneBuilder ctor
SceneBuilder::new() now takes &mut Scene or &mut SceneFragment
This commit is contained in:
parent
016f9de05f
commit
37a9763748
|
@ -30,18 +30,30 @@ pub struct SceneBuilder<'a> {
|
||||||
impl<'a> SceneBuilder<'a> {
|
impl<'a> SceneBuilder<'a> {
|
||||||
/// Creates a new builder for filling a scene. Any current content in the scene
|
/// Creates a new builder for filling a scene. Any current content in the scene
|
||||||
/// will be cleared.
|
/// will be cleared.
|
||||||
|
#[deprecated = "use SceneBuilder::new() instead"]
|
||||||
pub fn for_scene(scene: &'a mut Scene) -> Self {
|
pub fn for_scene(scene: &'a mut Scene) -> Self {
|
||||||
Self::new(&mut scene.data, false)
|
Self::new_inner(&mut scene.data, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new builder for filling a scene fragment. Any current content in
|
/// Creates a new builder for filling a scene fragment. Any current content in
|
||||||
/// the fragment will be cleared.
|
/// the fragment will be cleared.
|
||||||
|
#[deprecated = "use SceneBuilder::new() instead"]
|
||||||
pub fn for_fragment(fragment: &'a mut SceneFragment) -> Self {
|
pub fn for_fragment(fragment: &'a mut SceneFragment) -> Self {
|
||||||
Self::new(&mut fragment.data, true)
|
Self::new_inner(&mut fragment.data, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new scene builder for a scene or scene fragment. Any content will be
|
||||||
|
/// cleared. The types accepted for the scene parameter are `&mut Scene` or
|
||||||
|
/// `&mut SceneFragment`.
|
||||||
|
pub fn new(scene: impl Into<AnyScene<'a>>) -> Self {
|
||||||
|
match scene.into() {
|
||||||
|
AnyScene::Scene(scene) => Self::new_inner(&mut scene.data, false),
|
||||||
|
AnyScene::Fragment(fragment) => Self::new_inner(&mut fragment.data, true),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new builder for constructing a scene.
|
/// Creates a new builder for constructing a scene.
|
||||||
fn new(scene: &'a mut SceneData, is_fragment: bool) -> Self {
|
fn new_inner(scene: &'a mut SceneData, is_fragment: bool) -> Self {
|
||||||
scene.reset(is_fragment);
|
scene.reset(is_fragment);
|
||||||
Self {
|
Self {
|
||||||
scene,
|
scene,
|
||||||
|
@ -276,6 +288,26 @@ impl<'a> SceneBuilder<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Helper for constructing a scene builder.
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub enum AnyScene<'a> {
|
||||||
|
Scene(&'a mut Scene),
|
||||||
|
Fragment(&'a mut SceneFragment),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&'a mut Scene> for AnyScene<'a> {
|
||||||
|
fn from(scene: &'a mut Scene) -> Self {
|
||||||
|
Self::Scene(scene)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&'a mut SceneFragment> for AnyScene<'a> {
|
||||||
|
fn from(scene: &'a mut SceneFragment) -> Self {
|
||||||
|
Self::Fragment(scene)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn encode_blend_mode(mode: BlendMode) -> u32 {
|
fn encode_blend_mode(mode: BlendMode) -> u32 {
|
||||||
(mode.mix as u32) << 8 | mode.compose as u32
|
(mode.mix as u32) << 8 | mode.compose as u32
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ async fn run() -> Result<()> {
|
||||||
current_frame += 1;
|
current_frame += 1;
|
||||||
let width = surface.config.width;
|
let width = surface.config.width;
|
||||||
let height = surface.config.height;
|
let height = surface.config.height;
|
||||||
let mut builder = SceneBuilder::for_scene(&mut scene);
|
let mut builder = SceneBuilder::new(&mut scene);
|
||||||
const N_SCENES: usize = 6;
|
const N_SCENES: usize = 6;
|
||||||
match scene_ix % N_SCENES {
|
match scene_ix % N_SCENES {
|
||||||
0 => test_scene::render_anim_frame(&mut builder, &mut simple_text, current_frame),
|
0 => test_scene::render_anim_frame(&mut builder, &mut simple_text, current_frame),
|
||||||
|
|
|
@ -265,7 +265,7 @@ fn render_blend_square(sb: &mut SceneBuilder, blend: BlendMode, transform: Affin
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
fn blend_square(blend: BlendMode) -> SceneFragment {
|
fn blend_square(blend: BlendMode) -> SceneFragment {
|
||||||
let mut fragment = SceneFragment::default();
|
let mut fragment = SceneFragment::default();
|
||||||
let mut sb = SceneBuilder::for_fragment(&mut fragment);
|
let mut sb = SceneBuilder::new(&mut fragment);
|
||||||
render_blend_square(&mut sb, blend, Affine::IDENTITY);
|
render_blend_square(&mut sb, blend, Affine::IDENTITY);
|
||||||
sb.finish();
|
sb.finish();
|
||||||
fragment
|
fragment
|
||||||
|
|
Loading…
Reference in a new issue