Fix handling of interactivity (#295)

* Fix handling of interactivity

* Sort out silly mixup
This commit is contained in:
Daniel McNab 2023-03-16 13:38:43 +00:00 committed by GitHub
parent c503973739
commit fd6bfe91d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 4 deletions

View file

@ -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;

View file

@ -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<Vec2>,

View file

@ -114,14 +114,14 @@ pub fn svg_function_of<R: AsRef<str>>(
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<R: AsRef<str>>(
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();

View file

@ -271,6 +271,7 @@ fn run(
images: &mut images,
resolution: None,
base_color: None,
interactive: true,
};
(example_scene.function)(&mut builder, &mut scene_params);