@@ -153,9 +153,13 @@ impl Gallery {
153
153
}
154
154
155
155
pub fn view ( & self ) -> Element < ' _ , Message > {
156
- let gallery = row ( self . images . iter ( ) . map ( |image| {
157
- card ( image, self . thumbnails . get ( & image. id ) , self . now )
158
- } ) )
156
+ let gallery = if self . images . is_empty ( ) {
157
+ row ( ( 0 ..=Image :: LIMIT ) . map ( |_| placeholder ( ) ) )
158
+ } else {
159
+ row ( self . images . iter ( ) . map ( |image| {
160
+ card ( image, self . thumbnails . get ( & image. id ) , self . now )
161
+ } ) )
162
+ }
159
163
. spacing ( 10 )
160
164
. wrap ( ) ;
161
165
@@ -187,8 +191,8 @@ fn card<'a>(
187
191
188
192
let card = mouse_area (
189
193
container ( image)
190
- . width ( 320 )
191
- . height ( 410 )
194
+ . width ( Thumbnail :: WIDTH )
195
+ . height ( Thumbnail :: HEIGHT )
192
196
. style ( container:: dark) ,
193
197
)
194
198
. on_enter ( Message :: ThumbnailHovered ( metadata. id , true ) )
@@ -207,13 +211,24 @@ fn card<'a>(
207
211
}
208
212
}
209
213
214
+ fn placeholder < ' a > ( ) -> Element < ' a , Message > {
215
+ container ( horizontal_space ( ) )
216
+ . width ( Thumbnail :: WIDTH )
217
+ . height ( Thumbnail :: HEIGHT )
218
+ . style ( container:: dark)
219
+ . into ( )
220
+ }
221
+
210
222
struct Thumbnail {
211
223
handle : image:: Handle ,
212
224
fade_in : Animation < bool > ,
213
225
zoom : Animation < bool > ,
214
226
}
215
227
216
228
impl Thumbnail {
229
+ const WIDTH : u16 = 320 ;
230
+ const HEIGHT : u16 = 410 ;
231
+
217
232
fn new ( rgba : Rgba ) -> Self {
218
233
Self {
219
234
handle : image:: Handle :: from_rgba (
0 commit comments