diff --git a/src/app/browser/window/tab/item/page/content/status.rs b/src/app/browser/window/tab/item/page/content/status.rs index 218177b1..4e248367 100644 --- a/src/app/browser/window/tab/item/page/content/status.rs +++ b/src/app/browser/window/tab/item/page/content/status.rs @@ -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(), } } diff --git a/src/app/browser/window/tab/item/page/content/status/failure.rs b/src/app/browser/window/tab/item/page/content/status/failure.rs index 123ab629..a9f0aaf7 100644 --- a/src/app/browser/window/tab/item/page/content/status/failure.rs +++ b/src/app/browser/window/tab/item/page/content/status/failure.rs @@ -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 } } diff --git a/src/app/browser/window/tab/item/page/content/status/failure/widget.rs b/src/app/browser/window/tab/item/page/content/status/failure/widget.rs deleted file mode 100644 index 2857e4e6..00000000 --- a/src/app/browser/window/tab/item/page/content/status/failure/widget.rs +++ /dev/null @@ -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 - } -} diff --git a/src/app/browser/window/tab/item/page/content/status/loading.rs b/src/app/browser/window/tab/item/page/content/status/loading.rs index 50968fba..754f6b77 100644 --- a/src/app/browser/window/tab/item/page/content/status/loading.rs +++ b/src/app/browser/window/tab/item/page/content/status/loading.rs @@ -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, ) -> 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 } } diff --git a/src/app/browser/window/tab/item/page/content/status/loading/widget.rs b/src/app/browser/window/tab/item/page/content/status/loading/widget.rs deleted file mode 100644 index 8ea2c879..00000000 --- a/src/app/browser/window/tab/item/page/content/status/loading/widget.rs +++ /dev/null @@ -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, - ) -> 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 - } -}