zoodex/src/ui/collatable_container/mod.rs

115 lines
3.2 KiB
Rust
Raw Normal View History

mod collated_grid ;
mod collation_menu ;
2025-02-05 14:57:07 +01:00
use gtk4 :: * ;
use gtk4 :: Orientation :: * ;
use gtk4 :: prelude :: * ;
use crate :: data_manager :: * ;
use crate :: ui :: component :: * ;
use crate :: ui :: utility :: * ;
use crate :: ui :: collatable_container :: collated_grid :: * ;
use crate :: ui :: collatable_container :: collation_menu :: * ;
use crate :: 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 () ,
& scrolled_window ! (
@ propagate_natural_height : true ;
& vertically_filling ! ( collated_grid . get_widget () ) ,
2025-01-31 16:24:22 +01:00
) ,
) ;
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 () ) ;
let series_collation_menu = SeriesCollationMenu :: new ( |sorting|
collated_grid . set_sorting (sorting) ) ;
let widget = g_box ! (
@ orientation : Vertical ;
series_collation_menu . get_widget () ,
& scrolled_window ! (
@ propagate_natural_height : true ;
& vertically_filling ! ( collated_grid . get_widget () ) ,
2025-01-31 17:09:22 +01:00
) ,
) ;
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 }
}