Draft new grid widget
This commit is contained in:
parent
193a340d6d
commit
b89e78cd82
5 changed files with 388 additions and 27 deletions
|
|
@ -7,7 +7,7 @@ publish = false
|
|||
|
||||
[dependencies]
|
||||
iced.workspace = true
|
||||
iced.features = ["tokio", "sipper", "image", "web-colors", "debug"]
|
||||
iced.features = ["tokio", "sipper", "image", "debug"]
|
||||
|
||||
reqwest.version = "0.12"
|
||||
reqwest.features = ["json"]
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ use crate::civitai::{Error, Id, Image, Rgba, Size};
|
|||
use iced::animation;
|
||||
use iced::time::{Instant, milliseconds};
|
||||
use iced::widget::{
|
||||
button, center_x, container, horizontal_space, image, mouse_area, opaque,
|
||||
pop, row, scrollable, stack,
|
||||
button, container, grid, horizontal_space, image, mouse_area, opaque, pop,
|
||||
scrollable, stack,
|
||||
};
|
||||
use iced::window;
|
||||
use iced::{
|
||||
|
|
@ -175,19 +175,18 @@ impl Gallery {
|
|||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, Message> {
|
||||
let gallery = if self.images.is_empty() {
|
||||
row((0..=Image::LIMIT).map(|_| placeholder()))
|
||||
} else {
|
||||
row(self.images.iter().map(|image| {
|
||||
card(image, self.previews.get(&image.id), self.now)
|
||||
}))
|
||||
}
|
||||
.spacing(10)
|
||||
.wrap();
|
||||
let images = self
|
||||
.images
|
||||
.iter()
|
||||
.map(|image| card(image, self.previews.get(&image.id), self.now))
|
||||
.chain((self.images.len()..=Image::LIMIT).map(|_| placeholder()));
|
||||
|
||||
let content =
|
||||
container(scrollable(center_x(gallery)).spacing(10)).padding(10);
|
||||
let gallery = grid(images)
|
||||
.fluid(Preview::WIDTH)
|
||||
.ratio(Preview::WIDTH as f32 / Preview::HEIGHT as f32)
|
||||
.spacing(10);
|
||||
|
||||
let content = container(scrollable(gallery).spacing(10)).padding(10);
|
||||
let viewer = self.viewer.view(self.now);
|
||||
|
||||
stack![content, viewer].into()
|
||||
|
|
@ -204,7 +203,6 @@ fn card<'a>(
|
|||
if let Preview::Ready { thumbnail, .. } = &preview {
|
||||
image(&thumbnail.handle)
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.content_fit(ContentFit::Cover)
|
||||
.opacity(thumbnail.fade_in.interpolate(0.0, 1.0, now))
|
||||
.scale(thumbnail.zoom.interpolate(1.0, 1.1, now))
|
||||
|
|
@ -216,7 +214,6 @@ fn card<'a>(
|
|||
if let Some(blurhash) = preview.blurhash(now) {
|
||||
let blurhash = image(&blurhash.handle)
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.content_fit(ContentFit::Cover)
|
||||
.opacity(blurhash.fade_in.interpolate(0.0, 1.0, now));
|
||||
|
||||
|
|
@ -228,14 +225,9 @@ fn card<'a>(
|
|||
horizontal_space().into()
|
||||
};
|
||||
|
||||
let card = mouse_area(
|
||||
container(image)
|
||||
.width(Preview::WIDTH)
|
||||
.height(Preview::HEIGHT)
|
||||
.style(container::dark),
|
||||
)
|
||||
.on_enter(Message::ThumbnailHovered(metadata.id, true))
|
||||
.on_exit(Message::ThumbnailHovered(metadata.id, false));
|
||||
let card = mouse_area(container(image).height(Fill).style(container::dark))
|
||||
.on_enter(Message::ThumbnailHovered(metadata.id, true))
|
||||
.on_exit(Message::ThumbnailHovered(metadata.id, false));
|
||||
|
||||
if let Some(preview) = preview {
|
||||
let is_thumbnail = matches!(preview, Preview::Ready { .. });
|
||||
|
|
@ -254,8 +246,7 @@ fn card<'a>(
|
|||
|
||||
fn placeholder<'a>() -> Element<'a, Message> {
|
||||
container(horizontal_space())
|
||||
.width(Preview::WIDTH)
|
||||
.height(Preview::HEIGHT)
|
||||
.height(Fill)
|
||||
.style(container::dark)
|
||||
.into()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue