zoodex/src/ui/collatable_container.rs

77 lines
2.1 KiB
Rust
Raw Normal View History

use gtk4 :: { * , prelude :: * } ;
use crate :: {
collection :: * ,
ui :: {
collated_grid :: * ,
collation_menu :: * ,
component :: * ,
utility :: * ,
} ,
utility :: * ,
} ;
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 = create_vertical_box ! (
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 = create_vertical_box ! (
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 ( & create_vertical_filler_container (child) )
. propagate_natural_height (true)
. build ()
}