From f61b9e0c92f0c1c56035f3309ce8d6f90242c67c Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 29 Sep 2024 03:21:04 +0300 Subject: [PATCH] implement progress fraction update animation --- .../main/tab/page/navigation/request.rs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/browser/main/tab/page/navigation/request.rs b/src/browser/main/tab/page/navigation/request.rs index 3d7402b0..8b40cbac 100644 --- a/src/browser/main/tab/page/navigation/request.rs +++ b/src/browser/main/tab/page/navigation/request.rs @@ -1,11 +1,14 @@ use gtk::{ gio::SimpleAction, - glib::{GString, Uri, UriFlags}, + glib::{timeout_add_local, ControlFlow, GString, Uri, UriFlags}, prelude::{ActionExt, EditableExt, EntryExt}, 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 { widget: Entry, @@ -15,6 +18,7 @@ impl Request { // Construct pub fn new( text: Option, + // Actions action_update: Arc, action_tab_page_reload: Arc, ) -> Self { @@ -45,8 +49,21 @@ impl Request { // Actions pub fn update(&self, progress_fraction: f64) { - self.widget.set_progress_fraction(progress_fraction); - // @TODO animate progress fraction + // Animate progress fraction update + 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