mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-05 16:04:15 +00:00
remove extra levels
This commit is contained in:
parent
91e22f0035
commit
8e2e430bc6
@ -19,7 +19,7 @@ impl Status {
|
|||||||
/// Useful as placeholder widget for error handlers
|
/// Useful as placeholder widget for error handlers
|
||||||
pub fn new_failure(title: Option<&str>, description: Option<&str>) -> Self {
|
pub fn new_failure(title: Option<&str>, description: Option<&str>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
gobject: Failure::new(title, description).gobject().clone(),
|
gobject: Failure::new(title, description, None).gobject().clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,20 +1,36 @@
|
|||||||
mod widget;
|
|
||||||
use widget::Widget;
|
|
||||||
|
|
||||||
use adw::StatusPage;
|
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 {
|
pub struct Failure {
|
||||||
widget: Widget,
|
gobject: StatusPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Failure {
|
impl Failure {
|
||||||
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
|
pub fn new(title: Option<&str>, description: Option<&str>, icon_name: Option<&str>) -> Self {
|
||||||
Self {
|
let gobject = StatusPage::new();
|
||||||
widget: Widget::new(title, description),
|
|
||||||
}
|
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 {
|
pub fn gobject(&self) -> &StatusPage {
|
||||||
&self.widget.gobject()
|
&self.gobject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +1,15 @@
|
|||||||
mod widget;
|
use adw::{Spinner, StatusPage};
|
||||||
use widget::Widget;
|
use gtk::{
|
||||||
|
glib::{timeout_add_local, ControlFlow},
|
||||||
use adw::StatusPage;
|
prelude::WidgetExt,
|
||||||
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
/// 16-64 (px)
|
||||||
|
const SPINNER_SIZE: i32 = 64;
|
||||||
|
|
||||||
pub struct Loading {
|
pub struct Loading {
|
||||||
widget: Widget,
|
gobject: StatusPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Loading {
|
impl Loading {
|
||||||
@ -14,12 +18,36 @@ impl Loading {
|
|||||||
description: Option<&str>,
|
description: Option<&str>,
|
||||||
show_with_delay: Option<Duration>,
|
show_with_delay: Option<Duration>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
let gobject = StatusPage::builder()
|
||||||
widget: Widget::new(title, description, show_with_delay),
|
.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 {
|
pub fn gobject(&self) -> &StatusPage {
|
||||||
&self.widget.gobject()
|
&self.gobject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user