diff --git a/.mac-setup.sh b/.mac-setup.sh index 142f1cf3..269a1bc5 100755 --- a/.mac-setup.sh +++ b/.mac-setup.sh @@ -11,7 +11,7 @@ NC=$(tput sgr0) # Environment EMSDK_VERSION=${EMSDK_VERSION:-latest} -UNIFFI_BINDGEN_CPP_VERSION=${UNIFFI_BINDGEN_CPP_VERSION:-"v0.4.1+v0.25.0"} +UNIFFI_BINDGEN_CPP_VERSION=${UNIFFI_BINDGEN_CPP_VERSION:-"v0.4.2+v0.25.0"} die() { printf %s "${@+$@$'\n'}" 1>&2 ; exit 1; } diff --git a/Makefile b/Makefile index d9b6c099..67264ea3 100644 --- a/Makefile +++ b/Makefile @@ -98,7 +98,7 @@ EMSDK_VERSION := 3.1.51 EMSDK_ENV := emsdk_env.sh UNIFFI_BINDGEN_CPP := uniffi-bindgen-cpp -UNIFFI_BINDGEN_CPP_VERSION := v0.4.1+v0.25.0 +UNIFFI_BINDGEN_CPP_VERSION := v0.4.2+v0.25.0 WASM_MODULE := DotLottiePlayer diff --git a/demo-player/src/main.rs b/demo-player/src/main.rs index 2a9eb005..ae2145fb 100644 --- a/demo-player/src/main.rs +++ b/demo-player/src/main.rs @@ -230,6 +230,10 @@ fn main() { } } + if window.is_key_pressed(Key::Y, KeyRepeat::No) { + lottie_player.load_theme(""); + } + if window.is_key_pressed(Key::Right, KeyRepeat::No) { if let Some(manifest) = lottie_player.manifest() { println!("{:?}", i); diff --git a/demo-player/src/theming_example.lottie b/demo-player/src/theming_example.lottie index 44792e5a..deac8722 100644 Binary files a/demo-player/src/theming_example.lottie and b/demo-player/src/theming_example.lottie differ diff --git a/deps/modules/thorvg b/deps/modules/thorvg index 8545cf5a..afa6d849 160000 --- a/deps/modules/thorvg +++ b/deps/modules/thorvg @@ -1 +1 @@ -Subproject commit 8545cf5ab8632c1860aa09fe5732081415fd6f11 +Subproject commit afa6d8499bd49141d99d5e40a4620bd9f6bc0467 diff --git a/dotlottie-ffi/Cargo.toml b/dotlottie-ffi/Cargo.toml index 2501205c..33fcc666 100644 --- a/dotlottie-ffi/Cargo.toml +++ b/dotlottie-ffi/Cargo.toml @@ -22,7 +22,7 @@ path = "uniffi-bindgen.rs" [dependencies] # uncomment uniffi v0.25.3 when building with uniffi-cpp-bindgen targetting C++/WASM # uniffi = { version = "0.25.3", features = ["cli"] } -uniffi = { version = "0.26.0", features = ["cli"] } +uniffi = { version = "0.26.1", features = ["cli"] } dotlottie_player = { path = "../dotlottie-rs" } dotlottie_fms = { path = "../dotlottie-fms" } cfg-if = "1.0" @@ -30,5 +30,5 @@ cfg-if = "1.0" [build-dependencies] # uncomment uniffi v0.25.3 when building with uniffi-cpp-bindgen targetting C++/WASM # uniffi = { version = "0.25.3", features = ["build"] } -uniffi = { version = "0.26.0", features = ["build"] } +uniffi = { version = "0.26.1", features = ["build"] } lazy_static = "1.4" diff --git a/dotlottie-rs/src/dotlottie_player.rs b/dotlottie-rs/src/dotlottie_player.rs index a6d1b8d8..6c89fd28 100644 --- a/dotlottie-rs/src/dotlottie_player.rs +++ b/dotlottie-rs/src/dotlottie_player.rs @@ -710,6 +710,10 @@ impl DotLottieRuntime { } pub fn load_theme(&mut self, theme_id: &str) -> bool { + if theme_id.is_empty() { + return self.renderer.load_theme_data("").is_ok(); + } + self.manifest() .and_then(|manifest| manifest.themes) .map_or(false, |themes| { diff --git a/dotlottie-rs/src/thorvg.rs b/dotlottie-rs/src/thorvg.rs index 7927efec..11f15b24 100644 --- a/dotlottie-rs/src/thorvg.rs +++ b/dotlottie-rs/src/thorvg.rs @@ -1,7 +1,7 @@ #![allow(non_upper_case_globals)] #![allow(non_snake_case)] -use std::ffi::CString; +use std::{ffi::CString, ptr}; use thiserror::Error; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); @@ -71,7 +71,7 @@ pub trait Drawable { pub struct Canvas { raw_canvas: *mut Tvg_Canvas, - engine_method: Tvg_Engine + engine_method: Tvg_Engine, } impl Canvas { @@ -89,7 +89,7 @@ impl Canvas { Canvas { raw_canvas: unsafe { tvg_swcanvas_create() }, - engine_method: engine + engine_method: engine, } } @@ -274,11 +274,14 @@ impl Animation { } pub fn set_slots(&mut self, slots: &str) -> Result<(), TvgError> { - let slots = CString::new(slots).expect("Failed to create CString"); - - let result = unsafe { tvg_lottie_animation_override(self.raw_animation, slots.as_ptr()) }; + let result = if slots.is_empty() { + unsafe { tvg_lottie_animation_override(self.raw_animation, ptr::null()) } + } else { + let slots_cstr = CString::new(slots).expect("Failed to create CString"); + unsafe { tvg_lottie_animation_override(self.raw_animation, slots_cstr.as_ptr()) } + }; - convert_tvg_result(result, "tvg_animation_override") + convert_tvg_result(result, "tvg_lottie_animation_override") } } diff --git a/web-example.html b/web-example.html index 682e078d..815fcc20 100644 --- a/web-example.html +++ b/web-example.html @@ -36,8 +36,8 @@ - + { @@ -88,7 +88,7 @@ }, }); - function createSegments(startFrame, endFrame) { + function createSegment(startFrame, endFrame) { const vector = new Module.VectorFloat(); if (typeof startFrame === "number" && typeof endFrame === "number") { @@ -118,7 +118,7 @@ mode: Module.Mode.values[3], speed: 1, useFrameInterpolation: true, - segments: createSegments(0, 40), + segment: createSegment(0, 40), backgroundColor: 0, marker: "feather", layout: Module.createDefaultLayout(), @@ -129,8 +129,8 @@ // ); const data = await fetch( - "https://lottie.host/5c89381e-0d1a-4422-8247-f5b7e4b3c4e2/mqs5juC4PW.lottie" - // "./demo-player/src/theming_example.lottie", + // "https://lottie.host/5c89381e-0d1a-4422-8247-f5b7e4b3c4e2/mqs5juC4PW.lottie" + "./demo-player/src/theming_example.lottie" // "https://lottie.host/294b684d-d6b4-4116-ab35-85ef566d4379/VkGHcqcMUI.lottie", // "https://lottie.host/edff17eb-9a84-41f7-810a-22b94fbf9143/uYveqJ1Kqn.lottie" ).then((res) => res.arrayBuffer()); @@ -155,7 +155,7 @@ dotLottiePlayer.setConfig({ ...dotLottiePlayer.config(), mode: Module.Mode.values[1], - segments: createSegments(), + segment: createSegment(), }); console.log(dotLottiePlayer.markers()); @@ -336,7 +336,7 @@ themeSelect.addEventListener("change", (event) => { const theme = event.target.value; - if (theme === "theme") { + if (theme) { dotLottiePlayer.loadTheme(theme); } else { dotLottiePlayer.loadTheme("");