summaryrefslogtreecommitdiff
path: root/rust/crates/animation/src/values.rs
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-07-28 20:14:51 +0200
committercashmere <cashmere@autistici.org>2026-07-28 20:14:51 +0200
commit32438ce25f69de99d2523b98237f62cfa90890d7 (patch)
tree3a712c347dec0889bdea3328b4c817c2d9392b27 /rust/crates/animation/src/values.rs
parentf5a82152394fde4d8f740f664ab7737b82861618 (diff)
downloadopencut-32438ce25f69de99d2523b98237f62cfa90890d7.tar.gz
feat: port domain crates to Rust (session 1 complete)
All green: cargo test --workspace (~300 tests, 0 failures). - timeline (45): placement, resize/ripple, split, snap, retime, audio separation, scene helpers - animation (73): bezier solver, channel sampling, keyframe ops, split/clamp/clone, param definitions - commands (9): Command trait, BatchCommand, history, 19 concrete commands, freeze-frame port 1:1 - audio (22): audible collection, range mixing, mastering limiter, rms/peak buckets - text (19): cosmic-text layout/measure/raster, backgrounds, decorations - graphics (52): full CSS gradient parser, tiny-skia raster, 4 shape definitions - effect-defs (16): blur definition, registry, pass resolution - mask-defs (19): all 9 mask renderers via tiny-skia - renderer (6): node model + scene builder port - desktop: GPUI projects screen wired to ProjectStore - scene: factory (web defaults: v32, Main Track, 1920x1080, 30fps)
Diffstat (limited to 'rust/crates/animation/src/values.rs')
-rw-r--r--rust/crates/animation/src/values.rs89
1 files changed, 89 insertions, 0 deletions
diff --git a/rust/crates/animation/src/values.rs b/rust/crates/animation/src/values.rs
new file mode 100644
index 00000000..d16bf16a
--- /dev/null
+++ b/rust/crates/animation/src/values.rs
@@ -0,0 +1,89 @@
+use scene::ElementAnimations;
+use time::MediaTime;
+
+use crate::resolve::resolve_animation_path_value_at_time;
+use scene::ParamValue;
+
+pub fn resolve_opacity_at_time(
+ base_opacity: f64,
+ animations: Option<&ElementAnimations>,
+ local_time: MediaTime,
+) -> f64 {
+ match resolve_animation_path_value_at_time(
+ animations,
+ "opacity",
+ local_time.max(MediaTime::ZERO),
+ &ParamValue::Number(base_opacity),
+ ) {
+ ParamValue::Number(value) => value,
+ _ => base_opacity,
+ }
+}
+
+pub fn resolve_number_at_time(
+ base_value: f64,
+ animations: Option<&ElementAnimations>,
+ property_path: &str,
+ local_time: MediaTime,
+) -> f64 {
+ match resolve_animation_path_value_at_time(
+ animations,
+ property_path,
+ local_time.max(MediaTime::ZERO),
+ &ParamValue::Number(base_value),
+ ) {
+ ParamValue::Number(value) => value,
+ _ => base_value,
+ }
+}
+
+pub fn resolve_color_at_time(
+ base_color: &str,
+ animations: Option<&ElementAnimations>,
+ property_path: &str,
+ local_time: MediaTime,
+) -> String {
+ match resolve_animation_path_value_at_time(
+ animations,
+ property_path,
+ local_time.max(MediaTime::ZERO),
+ &ParamValue::String(base_color.to_string()),
+ ) {
+ ParamValue::String(value) => value,
+ _ => base_color.to_string(),
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use scene::{AnimationChannel, ChannelData, ScalarAnimationKey, ScalarChannel, ScalarSegmentType, TangentMode};
+ use std::collections::BTreeMap;
+
+ #[test]
+ fn resolves_opacity_with_animation_and_fallback() {
+ let channel = AnimationChannel::Scalar(ScalarChannel {
+ keys: vec![ScalarAnimationKey {
+ id: "a".to_string(),
+ time: MediaTime::from_ticks(0),
+ value: 0.25,
+ left_handle: None,
+ right_handle: None,
+ segment_to_next: ScalarSegmentType::Linear,
+ tangent_mode: TangentMode::Flat,
+ }],
+ extrapolation: None,
+ });
+ let mut animations: ElementAnimations = BTreeMap::new();
+ animations.insert("opacity".to_string(), ChannelData::Single(channel));
+ assert_eq!(
+ resolve_opacity_at_time(1.0, Some(&animations), MediaTime::from_ticks(0)),
+ 0.25
+ );
+ assert_eq!(
+ resolve_opacity_at_time(1.0, Some(&animations), MediaTime::from_ticks(-5)),
+ 0.25
+ );
+ assert_eq!(resolve_opacity_at_time(1.0, None, MediaTime::from_ticks(0)), 1.0);
+ }
+}