Skip to content

Commit

Permalink
feat: 🎸 revert loaded theme (#104)
Browse files Browse the repository at this point in the history
* feat: 🎸 revert loaded theme

* chore: 🤖 upgrade uniffi-bindgen-cpp

* chore: 🤖 update ThorVG to v0.12.9
  • Loading branch information
theashraf authored Mar 22, 2024
1 parent 1c05a84 commit ff2d444
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .mac-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions demo-player/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Binary file modified demo-player/src/theming_example.lottie
Binary file not shown.
4 changes: 2 additions & 2 deletions dotlottie-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ 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"

[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"
4 changes: 4 additions & 0 deletions dotlottie-rs/src/dotlottie_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
17 changes: 10 additions & 7 deletions dotlottie-rs/src/thorvg.rs
Original file line number Diff line number Diff line change
@@ -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"));
Expand Down Expand Up @@ -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 {
Expand All @@ -89,7 +89,7 @@ impl Canvas {

Canvas {
raw_canvas: unsafe { tvg_swcanvas_create() },
engine_method: engine
engine_method: engine,
}
}

Expand Down Expand Up @@ -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")
}
}

Expand Down
18 changes: 9 additions & 9 deletions web-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<button id="play">play</button>
<button id="pause">pause</button>
<button id="resize">resize</button>
<select id="themeSelect">
<option>None</option>
<select id="theme-select">
<option value="">None</option>
<option value="theme">Theme</option>
</select>
<input
Expand Down Expand Up @@ -77,7 +77,7 @@
const bgColorInput = document.querySelector("#bg-color");
const fitSelect = document.querySelector("#fit");
const alignSelect = document.querySelector("#align");
const themeSelect = document.querySelector("select");
const themeSelect = document.querySelector("#theme-select");

const Module = await createDotLottiePlayerModule({
locateFile: (path, prefix) => {
Expand All @@ -88,7 +88,7 @@
},
});

function createSegments(startFrame, endFrame) {
function createSegment(startFrame, endFrame) {
const vector = new Module.VectorFloat();

if (typeof startFrame === "number" && typeof endFrame === "number") {
Expand Down Expand Up @@ -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(),
Expand All @@ -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());
Expand All @@ -155,7 +155,7 @@
dotLottiePlayer.setConfig({
...dotLottiePlayer.config(),
mode: Module.Mode.values[1],
segments: createSegments(),
segment: createSegment(),
});

console.log(dotLottiePlayer.markers());
Expand Down Expand Up @@ -336,7 +336,7 @@
themeSelect.addEventListener("change", (event) => {
const theme = event.target.value;

if (theme === "theme") {
if (theme) {
dotLottiePlayer.loadTheme(theme);
} else {
dotLottiePlayer.loadTheme("");
Expand Down

0 comments on commit ff2d444

Please sign in to comment.