2025-01-31 11:38:06 +01:00
|
|
|
mod collated_grid ;
|
|
|
|
|
mod collation_menu ;
|
|
|
|
|
|
|
|
|
|
use gtk4 :: { * , Orientation :: * , prelude :: * } ;
|
2024-11-20 17:18:22 +01:00
|
|
|
|
|
|
|
|
use crate :: {
|
|
|
|
|
collection :: * ,
|
2024-11-27 15:22:55 +01:00
|
|
|
ui :: {
|
2025-01-31 11:38:06 +01:00
|
|
|
collatable_container :: { collated_grid :: * , collation_menu :: * } ,
|
2024-11-27 15:22:55 +01:00
|
|
|
component :: * ,
|
|
|
|
|
utility :: * ,
|
|
|
|
|
} ,
|
2024-11-20 17:18:22 +01:00
|
|
|
utility :: * ,
|
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
2024-11-26 16:49:19 +01:00
|
|
|
|
2025-01-31 11:38:06 +01:00
|
|
|
# [ derive (PartialEq) ] pub enum FilmsSortedBy { Name , ReleaseDate , Runtime }
|
|
|
|
|
# [ derive (PartialEq) ] pub enum SeriesSortedBy { Name , FirstReleaseDate }
|
|
|
|
|
# [ derive (PartialEq) ] pub enum SortingDirection { Ascending , Descending }
|
|
|
|
|
|
2024-11-26 17:20:53 +01:00
|
|
|
pub struct CollatableFilmsContainer {
|
2024-11-27 11:47:20 +01:00
|
|
|
collated_grid : & 'static CollatedFilmsGrid ,
|
2024-11-27 15:22:55 +01:00
|
|
|
widget : Box ,
|
2024-11-20 17:18:22 +01:00
|
|
|
}
|
2024-11-26 17:20:53 +01:00
|
|
|
pub struct CollatableSeriesContainer {
|
2024-11-27 11:47:20 +01:00
|
|
|
collated_grid : & 'static CollatedSeriesGrid ,
|
2024-11-27 15:22:55 +01:00
|
|
|
widget : Box ,
|
2024-11-20 17:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-26 17:20:53 +01:00
|
|
|
impl CollatableFilmsContainer {
|
2024-11-20 17:18:22 +01:00
|
|
|
pub fn new ( films : Vec <Film> ) -> Self {
|
2024-11-27 15:22:55 +01:00
|
|
|
let collated_grid = leak (
|
2025-01-30 17:56:43 +01:00
|
|
|
CollatedFilmsGrid :: new ( films , FilmsSortedBy :: Name , SortingDirection :: Ascending ) ) ;
|
|
|
|
|
let film_collation_menu = FilmCollationMenu :: new ( | sorting , direction |
|
|
|
|
|
collated_grid . set_sorting ( sorting , direction ) ) ;
|
2024-11-27 15:22:55 +01:00
|
|
|
|
2025-01-31 11:38:06 +01:00
|
|
|
let widget = g_box ! (
|
|
|
|
|
@ orientation : Vertical ,
|
2024-11-27 15:22:55 +01:00
|
|
|
film_collation_menu . get_widget () ,
|
2024-11-27 11:47:20 +01:00
|
|
|
& create_collection_scrolled_window ( collated_grid . get_widget () ) ,
|
2024-11-20 17:18:22 +01:00
|
|
|
) ;
|
|
|
|
|
|
2024-11-27 11:47:20 +01:00
|
|
|
Self { collated_grid , widget }
|
2024-11-20 17:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-26 16:49:19 +01:00
|
|
|
pub fn set_films ( & self , films : Vec <Film> ) {
|
2025-01-30 17:56:43 +01:00
|
|
|
self . collated_grid . set_films ( films , FilmsSortedBy :: Name , SortingDirection :: Ascending ) ;
|
2024-11-20 17:18:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-11-26 17:20:53 +01:00
|
|
|
impl CollatableSeriesContainer {
|
2024-11-20 17:18:22 +01:00
|
|
|
pub fn new ( series : Vec <Series> ) -> Self {
|
2024-11-27 15:22:55 +01:00
|
|
|
let collated_grid = leak (
|
|
|
|
|
CollatedSeriesGrid :: new ( series , SeriesSortedBy :: Name ) ) ;
|
|
|
|
|
let series_collation_menu = SeriesCollationMenu :: new ( |sorted_by| {
|
|
|
|
|
collated_grid . set_sorting (sorted_by) ;
|
|
|
|
|
} ) ;
|
|
|
|
|
|
2025-01-31 11:38:06 +01:00
|
|
|
let widget = g_box ! (
|
|
|
|
|
@ orientation : Vertical ,
|
2024-11-27 15:22:55 +01:00
|
|
|
series_collation_menu . get_widget () ,
|
2024-11-27 11:47:20 +01:00
|
|
|
& create_collection_scrolled_window ( collated_grid . get_widget () ) ,
|
2024-11-20 17:18:22 +01:00
|
|
|
) ;
|
|
|
|
|
|
2024-11-27 11:47:20 +01:00
|
|
|
Self { collated_grid , widget }
|
2024-11-20 17:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-27 11:47:20 +01:00
|
|
|
pub fn set_series ( & self , series : Vec <Series> ) {
|
|
|
|
|
self . collated_grid . set_series ( series , SeriesSortedBy :: Name ) ;
|
2024-11-20 17:18:22 +01:00
|
|
|
}
|
2024-11-27 15:22:55 +01:00
|
|
|
}
|
2024-11-20 17:18:22 +01:00
|
|
|
|
2024-11-27 15:22:55 +01:00
|
|
|
impl Component <Box> for CollatableFilmsContainer {
|
|
|
|
|
fn get_widget ( & self ) -> & Box { & self . widget }
|
|
|
|
|
}
|
|
|
|
|
impl Component <Box> for CollatableSeriesContainer {
|
|
|
|
|
fn get_widget ( & self ) -> & Box { & self . widget }
|
2024-11-20 17:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-27 11:47:20 +01:00
|
|
|
fn create_collection_scrolled_window ( child : & FlowBox ) -> ScrolledWindow {
|
2024-11-20 17:18:22 +01:00
|
|
|
ScrolledWindow :: builder ()
|
2025-01-31 11:38:06 +01:00
|
|
|
. child ( & vertically_filling ! (child) )
|
2024-11-20 17:18:22 +01:00
|
|
|
. propagate_natural_height (true)
|
|
|
|
|
. build ()
|
|
|
|
|
}
|