Skip to main content

AnimationEngine

Struct AnimationEngine 

Source
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.rstick_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

Source

pub fn new() -> Self

Source

pub fn clear(&mut self)

すべての進行状態をクリア(ページ遷移時に呼ぶ)。

Source

pub fn is_active(&self) -> bool

進行中・予定のアニメーションが1つでもあるか(再描画要否の判定に使う)。

Source

pub fn start_transition( &mut self, element_id: &str, property: &str, from: &str, to: &str, spec: TransitionSpec, now_ms: f32, )

要素に transition が設定された状態で値が old→new に変化したら呼ぶ。 既存の同プロパティのトランジションは置き換える(再ターゲット)。

Source

pub fn start_animation( &mut self, element_id: &str, spec: AnimationSpec, keyframes: Keyframes, now_ms: f32, )

要素に animation が設定されたら呼ぶ。既存の同名アニメが既にある場合は 再登録せず、play_stateanimation-play-state:paused のライブ切り替え、例えば hover 等のクラストグルで実現する一般的なパターン)だけを更新する。以前は既存アニメを 完全にスキップしていたため、実行中アニメの play_state をあとから変更しても 一切反映されなかった。

Source

pub fn cancel_for(&mut self, element_id: &str)

指定要素のアニメ/トランジションを取り消す。

Source

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つのアニメーションが 永久に同時に走り続けてしまうバグがあった。

Source

pub fn tick(&mut self, now_ms: f32) -> bool

現在時刻で全アニメ/トランジションを評価し、computed を更新する。 戻り値: 進行中のものが残っているか(= 次フレームも再描画が要るか)。

Trait Implementations§

Source§

impl Clone for AnimationEngine

Source§

fn clone(&self) -> AnimationEngine

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AnimationEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AnimationEngine

Source§

fn default() -> AnimationEngine

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.