mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-05 07:54:14 +00:00
implement show_with_delay option
This commit is contained in:
parent
0912f2c68d
commit
a336b18ac3
@ -29,7 +29,7 @@ use gtk::{
|
||||
Box,
|
||||
};
|
||||
use sqlite::Transaction;
|
||||
use std::{cell::RefCell, sync::Arc};
|
||||
use std::{cell::RefCell, sync::Arc, time::Duration};
|
||||
|
||||
pub struct Page {
|
||||
id: GString,
|
||||
@ -548,7 +548,8 @@ impl Page {
|
||||
// Final image size unknown, show loading widget
|
||||
let status = content.set_status_loading(
|
||||
Some(&"Loading.."),
|
||||
None
|
||||
None,
|
||||
Some(Duration::from_secs(1)) // show if download time > 1 second
|
||||
);
|
||||
|
||||
// Asynchronously move `InputStream` data from `SocketConnection` into the local `MemoryInputStream`
|
||||
|
@ -13,6 +13,8 @@ use gtk::{
|
||||
prelude::{BoxExt, WidgetExt},
|
||||
Box, Orientation,
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
pub struct Content {
|
||||
// GTK
|
||||
gobject: Box,
|
||||
@ -46,9 +48,14 @@ impl Content {
|
||||
}
|
||||
|
||||
/// Loading placeholder
|
||||
pub fn set_status_loading(&self, title: Option<&str>, description: Option<&str>) -> Status {
|
||||
pub fn set_status_loading(
|
||||
&self,
|
||||
title: Option<&str>,
|
||||
description: Option<&str>,
|
||||
show_with_delay: Option<Duration>,
|
||||
) -> Status {
|
||||
self.clean();
|
||||
let status = Status::new_loading(title, description);
|
||||
let status = Status::new_loading(title, description, show_with_delay);
|
||||
self.gobject.append(status.gobject());
|
||||
status
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ use failure::Failure;
|
||||
use loading::Loading;
|
||||
|
||||
use adw::StatusPage;
|
||||
use std::time::Duration;
|
||||
|
||||
pub struct Status {
|
||||
gobject: StatusPage,
|
||||
@ -25,9 +26,15 @@ impl Status {
|
||||
/// Create new loading preset
|
||||
///
|
||||
/// Useful as placeholder widget for async operations
|
||||
pub fn new_loading(title: Option<&str>, description: Option<&str>) -> Self {
|
||||
pub fn new_loading(
|
||||
title: Option<&str>,
|
||||
description: Option<&str>,
|
||||
show_with_delay: Option<Duration>,
|
||||
) -> Self {
|
||||
Self {
|
||||
gobject: Loading::new(title, description).gobject().clone(),
|
||||
gobject: Loading::new(title, description, show_with_delay)
|
||||
.gobject()
|
||||
.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,15 +2,20 @@ mod widget;
|
||||
use widget::Widget;
|
||||
|
||||
use adw::StatusPage;
|
||||
use std::time::Duration;
|
||||
|
||||
pub struct Loading {
|
||||
widget: Widget,
|
||||
}
|
||||
|
||||
impl Loading {
|
||||
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
|
||||
pub fn new(
|
||||
title: Option<&str>,
|
||||
description: Option<&str>,
|
||||
show_with_delay: Option<Duration>,
|
||||
) -> Self {
|
||||
Self {
|
||||
widget: Widget::new(title, description),
|
||||
widget: Widget::new(title, description, show_with_delay),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,9 @@
|
||||
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;
|
||||
@ -11,7 +16,13 @@ impl Widget {
|
||||
// Constructors
|
||||
|
||||
/// Create new default widget configuration with options
|
||||
pub fn new(title: Option<&str>, description: Option<&str>) -> Self {
|
||||
///
|
||||
/// * 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()
|
||||
@ -27,6 +38,17 @@ impl Widget {
|
||||
|
||||
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 }
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user