zoodex/src/ui/collatable_container/mod.rs

116 lines
3.1 KiB
Rust
Raw Normal View History

mod collated_grid ;
mod collation_menu ;
use gtk4 :: { * , Orientation :: * , prelude :: * } ;
use crate :: {
2025-02-05 00:03:26 +01:00
data_manager :: * ,
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 17:38:52 +01:00
# [ derive ( Clone , Copy ) ] pub struct FilmsSorting {
property : FilmProperty ,
direction : SortingDirection ,
}
# [ derive ( Clone , Copy ) ] pub struct SeriesSorting {
property : SeriesProperty ,
direction : SortingDirection ,
}
2025-01-31 16:24:22 +01:00
impl FilmsSorting {
2025-01-31 17:38:52 +01:00
pub fn new ( property : FilmProperty , direction : SortingDirection ) -> Self {
Self { property , direction }
}
2025-01-31 16:24:22 +01:00
}
impl SeriesSorting {
2025-01-31 17:38:52 +01:00
pub fn new ( property : SeriesProperty , direction : SortingDirection ) -> Self {
Self { property , direction }
}
2025-01-31 16:24:22 +01:00
}
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 {
2025-02-05 13:51:22 +01:00
pub fn new () -> Self {
let collated_grid = leak ( CollatedFilmsGrid :: new () ) ;
2025-01-31 16:24:22 +01:00
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 ;
2025-01-31 16:24:22 +01:00
vertically_filling ! ( * collated_grid . get_widget () ) ,
) ,
) ;
Self { collated_grid , widget }
}
2025-02-05 13:51:22 +01:00
pub async fn set_films ( & self , films : Vec <FilmOverview> ) {
self . collated_grid . set_films ( films , FilmsSorting :: default () ) . await ;
}
}
impl CollatableSeriesContainer {
2025-02-05 13:51:22 +01:00
pub fn new () -> Self {
let collated_grid = leak ( CollatedSeriesGrid :: new () ) ;
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 ;
2025-01-31 17:09:22 +01:00
vertically_filling ! ( * collated_grid . get_widget () ) ,
) ,
) ;
Self { collated_grid , widget }
}
2025-02-05 13:51:22 +01:00
pub async fn set_series ( & self , series : Vec <SeriesOverview> ) {
self . collated_grid . set_series ( series , SeriesSorting :: default () ) . await ;
}
}
impl Component <Box> for CollatableFilmsContainer {
fn get_widget ( & self ) -> & Box { & self . widget }
}
impl Component <Box> for CollatableSeriesContainer {
fn get_widget ( & self ) -> & Box { & self . widget }
}