From 524bc9f33c2f1db811dedea08cbc6870ae9d6260 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 9 Dec 2024 05:14:41 +0200 Subject: [PATCH] fix spinner widget for gtk replacement --- .../tab/item/page/content/status/loading.rs | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/app/browser/window/tab/item/page/content/status/loading.rs b/src/app/browser/window/tab/item/page/content/status/loading.rs index a6520748..99f455dd 100644 --- a/src/app/browser/window/tab/item/page/content/status/loading.rs +++ b/src/app/browser/window/tab/item/page/content/status/loading.rs @@ -6,32 +6,42 @@ use gtk::{ }; use std::time::Duration; -const SPINNER_SIZE: i32 = 64; // 16-64 +const SPINNER_SIZE: i32 = 32; // 16-64 const DEFAULT_TITLE: &str = "Loading.."; -/// Create new default `GObject` preset for loading +/// Create new default preset for loading /// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html) pub fn new_gobject(show_with_delay: Option) -> StatusPage { - let gobject = StatusPage::builder() - .child( - &Spinner::builder() - .width_request(SPINNER_SIZE) - .height_request(SPINNER_SIZE) - .build(), - ) + // Init spinner component + let spinner = Spinner::builder() + .width_request(SPINNER_SIZE) + .height_request(SPINNER_SIZE) + .build(); + + // Init main widget + let status_page = StatusPage::builder() + .child(&spinner) .title(DEFAULT_TITLE) .build(); - if let Some(duration) = show_with_delay { - gobject.set_visible(false); - timeout_add_local(duration, { - let this = gobject.clone(); - move || { - this.set_visible(true); - ControlFlow::Break - } - }); + // Apply optional delay + match show_with_delay { + Some(duration) => { + timeout_add_local(duration, { + let status_page = status_page.clone(); + move || { + status_page.set_visible(true); + spinner.start(); + ControlFlow::Break + } + }); + } + None => { + status_page.set_visible(true); + spinner.start(); + } } - gobject + // Done + status_page }