implement separated mod with options for failure component

This commit is contained in:
yggverse 2024-10-29 01:24:10 +02:00
parent 1d4a3cbd42
commit 931dc1cfc2
5 changed files with 92 additions and 26 deletions

View file

@ -1,6 +1,8 @@
mod failure;
mod loading;
use failure::Failure;
use loading::Loading;
use adw::StatusPage;
@ -9,14 +11,26 @@ pub struct Status {
}
impl Status {
// Construct
pub fn new_error(title: &str, description: &str) -> Self {
// Constructors
/// Create new default failure component
pub fn new_failure(title: Option<&str>, description: Option<&str>) -> Self {
Self {
gobject: Failure::new(title, description),
gobject: Failure::new(title, description).gobject().clone(),
}
}
/// Create new default loading component
///
/// Useful as the placeholder widget for async operations
pub fn new_loading(title: Option<&str>, description: Option<&str>) -> Self {
Self {
gobject: Loading::new(title, description).gobject().clone(),
}
}
// Getters
pub fn gobject(&self) -> &StatusPage {
&self.gobject
}

View file

@ -1,15 +1,20 @@
mod widget;
use widget::Widget;
use adw::StatusPage;
pub struct Failure {
// nothing yet..
widget: Widget,
}
impl Failure {
pub fn new(title: &str, description: &str) -> StatusPage {
StatusPage::builder()
.description(description)
.icon_name("dialog-error-symbolic")
.title(title)
.build()
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,28 @@
use adw::StatusPage;
pub struct Widget {
gobject: StatusPage,
}
impl Widget {
// Constructors
/// Create new default widget configuration
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
let gobject = StatusPage::new();
if let Some(value) = title {
gobject.set_title(value);
}
gobject.set_description(description);
Self { gobject }
}
// Getters
pub fn gobject(&self) -> &StatusPage {
&self.gobject
}
}