fix spinner widget for gtk replacement

This commit is contained in:
yggverse 2024-12-09 05:14:41 +02:00
parent fff97d3cc0
commit 524bc9f33c

View File

@ -6,32 +6,42 @@ use gtk::{
}; };
use std::time::Duration; use std::time::Duration;
const SPINNER_SIZE: i32 = 64; // 16-64 const SPINNER_SIZE: i32 = 32; // 16-64
const DEFAULT_TITLE: &str = "Loading.."; 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) /// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
pub fn new_gobject(show_with_delay: Option<Duration>) -> StatusPage { pub fn new_gobject(show_with_delay: Option<Duration>) -> StatusPage {
let gobject = StatusPage::builder() // Init spinner component
.child( let spinner = Spinner::builder()
&Spinner::builder() .width_request(SPINNER_SIZE)
.width_request(SPINNER_SIZE) .height_request(SPINNER_SIZE)
.height_request(SPINNER_SIZE) .build();
.build(),
) // Init main widget
let status_page = StatusPage::builder()
.child(&spinner)
.title(DEFAULT_TITLE) .title(DEFAULT_TITLE)
.build(); .build();
if let Some(duration) = show_with_delay { // Apply optional delay
gobject.set_visible(false); match show_with_delay {
timeout_add_local(duration, { Some(duration) => {
let this = gobject.clone(); timeout_add_local(duration, {
move || { let status_page = status_page.clone();
this.set_visible(true); move || {
ControlFlow::Break status_page.set_visible(true);
} spinner.start();
}); ControlFlow::Break
}
});
}
None => {
status_page.set_visible(true);
spinner.start();
}
} }
gobject // Done
status_page
} }