implement loading widget

This commit is contained in:
yggverse 2024-10-29 01:09:05 +02:00
parent ced0113d0c
commit 385586ca3d
3 changed files with 61 additions and 0 deletions

View File

@ -48,6 +48,14 @@ impl Content {
self.gobject.append(status_default.gobject()); self.gobject.append(status_default.gobject());
} }
pub fn set_status_loading(&self, title: Option<&str>, description: Option<&str>) {
self.clean();
let status_default = Status::new_loading(title, description);
self.gobject.append(status_default.gobject());
}
pub fn set_text_gemini(&self, base: &Uri, data: &str) -> Option<GString> { pub fn set_text_gemini(&self, base: &Uri, data: &str) -> Option<GString> {
self.clean(); self.clean();

View File

@ -0,0 +1,20 @@
mod widget;
use widget::Widget;
use adw::StatusPage;
pub struct Loading {
widget: Widget,
}
impl Loading {
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
Self {
widget: Widget::new(title, description),
}
}
pub fn gobject(&self) -> &StatusPage {
&self.widget.gobject()
}
}

View File

@ -0,0 +1,33 @@
use adw::{Spinner, StatusPage};
/// 16-64 (px)
const SPINNER_SIZE: i32 = 64;
pub struct Widget {
gobject: StatusPage,
}
impl Widget {
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
let gobject = StatusPage::builder()
.child(
&Spinner::builder()
.width_request(SPINNER_SIZE)
.height_request(SPINNER_SIZE)
.build(),
)
.build();
if let Some(value) = title {
gobject.set_title(value);
}
gobject.set_description(description);
Self { gobject }
}
pub fn gobject(&self) -> &StatusPage {
&self.gobject
}
}