Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
13r0ck committed Mar 23, 2023
1 parent a27485c commit 2cdcc3f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
6 changes: 3 additions & 3 deletions examples/counter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ impl Application for Counter {
.height(100.),
)
.link(
keyframes::Container::new(Duration::from_secs(4))
keyframes::Container::new(Duration::from_secs(2))
.width(200.)
.height(300.)
.padding([0, 0, 0, 0]),
)
.link(
keyframes::Container::new(Duration::from_secs(6))
keyframes::Container::new(Duration::from_secs(2))
.width(700.)
.height(300.)
.padding([0, 0, 0, 500]),
)
.link(
keyframes::Container::new(Duration::from_secs(8))
keyframes::Container::new(Duration::from_secs(2))
.width(150.)
.height(150.)
.padding([0, 0, 0, 0]),
Expand Down
46 changes: 39 additions & 7 deletions src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,44 @@ impl Timeline {
pause
};

let mut converted_tracks = Vec::with_capacity(tracks.len());
let mut value_acc: Option<f32> = None;
let mut time_acc: Option<Instant> = None;
let mut i = 0;
while let Some(mut track) = tracks.pop() {
let converted_track: Vec<SubFrame> = track
.iter_mut()
.map(|frame| {
println!("value_acc:{value_acc:?}, time_acc:{time_acc:?}");
let subframe =
frame.to_subframe(value_acc, time_acc, now, i, &id, &self);
value_acc = Some(subframe.value);
time_acc = Some(subframe.at);
end = end.max(subframe.at);
println!(
"({i}): value:{} at:{:?}",
subframe.value, subframe.at
);
subframe
})
.collect();
converted_tracks.push(converted_track);

i += 1;
value_acc = None;
time_acc = None;
}
/*
let tracks: Vec<Vec<SubFrame>> = tracks
.iter_mut()
.inspect(|_| value_acc = None)
.inspect(|_| time_acc = None)
.enumerate()
.map(|(i, track)| {
track
.iter_mut()
.map(|frame| {
println!("value_acc:{value_acc:?}, time_acc:{time_acc:?}");
let subframe =
frame.to_subframe(value_acc, time_acc, now, i, &id, &self);
value_acc = Some(subframe.value);
Expand All @@ -372,9 +401,11 @@ impl Timeline {
.collect()
})
.collect();
*/

let meta = Meta::new(repeat, now, end, end - now, pause);
let _ = self.tracks.insert(id, (meta, tracks));
let _ = self.tracks.insert(id, (meta, converted_tracks));
println!("{:#?}", self.tracks);
}
Pending::Pause(id) => {
if let Some((meta, _track)) = self.tracks.get_mut(&id) {
Expand Down Expand Up @@ -424,27 +455,28 @@ impl Timeline {
let mut accumulator: Option<&SubFrame> = None;
loop {
match (accumulator, modifier_timeline.next()) {
// Found first element in timeline
(None, Some(modifier)) => {
// Found first element in timeline
accumulator = Some(modifier)
}
(None, None) => return None, // No elements in timeline
// No Elements in timeline
(None, None) => return None,
// Accumulator found in previous loop, but no greater value. Means animation duration has expired.
(Some(acc), None) => {
// Accumulator found in previous loop, but no greater value. Means animation duration has expired.
return Some(Interped {
previous: acc.value,
next: acc.value,
percent: 1.0,
value: acc.value,
});
}
// Found accumulator in middle-ish of timeline
(Some(acc), Some(modifier)) => {
// Found accumulator in middle-ish of timeline
// Can not interpolate between this one and next value?
if relative_now >= modifier.at || acc.value == modifier.value {
// Can not interpolate between this one and next value?
accumulator = Some(modifier);
// Can interpolate between these two, thus calculate and return that value.
} else {
// Can interpolate between these two, thus calculate and return that value.
let elapsed = relative_now.duration_since(acc.at).as_millis() as f32;
let duration = (modifier.at - acc.at).as_millis() as f32;

Expand Down

0 comments on commit 2cdcc3f

Please sign in to comment.