Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(compositor): give text annotations a symmetric 300 ms exit
EtienneLescot9c1cb43a3ddd
diff --git a/crates/compositor/src/compositor_linux.rs b/crates/compositor/src/compositor_linux.rsindex 6a21037e7..94c768c9d 100644--- a/crates/compositor/src/compositor_linux.rs+++ b/crates/compositor/src/compositor_linux.rs@@ -2632,6 +2632,7 @@ impl Compositor {let anim = crate::text_anim::text_animation_state(text.animation.as_deref(),(g.source_t - a.start_sec as f32) * 1000.0,+ ((a.end_sec - a.start_sec) * 1000.0) as f32,);let anim_px = rh / crate::text_anim::ANIMATION_REFERENCE_HEIGHT;let (mut ax, mut ay, mut aw, mut ah) = (diff --git a/crates/compositor/src/compositor_macos.rs b/crates/compositor/src/compositor_macos.rsindex 0ec96124f..4b08767ef 100644--- a/crates/compositor/src/compositor_macos.rs+++ b/crates/compositor/src/compositor_macos.rs@@ -1519,6 +1519,7 @@ impl Compositor {let anim = crate::text_anim::text_animation_state(text.animation.as_deref(),(t - a.start_sec as f32) * 1000.0,+ ((a.end_sec - a.start_sec) * 1000.0) as f32,);let anim_px = rh / crate::text_anim::ANIMATION_REFERENCE_HEIGHT;let (mut ax, mut ay, mut aw, mut ah) = (diff --git a/crates/compositor/src/compositor_windows.rs b/crates/compositor/src/compositor_windows.rsindex f1a373e2b..6a0e22374 100644--- a/crates/compositor/src/compositor_windows.rs+++ b/crates/compositor/src/compositor_windows.rs@@ -2433,6 +2433,7 @@ impl Compositor {let anim = crate::text_anim::text_animation_state(text.animation.as_deref(),(t - annotation.start_sec as f32) * 1000.0,+ ((annotation.end_sec - annotation.start_sec) * 1000.0) as f32,);// Les décalages sont donnés à la hauteur de référence : on les ramène à la// sortie, comme la taille de police, pour que l'animation ait la mêmediff --git a/crates/compositor/src/text_anim.rs b/crates/compositor/src/text_anim.rsindex 6a30bd0a0..2da3f032d 100644--- a/crates/compositor/src/text_anim.rs+++ b/crates/compositor/src/text_anim.rs@@ -13,6 +13,10 @@ pub const ANIMATION_REFERENCE_HEIGHT: f32 = 1080.0;pub const TEXT_ANIMATION_DURATION_MS: f32 = 700.0;+/// Sortie automatique : la même courbe que l'entrée, jouée à rebours et plus vite. Sans elle, la+/// fin de l'annotation est une coupe sèche alors que son arrivée est animée.+pub const TEXT_EXIT_DURATION_MS: f32 = 300.0;+#[derive(Debug, Clone, Copy, PartialEq)]pub struct TextAnimationState {pub opacity: f32,@@ -45,13 +49,29 @@ fn ease_out_back(v: f32) -> f32 {1.0 + C3 * (t - 1.0).powi(3) + C1 * (t - 1.0).powi(2)}-/// État de l'animation `animation` après `elapsed_ms` depuis le début de l'annotation.-pub fn text_animation_state(animation: Option<&str>, elapsed_ms: f32) -> TextAnimationState {+/// État de l'animation `animation` après `elapsed_ms` depuis le début d'une annotation qui dure+/// `region_ms` au total.+///+/// L'entrée dure `TEXT_ANIMATION_DURATION_MS`, la sortie `TEXT_EXIT_DURATION_MS` et rejoue la même+/// courbe à rebours. Une région plus courte que les deux réunies partage son temps entre elles au+/// prorata : le texte atteint son état plein à la jonction au lieu d'être coupé en pleine entrée.+/// `pulse` est une emphase, pas une entrée : il n'a pas de sortie.+pub fn text_animation_state(+ animation: Option<&str>,+ elapsed_ms: f32,+ region_ms: f32,+) -> TextAnimationState {let name = animation.unwrap_or("none");if name == "none" {return TextAnimationState::IDLE;}- let progress = clamp01(elapsed_ms.max(0.0) / TEXT_ANIMATION_DURATION_MS);+ let region_ms = region_ms.max(0.0);+ let share = (region_ms / (TEXT_ANIMATION_DURATION_MS + TEXT_EXIT_DURATION_MS)).min(1.0);+ let ramp = |t: f32, len: f32| if len > 0.0 { clamp01(t / len) } else { 1.0 };+ let enter = ramp(elapsed_ms.max(0.0), TEXT_ANIMATION_DURATION_MS * share);+ let exit = ramp(region_ms - elapsed_ms, TEXT_EXIT_DURATION_MS * share);+ // Les deux rampes valent 1 à la jonction : prendre la plus petite suffit à les enchaîner.+ let progress = if name == "pulse" { enter } else { enter.min(exit) };let eased = ease_out_cubic(progress);match name {"fade" => TextAnimationState { opacity: eased, ..TextAnimationState::IDLE },@@ -85,25 +105,28 @@ pub fn text_animation_state(animation: Option<&str>, elapsed_ms: f32) -> TextAnimod tests {use super::*;+ /// Une région assez longue pour que ni l'entrée ni la sortie ne soient raccourcies.+ const LONG: f32 = 10_000.0;+#[test]fn no_animation_shows_the_text_as_is() {for at in [0.0, 350.0, 5000.0] {- assert_eq!(text_animation_state(None, at), TextAnimationState::IDLE);- assert_eq!(text_animation_state(Some("none"), at), TextAnimationState::IDLE);+ assert_eq!(text_animation_state(None, at, LONG), TextAnimationState::IDLE);+ assert_eq!(text_animation_state(Some("none"), at, LONG), TextAnimationState::IDLE);}}#[test]fn an_unknown_name_shows_the_text_rather_than_hiding_it() {// Le pire comportement serait une opacité 0 : l'annotation disparaîtrait sans explication.- assert_eq!(text_animation_state(Some("kenburns"), 0.0), TextAnimationState::IDLE);+ assert_eq!(text_animation_state(Some("kenburns"), 0.0, LONG), TextAnimationState::IDLE);}#[test]fn every_animation_settles_on_the_plain_text() {// Propriété qui compte le plus : passée la durée, aucune animation ne laisse de trace.for name in ["fade", "rise", "pop", "slide-left", "typewriter", "pulse"] {- let end = text_animation_state(Some(name), TEXT_ANIMATION_DURATION_MS + 1.0);+ let end = text_animation_state(Some(name), TEXT_ANIMATION_DURATION_MS + 1.0, LONG);assert!((end.opacity - 1.0).abs() < 1e-3, "{name} : opacité {}", end.opacity);assert!((end.scale - 1.0).abs() < 1e-3, "{name} : échelle {}", end.scale);assert!(end.translate_x.abs() < 1e-3 && end.translate_y.abs() < 1e-3, "{name} : décalé");@@ -113,9 +136,9 @@ mod tests {#[test]fn fade_and_rise_start_invisible_and_below() {- let fade = text_animation_state(Some("fade"), 0.0);+ let fade = text_animation_state(Some("fade"), 0.0, LONG);assert_eq!(fade.opacity, 0.0);- let rise = text_animation_state(Some("rise"), 0.0);+ let rise = text_animation_state(Some("rise"), 0.0, LONG);assert_eq!(rise.opacity, 0.0);assert!((rise.translate_y - 18.0).abs() < 1e-3, "part de 18px plus bas");}@@ -123,7 +146,7 @@ mod tests {#[test]fn slide_left_enters_from_the_right() {// Signe négatif = le texte commence décalé vers la gauche et revient, comme le TS.- let s = text_animation_state(Some("slide-left"), 0.0);+ let s = text_animation_state(Some("slide-left"), 0.0, LONG);assert!((s.translate_x + 28.0).abs() < 1e-3, "translate_x = {}", s.translate_x);}@@ -131,15 +154,15 @@ mod tests {fn pop_overshoots_then_comes_back() {// easeOutBack dépasse 1 avant de retomber : c'est ce qui donne le « pop ».let mid = (0..=100)- .map(|i| text_animation_state(Some("pop"), i as f32 * 7.0).scale)+ .map(|i| text_animation_state(Some("pop"), i as f32 * 7.0, LONG).scale).fold(0.0f32, f32::max);assert!(mid > 1.0, "aucun dépassement : échelle max {mid}");- assert!(text_animation_state(Some("pop"), 0.0).scale >= 0.72, "plancher du TS respecté");+ assert!(text_animation_state(Some("pop"), 0.0, LONG).scale >= 0.72, "plancher du TS respecté");}#[test]fn pulse_swells_in_the_middle_and_never_moves() {- let mid = text_animation_state(Some("pulse"), TEXT_ANIMATION_DURATION_MS * 0.5);+ let mid = text_animation_state(Some("pulse"), TEXT_ANIMATION_DURATION_MS * 0.5, LONG);assert!((mid.scale - 1.06).abs() < 1e-3, "échelle {}", mid.scale);assert_eq!(mid.opacity, 1.0);assert_eq!(mid.translate_x, 0.0);@@ -148,7 +171,7 @@ mod tests {#[test]fn typewriter_reveals_linearly_and_only_from_the_left() {for (at, expected) in [(0.0, 0.0), (175.0, 0.25), (350.0, 0.5), (700.0, 1.0)] {- let s = text_animation_state(Some("typewriter"), at);+ let s = text_animation_state(Some("typewriter"), at, LONG);assert!((s.reveal - expected).abs() < 1e-3, "à {at}ms : {}", s.reveal);// Le texte reste opaque : c'est la largeur qui se dévoile, pas l'alpha (l'aperçu DOM// faisait exactement ça avec un `inset()`).@@ -159,6 +182,54 @@ mod tests {#[test]fn a_negative_elapsed_time_is_the_start_not_the_end() {// Peut arriver d'une frame calculée juste avant le début de l'annotation.- assert_eq!(text_animation_state(Some("fade"), -50.0).opacity, 0.0);+ assert_eq!(text_animation_state(Some("fade"), -50.0, LONG).opacity, 0.0);+ }++ #[test]+ fn every_entrance_leaves_the_way_it_came() {+ // La sortie rejoue l'entrée à rebours : en fin de région, on retrouve l'état initial.+ for name in ["fade", "rise", "pop", "slide-left", "typewriter"] {+ let start = text_animation_state(Some(name), 0.0, LONG);+ let end = text_animation_state(Some(name), LONG, LONG);+ assert_eq!(start, end, "{name}");+ // Et à mi-sortie, on retrouve l'entrée au même avancement.+ let half_exit =+ text_animation_state(Some(name), LONG - TEXT_EXIT_DURATION_MS * 0.5, LONG);+ let half_enter =+ text_animation_state(Some(name), TEXT_ANIMATION_DURATION_MS * 0.5, LONG);+ assert_eq!(half_exit, half_enter, "{name}");+ }+ }++ #[test]+ fn the_exit_only_starts_in_the_last_300ms() {+ let before = text_animation_state(Some("fade"), LONG - TEXT_EXIT_DURATION_MS, LONG);+ assert_eq!(before, TextAnimationState::IDLE);+ let during = text_animation_state(Some("fade"), LONG - 100.0, LONG);+ assert!(during.opacity > 0.0 && during.opacity < 1.0, "opacité {}", during.opacity);+ }++ #[test]+ fn a_short_region_splits_its_time_between_entrance_and_exit() {+ // 500 ms < 700 + 300 : entrée 350 ms, sortie 150 ms, texte plein à la jonction.+ // Avant, la région s'arrêtait aux 5/7 de l'entrée : jamais pleinement visible.+ let region = 500.0;+ let at_join = text_animation_state(Some("fade"), 350.0, region);+ assert!((at_join.opacity - 1.0).abs() < 1e-3, "opacité {}", at_join.opacity);+ let rising = text_animation_state(Some("fade"), 175.0, region);+ let falling = text_animation_state(Some("fade"), 425.0, region);+ assert!((rising.opacity - falling.opacity).abs() < 1e-3, "{rising:?} / {falling:?}");+ assert_eq!(text_animation_state(Some("fade"), region, region).opacity, 0.0);+ }++ #[test]+ fn pulse_has_no_exit() {+ let s = text_animation_state(Some("pulse"), LONG - 10.0, LONG);+ assert_eq!(s, TextAnimationState::IDLE);+ }++ #[test]+ fn an_empty_region_does_not_divide_by_zero() {+ assert!(text_animation_state(Some("fade"), 0.0, 0.0).opacity.is_finite());}}