mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
animate progress function on value changed only
This commit is contained in:
parent
0f5a990105
commit
323cb72a6f
1 changed files with 33 additions and 33 deletions
|
|
@ -61,43 +61,43 @@ impl Request {
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, progress_fraction: Option<f64>) {
|
pub fn update(&self, progress_fraction: Option<f64>) {
|
||||||
// Skip Non value
|
// Skip update animation for Non value
|
||||||
if let Some(value) = progress_fraction {
|
if let Some(value) = progress_fraction {
|
||||||
// Update shared fraction value for async progressbar animation
|
// Update shared fraction value for async progressbar function, animate on changed only
|
||||||
self.progress.fraction.replace(value);
|
if value != self.progress.fraction.replace(value) {
|
||||||
|
// Start new frame on previous process function completed (`source_id` changed to None)
|
||||||
|
// If previous process still active, we have just updated shared fraction value before, to use it inside the active process
|
||||||
|
if self.progress.source_id.borrow().is_none() {
|
||||||
|
// Start new animation frame iterator, update `source_id`
|
||||||
|
self.progress.source_id.replace(Some(timeout_add_local(
|
||||||
|
Duration::from_millis(PROGRESS_ANIMATION_TIME),
|
||||||
|
{
|
||||||
|
// Clone async pointers dependency
|
||||||
|
let widget = self.widget.clone();
|
||||||
|
let progress = self.progress.clone();
|
||||||
|
|
||||||
// Start new frame on previous process completed only (`source_id` is None)
|
// Frame
|
||||||
// If previous process still active, we have just updated shared fraction value before, to use it inside the active process
|
move || {
|
||||||
if self.progress.source_id.borrow().is_none() {
|
// Animate
|
||||||
// Start new animation frame iterator, update `source_id`
|
if *progress.fraction.borrow() > widget.progress_fraction() {
|
||||||
self.progress.source_id.replace(Some(timeout_add_local(
|
widget.set_progress_fraction(
|
||||||
Duration::from_millis(PROGRESS_ANIMATION_TIME),
|
// Currently, here is no outrange validation, seems that wrapper make this work @TODO
|
||||||
{
|
widget.progress_fraction() + PROGRESS_ANIMATION_STEP,
|
||||||
// Clone async pointers dependency
|
);
|
||||||
let widget = self.widget.clone();
|
return ControlFlow::Continue;
|
||||||
let progress = self.progress.clone();
|
}
|
||||||
|
// Deactivate
|
||||||
|
progress.source_id.replace(None);
|
||||||
|
|
||||||
// Frame
|
// Reset
|
||||||
move || {
|
widget.set_progress_fraction(0.0);
|
||||||
// Animate
|
|
||||||
if *progress.fraction.borrow() > widget.progress_fraction() {
|
// Stop iteration
|
||||||
widget.set_progress_fraction(
|
ControlFlow::Break
|
||||||
// Currently, here is no outrange validation, seems that wrapper make this work @TODO
|
|
||||||
widget.progress_fraction() + PROGRESS_ANIMATION_STEP,
|
|
||||||
);
|
|
||||||
return ControlFlow::Continue;
|
|
||||||
}
|
}
|
||||||
// Deactivate
|
},
|
||||||
progress.source_id.replace(None);
|
)));
|
||||||
|
}
|
||||||
// Reset
|
|
||||||
widget.set_progress_fraction(0.0);
|
|
||||||
|
|
||||||
// Stop iteration
|
|
||||||
ControlFlow::Break
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue