remove extra levels

This commit is contained in:
yggverse 2024-10-31 19:15:22 +02:00
parent 91e22f0035
commit 8e2e430bc6
5 changed files with 62 additions and 116 deletions

View File

@ -19,7 +19,7 @@ impl Status {
/// Useful as placeholder widget for error handlers
pub fn new_failure(title: Option<&str>, description: Option<&str>) -> Self {
Self {
gobject: Failure::new(title, description).gobject().clone(),
gobject: Failure::new(title, description, None).gobject().clone(),
}
}

View File

@ -1,20 +1,36 @@
mod widget;
use widget::Widget;
use adw::StatusPage;
const DEFAULT_TITLE: &str = "Oops";
const DEFAULT_DESCRIPTION: Option<&str> = None;
const DEFAULT_ICON_NAME: Option<&str> = Some("dialog-error");
pub struct Failure {
widget: Widget,
gobject: StatusPage,
}
impl Failure {
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
Self {
widget: Widget::new(title, description),
}
pub fn new(title: Option<&str>, description: Option<&str>, icon_name: Option<&str>) -> Self {
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,
});
Self { gobject }
}
pub fn gobject(&self) -> &StatusPage {
&self.widget.gobject()
&self.gobject
}
}

View File

@ -1,38 +0,0 @@
use adw::StatusPage;
const DEFAULT_TITLE: &str = "Oops";
const DEFAULT_DESCRIPTION: Option<&str> = None;
const DEFAULT_ICON_NAME: &str = "dialog-error";
pub struct Widget {
gobject: StatusPage,
}
impl Widget {
// Constructors
/// Create new default widget configuration with options
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
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(Some(DEFAULT_ICON_NAME));
Self { gobject }
}
// Getters
pub fn gobject(&self) -> &StatusPage {
&self.gobject
}
}

View File

@ -1,11 +1,15 @@
mod widget;
use widget::Widget;
use adw::StatusPage;
use adw::{Spinner, StatusPage};
use gtk::{
glib::{timeout_add_local, ControlFlow},
prelude::WidgetExt,
};
use std::time::Duration;
/// 16-64 (px)
const SPINNER_SIZE: i32 = 64;
pub struct Loading {
widget: Widget,
gobject: StatusPage,
}
impl Loading {
@ -14,12 +18,36 @@ impl Loading {
description: Option<&str>,
show_with_delay: Option<Duration>,
) -> Self {
Self {
widget: Widget::new(title, description, show_with_delay),
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);
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
}
});
}
Self { gobject }
}
pub fn gobject(&self) -> &StatusPage {
&self.widget.gobject()
&self.gobject
}
}

View File

@ -1,60 +0,0 @@
use adw::{Spinner, StatusPage};
use gtk::{
glib::{timeout_add_local, ControlFlow},
prelude::WidgetExt,
};
use std::time::Duration;
/// 16-64 (px)
const SPINNER_SIZE: i32 = 64;
pub struct Widget {
gobject: StatusPage,
}
impl Widget {
// Constructors
/// Create new default widget configuration with options
///
/// * use `show_with_delay` option on loading not take a while
pub fn new(
title: Option<&str>,
description: Option<&str>,
show_with_delay: Option<Duration>,
) -> 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);
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
}
});
}
Self { gobject }
}
// Getters
pub fn gobject(&self) -> &StatusPage {
&self.gobject
}
}