Make loading of poster images async
This commit is contained in:
parent
bc1661b8d9
commit
547a811acf
4 changed files with 41 additions and 41 deletions
|
|
@ -4,10 +4,11 @@ use {
|
|||
Align :: * ,
|
||||
Orientation :: * ,
|
||||
gdk :: * ,
|
||||
gio :: * ,
|
||||
pango :: { * , Weight :: * } ,
|
||||
prelude :: * ,
|
||||
} ,
|
||||
std :: { cell :: * , iter :: * , path :: Path } ,
|
||||
std :: { cell :: * , iter :: * , path :: { Path , PathBuf } } ,
|
||||
} ;
|
||||
|
||||
use crate :: ui :: { collatable_container :: * , component :: * } ;
|
||||
|
|
@ -24,7 +25,7 @@ pub struct CollatedSeriesGrid {
|
|||
}
|
||||
|
||||
impl CollatedFilmsGrid {
|
||||
pub fn new ( films : Vec <FilmOverview> , sorting : FilmsSorting ) -> Self {
|
||||
pub fn new () -> Self {
|
||||
let grid_widget = flow_box ! (
|
||||
@ orientation : Horizontal ;
|
||||
@ homogeneous : true ;
|
||||
|
|
@ -32,16 +33,14 @@ impl CollatedFilmsGrid {
|
|||
) ;
|
||||
let film_widget_pairs = RefCell :: new ( vec ! () ) ;
|
||||
|
||||
let component = Self { film_widget_pairs , grid_widget } ;
|
||||
component . set_films ( films , sorting ) ;
|
||||
|
||||
component
|
||||
Self { film_widget_pairs , grid_widget }
|
||||
}
|
||||
|
||||
pub fn set_films ( & self , films : Vec <FilmOverview> , sorting : FilmsSorting ) {
|
||||
let widgets = films . iter ()
|
||||
. map (create_film_entry)
|
||||
. collect :: < Vec <_> > () ;
|
||||
pub async fn set_films ( & self , films : Vec <FilmOverview> , sorting : FilmsSorting ) {
|
||||
let mut widgets = Vec :: new () ;
|
||||
for film in films . as_slice () {
|
||||
widgets . push ( create_film_entry (film) . await ) ;
|
||||
}
|
||||
* self . film_widget_pairs . borrow_mut () = zip ( films , widgets )
|
||||
. collect () ;
|
||||
|
||||
|
|
@ -77,7 +76,7 @@ impl CollatedFilmsGrid {
|
|||
}
|
||||
}
|
||||
impl CollatedSeriesGrid {
|
||||
pub fn new ( series : Vec <SeriesOverview> , sorting : SeriesSorting ) -> Self {
|
||||
pub fn new () -> Self {
|
||||
let grid_widget = flow_box ! (
|
||||
@ orientation : Horizontal ;
|
||||
@ homogeneous : true ;
|
||||
|
|
@ -85,16 +84,14 @@ impl CollatedSeriesGrid {
|
|||
) ;
|
||||
let series_widget_pairs = RefCell :: new ( vec ! () ) ;
|
||||
|
||||
let component = Self { series_widget_pairs , grid_widget } ;
|
||||
component . set_series ( series, sorting ) ;
|
||||
|
||||
component
|
||||
Self { series_widget_pairs , grid_widget }
|
||||
}
|
||||
|
||||
pub fn set_series ( & self , series : Vec <SeriesOverview> , sorting : SeriesSorting ) {
|
||||
let widgets = series . iter ()
|
||||
. map (create_series_entry)
|
||||
. collect :: < Vec <_> > () ;
|
||||
pub async fn set_series ( & self , series : Vec <SeriesOverview> , sorting : SeriesSorting ) {
|
||||
let mut widgets = Vec :: new () ;
|
||||
for series in series . as_slice () {
|
||||
widgets . push ( create_series_entry (series) . await ) ;
|
||||
}
|
||||
* self . series_widget_pairs . borrow_mut () = zip ( series , widgets )
|
||||
. collect () ;
|
||||
|
||||
|
|
@ -135,24 +132,24 @@ impl Component <FlowBox> for CollatedSeriesGrid {
|
|||
fn get_widget ( & self ) -> & FlowBox { & self . grid_widget }
|
||||
}
|
||||
|
||||
pub fn create_film_entry ( film : & FilmOverview ) -> Box {
|
||||
pub async fn create_film_entry ( film : & FilmOverview ) -> Box {
|
||||
create_collection_item (
|
||||
film . name . as_str () ,
|
||||
film . original_name . as_deref () ,
|
||||
film . poster_file_path . as_deref () ,
|
||||
& create_film_details (film) ,
|
||||
)
|
||||
) . await
|
||||
}
|
||||
pub fn create_series_entry ( series : & SeriesOverview ) -> Box {
|
||||
pub async fn create_series_entry ( series : & SeriesOverview ) -> Box {
|
||||
create_collection_item (
|
||||
series . name . as_str () ,
|
||||
series . original_name . as_deref () ,
|
||||
series . poster_file_path . as_deref () ,
|
||||
& create_series_details (series) ,
|
||||
)
|
||||
) . await
|
||||
}
|
||||
|
||||
fn create_collection_item (
|
||||
async fn create_collection_item (
|
||||
name : & str ,
|
||||
original_name : Option < & str > ,
|
||||
poster_file_path : Option < & Path > ,
|
||||
|
|
@ -165,7 +162,11 @@ fn create_collection_item (
|
|||
. build () ;
|
||||
|
||||
if let Some (poster_file_path) = poster_file_path {
|
||||
let poster_texture = Texture :: from_filename (poster_file_path) . unwrap () ;
|
||||
let poster_file_path = PathBuf :: from (poster_file_path) ; // God forbid `Path` would work with `clone ! ()`
|
||||
let poster_texture = spawn_blocking ( move ||
|
||||
Texture :: from_filename (poster_file_path) . unwrap ()
|
||||
) . await . unwrap () ;
|
||||
|
||||
container . append (
|
||||
& Image :: builder ()
|
||||
. paintable ( & poster_texture )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue