summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-01-28 03:25:18 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-01-28 03:25:18 +0100
commitcd445f758f08f97a719a3320d54df30620aa4434 (patch)
tree2c63fffc6a06148c8ed65753debc0a1f6a17f52e /examples
parentae35992048e7717a6e4308841859bfb6c0a7d51c (diff)
downloadiced-cd445f758f08f97a719a3320d54df30620aa4434.tar.gz
iced-cd445f758f08f97a719a3320d54df30620aa4434.tar.bz2
iced-cd445f758f08f97a719a3320d54df30620aa4434.zip
Display grid placeholder when loading `gallery` example
Diffstat (limited to 'examples')
-rw-r--r--examples/gallery/src/civitai.rs4
-rw-r--r--examples/gallery/src/main.rs25
2 files changed, 23 insertions, 6 deletions
diff --git a/examples/gallery/src/civitai.rs b/examples/gallery/src/civitai.rs
index 7a8f1c45..986b6bf2 100644
--- a/examples/gallery/src/civitai.rs
+++ b/examples/gallery/src/civitai.rs
@@ -13,6 +13,8 @@ pub struct Image {
}
impl Image {
+ pub const LIMIT: usize = 99;
+
pub async fn list() -> Result<Vec<Self>, Error> {
let client = reqwest::Client::new();
@@ -27,7 +29,7 @@ impl Image {
("sort", "Most Reactions"),
("period", "Week"),
("nsfw", "None"),
- ("limit", "99"),
+ ("limit", &Image::LIMIT.to_string()),
])
.send()
.await?
diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs
index 7b3b6c35..9092cf9e 100644
--- a/examples/gallery/src/main.rs
+++ b/examples/gallery/src/main.rs
@@ -153,9 +153,13 @@ impl Gallery {
}
pub fn view(&self) -> Element<'_, Message> {
- let gallery = row(self.images.iter().map(|image| {
- card(image, self.thumbnails.get(&image.id), self.now)
- }))
+ let gallery = if self.images.is_empty() {
+ row((0..=Image::LIMIT).map(|_| placeholder()))
+ } else {
+ row(self.images.iter().map(|image| {
+ card(image, self.thumbnails.get(&image.id), self.now)
+ }))
+ }
.spacing(10)
.wrap();
@@ -187,8 +191,8 @@ fn card<'a>(
let card = mouse_area(
container(image)
- .width(320)
- .height(410)
+ .width(Thumbnail::WIDTH)
+ .height(Thumbnail::HEIGHT)
.style(container::dark),
)
.on_enter(Message::ThumbnailHovered(metadata.id, true))
@@ -207,6 +211,14 @@ fn card<'a>(
}
}
+fn placeholder<'a>() -> Element<'a, Message> {
+ container(horizontal_space())
+ .width(Thumbnail::WIDTH)
+ .height(Thumbnail::HEIGHT)
+ .style(container::dark)
+ .into()
+}
+
struct Thumbnail {
handle: image::Handle,
fade_in: Animation<bool>,
@@ -214,6 +226,9 @@ struct Thumbnail {
}
impl Thumbnail {
+ const WIDTH: u16 = 320;
+ const HEIGHT: u16 = 410;
+
fn new(rgba: Rgba) -> Self {
Self {
handle: image::Handle::from_rgba(