Sorting films now uses latest films vec, but it hangs the UI
This commit is contained in:
parent
f912281700
commit
988d4016ea
3 changed files with 28 additions and 23 deletions
|
@ -7,7 +7,7 @@ pub struct Collection {
|
|||
pub series : Vec <Series> ,
|
||||
}
|
||||
|
||||
pub struct Film {
|
||||
# [ derive (Clone) ] pub struct Film {
|
||||
pub uuid : String ,
|
||||
pub name : String ,
|
||||
pub original_name : Option <String> ,
|
||||
|
|
|
@ -10,14 +10,14 @@ use crate :: {
|
|||
} ;
|
||||
|
||||
|
||||
|
||||
pub enum FilmsSortedBy { Name , ReleaseDate , Runtime }
|
||||
pub enum SeriesSortedBy { Name , FirstReleaseDate }
|
||||
|
||||
pub struct FilmsContainer {
|
||||
films : Vec <Film> ,
|
||||
flow_box : FilmsFlowBox ,
|
||||
films : & 'static RefCell < Vec <Film> > ,
|
||||
flow_box : & 'static FilmsFlowBox ,
|
||||
widget : gtk4 :: Box ,
|
||||
sorted_by : & 'static Cell <FilmsSortedBy> ,
|
||||
}
|
||||
pub struct SeriesContainer {
|
||||
series : Vec <Series> ,
|
||||
|
@ -27,21 +27,21 @@ pub struct SeriesContainer {
|
|||
|
||||
impl FilmsContainer {
|
||||
pub fn new ( films : Vec <Film> ) -> Self {
|
||||
let flow_box = FilmsFlowBox :: new ( films . as_slice () ) ;
|
||||
let sorted_by = leak ( Cell :: new ( FilmsSortedBy :: Name ) ) ;
|
||||
let films = leak ( RefCell :: new (films) ) ;
|
||||
let flow_box = leak ( FilmsFlowBox :: new ( films . borrow () . as_slice () ) ) ;
|
||||
let widget = create_vertical_box ! (
|
||||
& create_film_collection_menu ( |new_sorted_by| {
|
||||
sorted_by . replace (new_sorted_by) ;
|
||||
& create_film_collection_menu ( |sorted_by| {
|
||||
flow_box . set_films ( films . borrow () . as_slice () ) ;
|
||||
} ) ,
|
||||
& create_collection_scrolled_window ( flow_box . get_widget () ) ,
|
||||
) ;
|
||||
|
||||
Self { films , flow_box , widget , sorted_by }
|
||||
Self { films , flow_box , widget }
|
||||
}
|
||||
|
||||
pub fn set_films ( & mut self , films : Vec <Film> ) {
|
||||
self . films = films ;
|
||||
self . flow_box . set_films ( self . films . as_slice () ) ;
|
||||
pub fn set_films ( & self , films : Vec <Film> ) {
|
||||
* self . films . borrow_mut () = films ;
|
||||
self . flow_box . set_films ( self . films . borrow () . as_slice () ) ;
|
||||
}
|
||||
|
||||
pub fn get_widget ( & self ) -> & gtk4 :: Box { & self . widget }
|
||||
|
|
|
@ -4,6 +4,7 @@ use {
|
|||
Align :: * ,
|
||||
Orientation :: * ,
|
||||
gdk :: Texture ,
|
||||
glib :: * ,
|
||||
prelude :: * ,
|
||||
} ,
|
||||
libadwaita :: { * , ViewSwitcherPolicy :: * } ,
|
||||
|
@ -62,7 +63,12 @@ impl FilmsFlowBox {
|
|||
pub fn set_films ( & self , films : & [Film] ) {
|
||||
self . widget . remove_all () ;
|
||||
for film in films {
|
||||
self . widget . append ( & create_film_item (film) ) ;
|
||||
let widget = self . widget . clone () ;
|
||||
let film = film . clone () ;
|
||||
|
||||
spawn_future_local ( async move {
|
||||
widget . append ( & create_film_item ( & film ) ) ;
|
||||
} ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +161,7 @@ fn create_collection_item (
|
|||
. build () ;
|
||||
|
||||
if let Some (poster_file_path) = poster_file_path {
|
||||
if let Ok (poster_texture) = Texture :: from_filename (poster_file_path) {
|
||||
let poster_texture = Texture :: from_filename (poster_file_path) . unwrap () ;
|
||||
container . append (
|
||||
& Image :: builder ()
|
||||
. paintable ( & poster_texture )
|
||||
|
@ -165,7 +171,6 @@ fn create_collection_item (
|
|||
. build ()
|
||||
) ;
|
||||
}
|
||||
}
|
||||
|
||||
container . append (
|
||||
& Label :: builder ()
|
||||
|
|
Loading…
Add table
Reference in a new issue