mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
update construction api
This commit is contained in:
parent
dcb4eacb7f
commit
cb651496fd
@ -63,10 +63,7 @@ impl Page {
|
|||||||
SimpleAction::new(&uuid_string_random(), Some(&String::static_variant_type()));
|
SimpleAction::new(&uuid_string_random(), Some(&String::static_variant_type()));
|
||||||
|
|
||||||
// Init components
|
// Init components
|
||||||
let content = Arc::new(Content::new(
|
let content = Content::new_arc(action_tab_open.clone(), action_page_open.clone());
|
||||||
action_tab_open.clone(),
|
|
||||||
action_page_open.clone(),
|
|
||||||
));
|
|
||||||
|
|
||||||
let navigation = Navigation::new_arc(
|
let navigation = Navigation::new_arc(
|
||||||
action_tab_page_navigation_base.clone(),
|
action_tab_page_navigation_base.clone(),
|
||||||
@ -189,11 +186,10 @@ impl Page {
|
|||||||
let description = gformat!("Protocol `{scheme}` not supported");
|
let description = gformat!("Protocol `{scheme}` not supported");
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
self.content.to_status_failure(
|
self.content
|
||||||
Some(title.as_str()),
|
.to_status_failure()
|
||||||
Some(description.as_str()),
|
.set_title(title.as_str())
|
||||||
None,
|
.set_description(Some(description.as_str()));
|
||||||
);
|
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
self.meta.replace(Meta {
|
self.meta.replace(Meta {
|
||||||
@ -524,11 +520,10 @@ impl Page {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content.to_status_failure(
|
content
|
||||||
Some(title.as_str()),
|
.to_status_failure()
|
||||||
Some(description.as_str()),
|
.set_title(title.as_str())
|
||||||
None
|
.set_description(Some(description.as_str()));
|
||||||
);
|
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
@ -551,8 +546,6 @@ impl Page {
|
|||||||
=> {
|
=> {
|
||||||
// Final image size unknown, show loading widget
|
// Final image size unknown, show loading widget
|
||||||
let status = content.to_status_loading(
|
let status = content.to_status_loading(
|
||||||
Some(&"Loading.."),
|
|
||||||
None,
|
|
||||||
Some(Duration::from_secs(1)) // show if download time > 1 second
|
Some(Duration::from_secs(1)) // show if download time > 1 second
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -594,11 +587,10 @@ impl Page {
|
|||||||
let title = gformat!("Oops");
|
let title = gformat!("Oops");
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content.to_status_failure(
|
content
|
||||||
Some(title.as_str()),
|
.to_status_failure()
|
||||||
Some(reason.message()),
|
.set_title(title.as_str())
|
||||||
None
|
.set_description(Some(reason.message()));
|
||||||
);
|
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
@ -623,17 +615,15 @@ impl Page {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content.to_status_failure(
|
content
|
||||||
Some(title.as_str()),
|
.to_status_failure()
|
||||||
Some(description.as_str()),
|
.set_title(title.as_str())
|
||||||
None
|
.set_description(Some(description.as_str()));
|
||||||
);
|
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
status: Some(status),
|
status: Some(status),
|
||||||
title: Some(title),
|
title: Some(title),
|
||||||
//description: Some(description),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -660,11 +650,10 @@ impl Page {
|
|||||||
let description = gformat!("Content type not supported");
|
let description = gformat!("Content type not supported");
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content.to_status_failure(
|
content
|
||||||
Some(title.as_str()),
|
.to_status_failure()
|
||||||
Some(description.as_str()),
|
.set_title(title.as_str())
|
||||||
None
|
.set_description(Some(description.as_str()));
|
||||||
);
|
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
@ -696,11 +685,9 @@ impl Page {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
content.to_status_failure(
|
content
|
||||||
Some(&"Oops"),
|
.to_status_failure()
|
||||||
Some(&"Could not parse redirect meta"),
|
.set_description(Some("Could not parse redirect meta"));
|
||||||
None
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,11 +747,10 @@ impl Page {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content.to_status_failure(
|
content
|
||||||
Some(title.as_str()),
|
.to_status_failure()
|
||||||
Some(description.as_str()),
|
.set_title(title.as_str())
|
||||||
None
|
.set_description(Some(description.as_str()));
|
||||||
);
|
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
@ -785,11 +771,10 @@ impl Page {
|
|||||||
let title = gformat!("Oops");
|
let title = gformat!("Oops");
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content.to_status_failure(
|
content
|
||||||
Some(title.as_str()),
|
.to_status_failure()
|
||||||
Some(reason.message()),
|
.set_title(title.as_str())
|
||||||
None
|
.set_description(Some(reason.message()));
|
||||||
);
|
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
@ -809,11 +794,10 @@ impl Page {
|
|||||||
let title = gformat!("Oops");
|
let title = gformat!("Oops");
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
content.to_status_failure(
|
content
|
||||||
Some(title.as_str()),
|
.to_status_failure()
|
||||||
Some(reason.message()),
|
.set_title(title.as_str())
|
||||||
None
|
.set_description(Some(reason.message()));
|
||||||
);
|
|
||||||
|
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.replace(Meta {
|
meta.replace(Meta {
|
||||||
|
@ -13,7 +13,7 @@ use gtk::{
|
|||||||
prelude::{BoxExt, WidgetExt},
|
prelude::{BoxExt, WidgetExt},
|
||||||
Box, Orientation,
|
Box, Orientation,
|
||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
pub struct Content {
|
pub struct Content {
|
||||||
// GTK
|
// GTK
|
||||||
@ -27,12 +27,12 @@ impl Content {
|
|||||||
// Construct
|
// Construct
|
||||||
|
|
||||||
/// Create new container for different components
|
/// Create new container for different components
|
||||||
pub fn new(action_tab_open: SimpleAction, action_page_open: SimpleAction) -> Self {
|
pub fn new_arc(action_tab_open: SimpleAction, action_page_open: SimpleAction) -> Arc<Self> {
|
||||||
Self {
|
Arc::new(Self {
|
||||||
gobject: Box::builder().orientation(Orientation::Vertical).build(),
|
gobject: Box::builder().orientation(Orientation::Vertical).build(),
|
||||||
action_tab_open,
|
action_tab_open,
|
||||||
action_page_open,
|
action_page_open,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -50,14 +50,9 @@ impl Content {
|
|||||||
/// Set new `content::Status` component for `Self` with new `status::Failure` preset
|
/// Set new `content::Status` component for `Self` with new `status::Failure` preset
|
||||||
///
|
///
|
||||||
/// * action removes previous children component from `Self`
|
/// * action removes previous children component from `Self`
|
||||||
pub fn to_status_failure(
|
pub fn to_status_failure(&self) -> Status {
|
||||||
&self,
|
|
||||||
title: Option<&str>,
|
|
||||||
description: Option<&str>,
|
|
||||||
icon_name: Option<&str>,
|
|
||||||
) -> Status {
|
|
||||||
self.clean();
|
self.clean();
|
||||||
let status = Status::new_failure(title, description, icon_name);
|
let status = Status::new_failure();
|
||||||
self.gobject.append(status.gobject());
|
self.gobject.append(status.gobject());
|
||||||
status
|
status
|
||||||
}
|
}
|
||||||
@ -65,14 +60,9 @@ impl Content {
|
|||||||
/// Set new `content::Status` component for `Self` with new `status::Loading` preset
|
/// Set new `content::Status` component for `Self` with new `status::Loading` preset
|
||||||
///
|
///
|
||||||
/// * action removes previous children component from `Self`
|
/// * action removes previous children component from `Self`
|
||||||
pub fn to_status_loading(
|
pub fn to_status_loading(&self, show_with_delay: Option<Duration>) -> Status {
|
||||||
&self,
|
|
||||||
title: Option<&str>,
|
|
||||||
description: Option<&str>,
|
|
||||||
show_with_delay: Option<Duration>,
|
|
||||||
) -> Status {
|
|
||||||
self.clean();
|
self.clean();
|
||||||
let status = Status::new_loading(title, description, show_with_delay);
|
let status = Status::new_loading(show_with_delay);
|
||||||
self.gobject.append(status.gobject());
|
self.gobject.append(status.gobject());
|
||||||
status
|
status
|
||||||
}
|
}
|
||||||
|
@ -14,38 +14,38 @@ impl Status {
|
|||||||
/// Create new failure preset
|
/// Create new failure preset
|
||||||
///
|
///
|
||||||
/// Useful as placeholder widget for error handlers
|
/// Useful as placeholder widget for error handlers
|
||||||
pub fn new_failure(
|
pub fn new_failure() -> Self {
|
||||||
title: Option<&str>,
|
|
||||||
description: Option<&str>,
|
|
||||||
icon_name: Option<&str>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
gobject: failure::new_gobject_from(title, description, icon_name),
|
gobject: failure::new_gobject(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create new loading preset
|
/// Create new loading preset
|
||||||
///
|
///
|
||||||
/// Useful as placeholder widget for async operations
|
/// Useful as placeholder widget for async operations
|
||||||
pub fn new_loading(
|
pub fn new_loading(show_with_delay: Option<Duration>) -> Self {
|
||||||
title: Option<&str>,
|
|
||||||
description: Option<&str>,
|
|
||||||
show_with_delay: Option<Duration>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
gobject: loading::new_gobject_from(title, description, show_with_delay),
|
gobject: loading::new_gobject(show_with_delay),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
|
|
||||||
/// Set new description for status component
|
/// Set new title for `Self`
|
||||||
|
///
|
||||||
|
/// Return `Self` reference to apply another functions in chain
|
||||||
|
pub fn set_title(&self, value: &str) -> &Self {
|
||||||
|
self.gobject.set_title(value);
|
||||||
|
&self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set new description for `Self`
|
||||||
///
|
///
|
||||||
/// Useful for loading widgets to update byte totals and other dynamically changed information
|
/// Useful for loading widgets to update byte totals and other dynamically changed information
|
||||||
///
|
///
|
||||||
/// Return `Self` reference to apply another functions in chain
|
/// Return `Self` reference to apply another functions in chain
|
||||||
pub fn set_description(&self, description: Option<&str>) -> &Self {
|
pub fn set_description(&self, value: Option<&str>) -> &Self {
|
||||||
self.gobject.set_description(description);
|
self.gobject.set_description(value);
|
||||||
&self
|
&self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,31 +1,13 @@
|
|||||||
use adw::StatusPage;
|
use adw::StatusPage;
|
||||||
|
|
||||||
const DEFAULT_TITLE: &str = "Oops";
|
const DEFAULT_TITLE: &str = "Oops";
|
||||||
const DEFAULT_DESCRIPTION: Option<&str> = None;
|
const DEFAULT_ICON_NAME: &str = "dialog-error";
|
||||||
const DEFAULT_ICON_NAME: Option<&str> = Some("dialog-error");
|
|
||||||
|
|
||||||
/// Create new `GObject` preset for failure [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
|
/// Create new default `GObject` preset for failure
|
||||||
pub fn new_gobject_from(
|
/// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
|
||||||
title: Option<&str>,
|
pub fn new_gobject() -> StatusPage {
|
||||||
description: Option<&str>,
|
StatusPage::builder()
|
||||||
icon_name: Option<&str>,
|
.title(DEFAULT_TITLE)
|
||||||
) -> StatusPage {
|
.icon_name(DEFAULT_ICON_NAME)
|
||||||
let gobject = StatusPage::new();
|
.build()
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,12 @@ use gtk::{
|
|||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// 16-64 (px)
|
const SPINNER_SIZE: i32 = 64; // 16-64
|
||||||
const SPINNER_SIZE: i32 = 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)
|
/// Create new default `GObject` preset for loading
|
||||||
pub fn new_gobject_from(
|
/// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
|
||||||
title: Option<&str>,
|
pub fn new_gobject(show_with_delay: Option<Duration>) -> StatusPage {
|
||||||
description: Option<&str>,
|
|
||||||
show_with_delay: Option<Duration>,
|
|
||||||
) -> StatusPage {
|
|
||||||
let gobject = StatusPage::builder()
|
let gobject = StatusPage::builder()
|
||||||
.child(
|
.child(
|
||||||
&Spinner::builder()
|
&Spinner::builder()
|
||||||
@ -21,14 +18,9 @@ pub fn new_gobject_from(
|
|||||||
.height_request(SPINNER_SIZE)
|
.height_request(SPINNER_SIZE)
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
|
.title(DEFAULT_TITLE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if let Some(value) = title {
|
|
||||||
gobject.set_title(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
gobject.set_description(description);
|
|
||||||
|
|
||||||
if let Some(duration) = show_with_delay {
|
if let Some(duration) = show_with_delay {
|
||||||
gobject.set_visible(false);
|
gobject.set_visible(false);
|
||||||
timeout_add_local(duration, {
|
timeout_add_local(duration, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user