1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::collections::{HashMap, VecDeque};
use super::{Easing, Action, AnimationError};
use yoga::StyleUnit;

/// Task properties needed for active task
#[derive(Clone, Debug)]
pub struct TaskProperties {
    /// Started properties of transition
    pub started: HashMap<String, StyleUnit>,
    // Worked properties - for update properties
    pub worked: HashMap<String, StyleUnit>,
}

/// Task is named queue of linear actions - stored and runned in main `Animation` instance 
#[derive(Clone, Debug)]
pub struct Task {
    pub properties: TaskProperties, 
    pub queue: VecDeque<Action>,
    pub finished: bool,
}

/// Single interpolation task for transition an float value
#[derive(Clone, Debug)]
pub struct SingleTask {
    pub easing: Easing,
    pub finished: bool,
    pub duration: u32,
    pub elapsed: u32,
    pub target: f32, 
    pub start: f32,
}

impl Task {
    /// Tick for handle new value of transitions queue action and return finished status after iterate
    pub fn run(&mut self, delta_time: f32) -> Result<bool, AnimationError> {
        let mut pop_action = false;

        if let Some(task) = self.queue.front_mut() {
            if let Ok(status) = task.next(&mut self.properties, delta_time) {
                pop_action = status;
            }
        } else {
            self.finished = true;
            return Ok(true);
        }

        if pop_action {
            let finished = self.queue.pop_front().is_none();
            self.finished = finished;
            Ok(finished)
        } else {
            Ok(false)
        }
    }
}

impl SingleTask {
    /// Tick for run transition for value
    pub fn run(&mut self, delta_time: f32) -> Result<bool, AnimationError> {
        Ok(true)
    }
}