Move collation components into submodules
This commit is contained in:
parent
5cccefbd4a
commit
ebc8bc0d2f
7 changed files with 85 additions and 44 deletions
85
src/ui/collatable_container/mod.rs
Normal file
85
src/ui/collatable_container/mod.rs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
mod collated_grid ;
|
||||
mod collation_menu ;
|
||||
|
||||
use gtk4 :: { * , Orientation :: * , prelude :: * } ;
|
||||
|
||||
use crate :: {
|
||||
collection :: * ,
|
||||
ui :: {
|
||||
collatable_container :: { collated_grid :: * , collation_menu :: * } ,
|
||||
component :: * ,
|
||||
utility :: * ,
|
||||
} ,
|
||||
utility :: * ,
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
# [ derive (PartialEq) ] pub enum FilmsSortedBy { Name , ReleaseDate , Runtime }
|
||||
# [ derive (PartialEq) ] pub enum SeriesSortedBy { Name , FirstReleaseDate }
|
||||
# [ derive (PartialEq) ] pub enum SortingDirection { Ascending , Descending }
|
||||
|
||||
pub struct CollatableFilmsContainer {
|
||||
collated_grid : & 'static CollatedFilmsGrid ,
|
||||
widget : Box ,
|
||||
}
|
||||
pub struct CollatableSeriesContainer {
|
||||
collated_grid : & 'static CollatedSeriesGrid ,
|
||||
widget : Box ,
|
||||
}
|
||||
|
||||
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 ) ) ;
|
||||
|
||||
let widget = g_box ! (
|
||||
@ orientation : Vertical ,
|
||||
film_collation_menu . get_widget () ,
|
||||
& create_collection_scrolled_window ( 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 ) ;
|
||||
}
|
||||
}
|
||||
impl CollatableSeriesContainer {
|
||||
pub fn new ( series : Vec <Series> ) -> Self {
|
||||
let collated_grid = leak (
|
||||
CollatedSeriesGrid :: new ( series , SeriesSortedBy :: Name ) ) ;
|
||||
let series_collation_menu = SeriesCollationMenu :: new ( |sorted_by| {
|
||||
collated_grid . set_sorting (sorted_by) ;
|
||||
} ) ;
|
||||
|
||||
let widget = g_box ! (
|
||||
@ orientation : Vertical ,
|
||||
series_collation_menu . get_widget () ,
|
||||
& create_collection_scrolled_window ( collated_grid . get_widget () ) ,
|
||||
) ;
|
||||
|
||||
Self { collated_grid , widget }
|
||||
}
|
||||
|
||||
pub fn set_series ( & self , series : Vec <Series> ) {
|
||||
self . collated_grid . set_series ( series , SeriesSortedBy :: Name ) ;
|
||||
}
|
||||
}
|
||||
|
||||
impl Component <Box> for CollatableFilmsContainer {
|
||||
fn get_widget ( & self ) -> & Box { & self . widget }
|
||||
}
|
||||
impl Component <Box> for CollatableSeriesContainer {
|
||||
fn get_widget ( & self ) -> & Box { & self . widget }
|
||||
}
|
||||
|
||||
fn create_collection_scrolled_window ( child : & FlowBox ) -> ScrolledWindow {
|
||||
ScrolledWindow :: builder ()
|
||||
. child ( & vertically_filling ! (child) )
|
||||
. propagate_natural_height (true)
|
||||
. build ()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue