From fd6bfe91d67634c35bfb807ec540fcfca28dbca6 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Thu, 16 Mar 2023 13:38:43 +0000 Subject: [PATCH] Fix handling of interactivity (#295) * Fix handling of interactivity * Sort out silly mixup --- examples/headless/src/main.rs | 1 + examples/scenes/src/lib.rs | 4 ++++ examples/scenes/src/svg.rs | 8 ++++---- examples/with_winit/src/lib.rs | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/headless/src/main.rs b/examples/headless/src/main.rs index 0111909..93e3234 100644 --- a/examples/headless/src/main.rs +++ b/examples/headless/src/main.rs @@ -104,6 +104,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> { images: &mut images, resolution: None, base_color: None, + interactive: false, }; (example_scene.function)(&mut builder, &mut scene_params); let mut transform = Affine::IDENTITY; diff --git a/examples/scenes/src/lib.rs b/examples/scenes/src/lib.rs index a1bf160..c85573c 100644 --- a/examples/scenes/src/lib.rs +++ b/examples/scenes/src/lib.rs @@ -17,6 +17,10 @@ use vello::{kurbo::Vec2, peniko::Color, SceneBuilder}; pub struct SceneParams<'a> { pub time: f64, + /// Whether blocking should be limited + /// Will not change between runs + // TODO: Just never block/handle this automatically? + pub interactive: bool, pub text: &'a mut SimpleText, pub images: &'a mut ImageCache, pub resolution: Option, diff --git a/examples/scenes/src/svg.rs b/examples/scenes/src/svg.rs index d28c881..f896e89 100644 --- a/examples/scenes/src/svg.rs +++ b/examples/scenes/src/svg.rs @@ -114,14 +114,14 @@ pub fn svg_function_of>( params.resolution = Some(*resolution); return; } - #[cfg(target_arch = "wasm32")] - { + if cfg!(target_arch = "wasm32") || !params.interactive { let contents = contents.take().unwrap(); let contents = contents(); let (scene_frag, resolution) = render_svg_contents(&name, contents.as_ref()); builder.append(&scene_frag, None); params.resolution = Some(resolution); - cached_scene = Some((scene_frag, resolution)) + cached_scene = Some((scene_frag, resolution)); + return; } #[cfg(not(target_arch = "wasm32"))] { @@ -129,7 +129,7 @@ pub fn svg_function_of>( if !has_started_parse { has_started_parse = true; // Prefer jank over loading screen for first time - timeout = std::time::Duration::from_millis(400); + timeout = std::time::Duration::from_millis(75); let tx = tx.take().unwrap(); let contents = contents.take().unwrap(); let name = name.clone(); diff --git a/examples/with_winit/src/lib.rs b/examples/with_winit/src/lib.rs index 34606cc..380d40b 100644 --- a/examples/with_winit/src/lib.rs +++ b/examples/with_winit/src/lib.rs @@ -271,6 +271,7 @@ fn run( images: &mut images, resolution: None, base_color: None, + interactive: true, }; (example_scene.function)(&mut builder, &mut scene_params);