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

@ -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, {