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;
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<Duration>) -> 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
}