mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-05 16:04:15 +00:00
implement progress fraction update animation
This commit is contained in:
parent
814c513743
commit
f61b9e0c92
@ -1,11 +1,14 @@
|
|||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
glib::{GString, Uri, UriFlags},
|
glib::{timeout_add_local, ControlFlow, GString, Uri, UriFlags},
|
||||||
prelude::{ActionExt, EditableExt, EntryExt},
|
prelude::{ActionExt, EditableExt, EntryExt},
|
||||||
Entry,
|
Entry,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
const PROGRESS_ANIMATION_STEP: f64 = 0.2;
|
||||||
|
const PROGRESS_ANIMATION_TIME: u64 = 25;
|
||||||
|
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
widget: Entry,
|
widget: Entry,
|
||||||
@ -15,6 +18,7 @@ impl Request {
|
|||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new(
|
||||||
text: Option<GString>,
|
text: Option<GString>,
|
||||||
|
// Actions
|
||||||
action_update: Arc<SimpleAction>,
|
action_update: Arc<SimpleAction>,
|
||||||
action_tab_page_reload: Arc<SimpleAction>,
|
action_tab_page_reload: Arc<SimpleAction>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -45,8 +49,21 @@ impl Request {
|
|||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, progress_fraction: f64) {
|
pub fn update(&self, progress_fraction: f64) {
|
||||||
self.widget.set_progress_fraction(progress_fraction);
|
// Animate progress fraction update
|
||||||
// @TODO animate progress fraction
|
timeout_add_local(Duration::from_millis(PROGRESS_ANIMATION_TIME), {
|
||||||
|
let widget = self.widget.clone();
|
||||||
|
move || {
|
||||||
|
if progress_fraction > widget.progress_fraction() {
|
||||||
|
widget.set_progress_fraction(
|
||||||
|
widget.progress_fraction() + PROGRESS_ANIMATION_STEP,
|
||||||
|
);
|
||||||
|
return ControlFlow::Continue;
|
||||||
|
} else {
|
||||||
|
widget.set_progress_fraction(progress_fraction);
|
||||||
|
}
|
||||||
|
ControlFlow::Break
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
|
Loading…
x
Reference in New Issue
Block a user