Introduce sorting structs

This commit is contained in:
Reinout Meliesie 2025-01-31 16:24:22 +01:00
commit e2330cae50
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
5 changed files with 106 additions and 71 deletions

View file

@ -14,11 +14,34 @@ use crate :: {
# [ derive ( Clone , Copy , PartialEq ) ] pub enum FilmsSortedBy { Name , ReleaseDate , Runtime }
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SeriesSortedBy { Name , FirstReleaseDate }
# [ derive ( Clone , Copy , PartialEq ) ] pub enum FilmProperty { Name , ReleaseDate , Runtime }
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SeriesProperty { Name , FirstReleaseDate }
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SortingDirection { Ascending , Descending }
pub struct FilmSorting { property : FilmsSortedBy , direction : SortingDirection }
# [ derive ( Clone , Copy ) ] pub struct FilmsSorting { property : FilmProperty , direction : SortingDirection }
# [ derive ( Clone , Copy ) ] pub struct SeriesSorting { property : SeriesProperty , direction : SortingDirection }
impl FilmsSorting {
pub fn new ( property : FilmProperty , direction : SortingDirection ) -> Self { Self { property , direction } }
}
impl SeriesSorting {
pub fn new ( property : SeriesProperty , direction : SortingDirection ) -> Self { Self { property , direction } }
}
impl Default for FilmsSorting {
fn default () -> Self { Self {
property : FilmProperty :: Name ,
direction : SortingDirection :: Ascending ,
} }
}
impl Default for SeriesSorting {
fn default () -> Self { Self {
property : SeriesProperty :: Name ,
direction : SortingDirection :: Ascending ,
} }
}
pub struct CollatableFilmsContainer {
collated_grid : & 'static CollatedFilmsGrid ,
@ -32,27 +55,30 @@ pub struct CollatableSeriesContainer {
impl CollatableFilmsContainer {
pub fn new ( films : Vec <Film> ) -> Self {
let collated_grid = leak (
CollatedFilmsGrid :: new ( films , FilmsSortedBy :: Name , SortingDirection :: Ascending ) ) ;
let film_collation_menu = FilmCollationMenu :: new ( | sorting , direction |
collated_grid . set_sorting ( sorting , direction ) ) ;
CollatedFilmsGrid :: new ( films , FilmsSorting :: default () ) ) ;
let film_collation_menu = FilmCollationMenu :: new ( |sorting|
collated_grid . set_sorting (sorting) ) ;
let widget = g_box ! (
@ orientation : Vertical ,
* film_collation_menu . get_widget () ,
create_collection_scrolled_window ( collated_grid . get_widget () ) ,
scrolled_window ! (
@ propagate_natural_height : true ,
vertically_filling ! ( * collated_grid . get_widget () ) ,
) ,
) ;
Self { collated_grid , widget }
}
pub fn set_films ( & self , films : Vec <Film> ) {
self . collated_grid . set_films ( films , FilmsSortedBy :: Name , SortingDirection :: Ascending ) ;
self . collated_grid . set_films ( films , FilmsSorting :: default () ) ;
}
}
impl CollatableSeriesContainer {
pub fn new ( series : Vec <Series> ) -> Self {
let collated_grid = leak (
CollatedSeriesGrid :: new ( series , SeriesSortedBy :: Name ) ) ;
CollatedSeriesGrid :: new ( series , SeriesSorting :: default () ) ) ;
let series_collation_menu = SeriesCollationMenu :: new ( |sorted_by| {
collated_grid . set_sorting (sorted_by) ;
} ) ;
@ -67,7 +93,7 @@ impl CollatableSeriesContainer {
}
pub fn set_series ( & self , series : Vec <Series> ) {
self . collated_grid . set_series ( series , SeriesSortedBy :: Name ) ;
self . collated_grid . set_series ( series , SeriesSorting :: default () ) ;
}
}