update construction api

This commit is contained in:
yggverse 2024-11-01 01:04:59 +02:00
parent dcb4eacb7f
commit cb651496fd
5 changed files with 73 additions and 125 deletions

View file

@ -14,38 +14,38 @@ impl Status {
/// Create new failure preset
///
/// Useful as placeholder widget for error handlers
pub fn new_failure(
title: Option<&str>,
description: Option<&str>,
icon_name: Option<&str>,
) -> Self {
pub fn new_failure() -> Self {
Self {
gobject: failure::new_gobject_from(title, description, icon_name),
gobject: failure::new_gobject(),
}
}
/// Create new loading preset
///
/// Useful as placeholder widget for async operations
pub fn new_loading(
title: Option<&str>,
description: Option<&str>,
show_with_delay: Option<Duration>,
) -> Self {
pub fn new_loading(show_with_delay: Option<Duration>) -> Self {
Self {
gobject: loading::new_gobject_from(title, description, show_with_delay),
gobject: loading::new_gobject(show_with_delay),
}
}
// Setters
/// Set new description for status component
/// Set new title for `Self`
///
/// Return `Self` reference to apply another functions in chain
pub fn set_title(&self, value: &str) -> &Self {
self.gobject.set_title(value);
&self
}
/// Set new description for `Self`
///
/// Useful for loading widgets to update byte totals and other dynamically changed information
///
/// Return `Self` reference to apply another functions in chain
pub fn set_description(&self, description: Option<&str>) -> &Self {
self.gobject.set_description(description);
pub fn set_description(&self, value: Option<&str>) -> &Self {
self.gobject.set_description(value);
&self
}

View file

@ -1,31 +1,13 @@
use adw::StatusPage;
const DEFAULT_TITLE: &str = "Oops";
const DEFAULT_DESCRIPTION: Option<&str> = None;
const DEFAULT_ICON_NAME: Option<&str> = Some("dialog-error");
const DEFAULT_ICON_NAME: &str = "dialog-error";
/// Create new `GObject` preset for failure [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
pub fn new_gobject_from(
title: Option<&str>,
description: Option<&str>,
icon_name: Option<&str>,
) -> StatusPage {
let gobject = StatusPage::new();
gobject.set_title(match title {
Some(value) => value,
None => DEFAULT_TITLE,
});
gobject.set_description(match description {
Some(value) => Some(value),
None => DEFAULT_DESCRIPTION,
});
gobject.set_icon_name(match icon_name {
Some(value) => Some(value),
None => DEFAULT_ICON_NAME,
});
gobject
/// Create new default `GObject` preset for failure
/// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
pub fn new_gobject() -> StatusPage {
StatusPage::builder()
.title(DEFAULT_TITLE)
.icon_name(DEFAULT_ICON_NAME)
.build()
}

View file

@ -5,15 +5,12 @@ use gtk::{
};
use std::time::Duration;
/// 16-64 (px)
const SPINNER_SIZE: i32 = 64;
const SPINNER_SIZE: i32 = 64; // 16-64
const DEFAULT_TITLE: &str = "Loading..";
/// Create new `GObject` preset for loading [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
pub fn new_gobject_from(
title: Option<&str>,
description: Option<&str>,
show_with_delay: Option<Duration>,
) -> StatusPage {
/// Create new default `GObject` 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()
@ -21,14 +18,9 @@ pub fn new_gobject_from(
.height_request(SPINNER_SIZE)
.build(),
)
.title(DEFAULT_TITLE)
.build();
if let Some(value) = title {
gobject.set_title(value);
}
gobject.set_description(description);
if let Some(duration) = show_with_delay {
gobject.set_visible(false);
timeout_add_local(duration, {