pub struct AnimationEngine {
transitions: Vec<ActiveTransition>,
animations: Vec<ActiveAnimation>,
pub computed: Vec<(String, String, String)>,
pub lifecycle_events: Vec<(String, &'static str, String)>,
}Expand description
アニメーション/トランジションの集中管理。
Fields§
§transitions: Vec<ActiveTransition>§animations: Vec<ActiveAnimation>§computed: Vec<(String, String, String)>直近に算出した (element_id, property) → 値。レンダラが set_style に焼く。
lifecycle_events: Vec<(String, &'static str, String)>animationend/transitionend/animationstart(丸ごと未対応だった。
new AnimationEvent(...)/new TransitionEvent(...)コンストラクタ自体は
既に実装済みで、手動でのel.dispatchEvent(new AnimationEvent ('animationend', ...))は可能だったが、実際にCSSアニメーション/
トランジションが完了・開始した時に、このエンジン自身が自動でイベントを
発火する経路が丸ごと存在しなかった。tick()の呼び出し元
(web_engine/layout.rsのtick_animations。DOM/JSランタイムへのアクセス
権を持つ)がこのライフサイクルイベントリストを都度回収し、実際に
dispatch_event_withする。各要素は(element_id, event_type, name)
(nameはアニメーションならanimation-name、トランジションなら
プロパティ名)。animationiteration/transitionstart/transitionrun/
transitioncancel(反復・トランジション側の開始/中断系)は状態遷移の
追跡がより複雑になるため今回は対象外とし、定番の完了/開始検知パターンで
使われるanimationend/transitionend/animationstartの3つのみに絞った。
Implementations§
Source§impl AnimationEngine
impl AnimationEngine
pub fn new() -> Self
Sourcepub fn start_transition(
&mut self,
element_id: &str,
property: &str,
from: &str,
to: &str,
spec: TransitionSpec,
now_ms: f32,
)
pub fn start_transition( &mut self, element_id: &str, property: &str, from: &str, to: &str, spec: TransitionSpec, now_ms: f32, )
要素に transition が設定された状態で値が old→new に変化したら呼ぶ。
既存の同プロパティのトランジションは置き換える(再ターゲット)。
Sourcepub fn start_animation(
&mut self,
element_id: &str,
spec: AnimationSpec,
keyframes: Keyframes,
now_ms: f32,
)
pub fn start_animation( &mut self, element_id: &str, spec: AnimationSpec, keyframes: Keyframes, now_ms: f32, )
要素に animation が設定されたら呼ぶ。既存の同名アニメが既にある場合は
再登録せず、play_state(animation-play-state:paused のライブ切り替え、例えば
hover 等のクラストグルで実現する一般的なパターン)だけを更新する。以前は既存アニメを
完全にスキップしていたため、実行中アニメの play_state をあとから変更しても
一切反映されなかった。
Sourcepub fn cancel_for(&mut self, element_id: &str)
pub fn cancel_for(&mut self, element_id: &str)
指定要素のアニメ/トランジションを取り消す。
Sourcepub fn retain_animation_names(
&mut self,
element_id: &str,
current_names: &[String],
)
pub fn retain_animation_names( &mut self, element_id: &str, current_names: &[String], )
要素の animation-name(または animation ショートハンド)が変化した際、
現在指定されているアニメーション名の集合に無い、この要素の古いアニメーションを
取り消す。start_animation は「同一 (element, name) が既に存在すれば更新のみ」
という判定しかしないため、以前は animation-name を “fade” から “bounce” のような
別名へ切り替えても、古い “fade” のアニメーションが決して除去されず(特に
iterations: infinite の場合は自然完了もしないため)新旧2つのアニメーションが
永久に同時に走り続けてしまうバグがあった。
Trait Implementations§
Source§impl Clone for AnimationEngine
impl Clone for AnimationEngine
Source§fn clone(&self) -> AnimationEngine
fn clone(&self) -> AnimationEngine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more