zoodex/src/ui/collatable_container/mod.rs

108 lines
3.2 KiB
Rust
Raw Normal View History

mod collated_grid ;
mod collation_menu ;
use gtk4 :: { * , Orientation :: * , prelude :: * } ;
use crate :: {
collection :: * ,
ui :: {
component :: * , utility :: * ,
collatable_container :: { collated_grid :: * , collation_menu :: * } ,
} ,
utility :: * ,
} ;
2025-01-31 16:24:22 +01:00
# [ derive ( Clone , Copy , PartialEq ) ] pub enum FilmProperty { Name , ReleaseDate , Runtime }
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SeriesProperty { Name , FirstReleaseDate }
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SortingDirection { Ascending , Descending }
2025-01-31 16:24:22 +01:00
# [ derive ( Clone , Copy ) ] pub struct FilmsSorting { property : FilmProperty , direction : SortingDirection }
# [ derive ( Clone , Copy ) ] pub struct SeriesSorting { property : SeriesProperty , direction : SortingDirection }
impl FilmsSorting {
pub fn new ( property : FilmProperty , direction : SortingDirection ) -> Self { Self { property , direction } }
}
impl SeriesSorting {
pub fn new ( property : SeriesProperty , direction : SortingDirection ) -> Self { Self { property , direction } }
}
impl Default for FilmsSorting {
fn default () -> Self { Self {
property : FilmProperty :: Name ,
direction : SortingDirection :: Ascending ,
} }
}
impl Default for SeriesSorting {
fn default () -> Self { Self {
property : SeriesProperty :: Name ,
direction : SortingDirection :: Ascending ,
} }
}
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-31 16:24:22 +01:00
CollatedFilmsGrid :: new ( films , FilmsSorting :: default () ) ) ;
let film_collation_menu = FilmCollationMenu :: new ( |sorting|
collated_grid . set_sorting (sorting) ) ;
let widget = g_box ! (
@ orientation : Vertical ,
* film_collation_menu . get_widget () ,
2025-01-31 16:24:22 +01:00
scrolled_window ! (
@ propagate_natural_height : true ,
vertically_filling ! ( * collated_grid . get_widget () ) ,
) ,
) ;
Self { collated_grid , widget }
}
pub fn set_films ( & self , films : Vec <Film> ) {
2025-01-31 16:24:22 +01:00
self . collated_grid . set_films ( films , FilmsSorting :: default () ) ;
}
}
impl CollatableSeriesContainer {
pub fn new ( series : Vec <Series> ) -> Self {
let collated_grid = leak (
2025-01-31 16:24:22 +01:00
CollatedSeriesGrid :: new ( series , SeriesSorting :: default () ) ) ;
2025-01-31 17:09:22 +01:00
let series_collation_menu = SeriesCollationMenu :: new ( |sorting| {
collated_grid . set_sorting (sorting) ;
} ) ;
let widget = g_box ! (
@ orientation : Vertical ,
* series_collation_menu . get_widget () ,
2025-01-31 17:09:22 +01:00
scrolled_window ! (
@ propagate_natural_height : true ,
vertically_filling ! ( * collated_grid . get_widget () ) ,
) ,
) ;
Self { collated_grid , widget }
}
pub fn set_series ( & self , series : Vec <Series> ) {
2025-01-31 16:24:22 +01:00
self . collated_grid . set_series ( series , SeriesSorting :: default () ) ;
}
}
impl Component <Box> for CollatableFilmsContainer {
fn get_widget ( & self ) -> & Box { & self . widget }
}
impl Component <Box> for CollatableSeriesContainer {
fn get_widget ( & self ) -> & Box { & self . widget }
}