75 lines
2 KiB
Rust
75 lines
2 KiB
Rust
|
|
use {
|
||
|
|
gtk4 :: { ScrolledWindow, Widget, prelude :: * } ,
|
||
|
|
std :: cell :: * ,
|
||
|
|
} ;
|
||
|
|
|
||
|
|
use crate :: {
|
||
|
|
collection :: * ,
|
||
|
|
ui :: { collection_menu :: * , internal :: * , utility :: * } ,
|
||
|
|
utility :: * ,
|
||
|
|
} ;
|
||
|
|
|
||
|
|
|
||
|
|
pub enum FilmsSortedBy { Name , ReleaseDate , Runtime }
|
||
|
|
pub enum SeriesSortedBy { Name , FirstReleaseDate }
|
||
|
|
|
||
|
|
pub struct FilmsContainer {
|
||
|
|
films : Vec <Film> ,
|
||
|
|
flow_box : FilmsFlowBox ,
|
||
|
|
widget : gtk4 :: Box ,
|
||
|
|
sorted_by : & 'static Cell <FilmsSortedBy> ,
|
||
|
|
}
|
||
|
|
pub struct SeriesContainer {
|
||
|
|
series : Vec <Series> ,
|
||
|
|
flow_box : SeriesFlowBox ,
|
||
|
|
widget : gtk4 :: Box ,
|
||
|
|
}
|
||
|
|
|
||
|
|
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 widget = create_vertical_box ! (
|
||
|
|
& create_film_collection_menu ( |new_sorted_by| {
|
||
|
|
sorted_by . replace (new_sorted_by) ;
|
||
|
|
} ) ,
|
||
|
|
& create_collection_scrolled_window ( flow_box . get_widget () ) ,
|
||
|
|
) ;
|
||
|
|
|
||
|
|
Self { films , flow_box , widget , sorted_by }
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn set_films ( & mut self , films : Vec <Film> ) {
|
||
|
|
self . films = films ;
|
||
|
|
self . flow_box . set_films ( self . films . as_slice () ) ;
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn get_widget ( & self ) -> & gtk4 :: Box { & self . widget }
|
||
|
|
}
|
||
|
|
impl SeriesContainer {
|
||
|
|
pub fn new ( series : Vec <Series> ) -> Self {
|
||
|
|
let flow_box = SeriesFlowBox :: new ( series . as_slice () ) ;
|
||
|
|
let widget = create_vertical_box ! (
|
||
|
|
& create_series_collection_menu ( |sorted_by| {
|
||
|
|
// TODO
|
||
|
|
} ) ,
|
||
|
|
& create_collection_scrolled_window ( flow_box . get_widget () ) ,
|
||
|
|
) ;
|
||
|
|
|
||
|
|
Self { series, flow_box , widget }
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn set_series ( & mut self , series : Vec <Series> ) {
|
||
|
|
self . series = series ;
|
||
|
|
self . flow_box . set_series ( self . series . as_slice () ) ;
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn get_widget ( & self ) -> & gtk4 :: Box { & self . widget }
|
||
|
|
}
|
||
|
|
|
||
|
|
fn create_collection_scrolled_window ( child : & impl IsA <Widget> ) -> ScrolledWindow {
|
||
|
|
ScrolledWindow :: builder ()
|
||
|
|
. child ( & create_vertical_filler_container (child) )
|
||
|
|
. propagate_natural_height (true)
|
||
|
|
. build ()
|
||
|
|
}
|