zoodex/src/ui/collatable_container/mod.rs

85 lines
2.5 KiB
Rust
Raw Normal View History

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 (
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 ) ) ;
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> ) {
2025-01-30 17:56:43 +01:00
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 ()
}