Move films and series containers into separate file

This commit is contained in:
Reinout Meliesie 2024-11-20 17:18:22 +01:00
parent 57c1db59b2
commit f912281700
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
4 changed files with 84 additions and 81 deletions

View file

@ -8,7 +8,7 @@ use {
libadwaita :: * ,
} ;
use crate :: ui :: { internal :: * , utility :: * } ;
use crate :: ui :: { dynamic_container :: * , utility :: * } ;
@ -112,4 +112,3 @@ fn create_sort_menu_entry ( label : & str , reverse : bool , selected : bool ) -
ListBoxRow :: builder () . child ( & container ) . build ()
}

View file

@ -0,0 +1,75 @@
use {
gtk4 :: { ScrolledWindow, Widget, prelude :: * } ,
std :: cell :: * ,
} ;
use crate :: {
collection :: * ,
ui :: { collection_menu :: * , internal :: * , utility :: * } ,
utility :: * ,
} ;
pub enum FilmsSortedBy { Name , ReleaseDate , Runtime }
pub enum SeriesSortedBy { Name , FirstReleaseDate }
pub struct FilmsContainer {
films : Vec <Film> ,
flow_box : FilmsFlowBox ,
widget : gtk4 :: Box ,
sorted_by : & 'static Cell <FilmsSortedBy> ,
}
pub struct SeriesContainer {
series : Vec <Series> ,
flow_box : SeriesFlowBox ,
widget : gtk4 :: Box ,
}
impl FilmsContainer {
pub fn new ( films : Vec <Film> ) -> Self {
let flow_box = FilmsFlowBox :: new ( films . as_slice () ) ;
let sorted_by = leak ( Cell :: new ( FilmsSortedBy :: Name ) ) ;
let widget = create_vertical_box ! (
& create_film_collection_menu ( |new_sorted_by| {
sorted_by . replace (new_sorted_by) ;
} ) ,
& create_collection_scrolled_window ( flow_box . get_widget () ) ,
) ;
Self { films , flow_box , widget , sorted_by }
}
pub fn set_films ( & mut self , films : Vec <Film> ) {
self . films = films ;
self . flow_box . set_films ( self . films . as_slice () ) ;
}
pub fn get_widget ( & self ) -> & gtk4 :: Box { & self . widget }
}
impl SeriesContainer {
pub fn new ( series : Vec <Series> ) -> Self {
let flow_box = SeriesFlowBox :: new ( series . as_slice () ) ;
let widget = create_vertical_box ! (
& create_series_collection_menu ( |sorted_by| {
// TODO
} ) ,
& create_collection_scrolled_window ( flow_box . get_widget () ) ,
) ;
Self { series, flow_box , widget }
}
pub fn set_series ( & mut self , series : Vec <Series> ) {
self . series = series ;
self . flow_box . set_series ( self . series . as_slice () ) ;
}
pub fn get_widget ( & self ) -> & gtk4 :: Box { & self . widget }
}
fn create_collection_scrolled_window ( child : & impl IsA <Widget> ) -> ScrolledWindow {
ScrolledWindow :: builder ()
. child ( & create_vertical_filler_container (child) )
. propagate_natural_height (true)
. build ()
}

View file

@ -1,27 +1,16 @@
use {
gtk4 :: {
FlowBox,
HeaderBar,
Image,
Justification,
Label,
ScrolledWindow,
SelectionMode,
Widget,
FlowBox, HeaderBar, Image, Justification, Label, SelectionMode,
Align :: * ,
Orientation :: * ,
gdk :: Texture ,
prelude :: * ,
} ,
libadwaita :: { * , ViewSwitcherPolicy :: * } ,
std :: { cell :: * , path :: * } ,
std :: path :: * ,
} ;
use crate :: {
collection :: * ,
ui :: { collection_menu :: * , utility :: * } ,
utility :: * ,
} ;
use crate :: collection :: * ;
@ -108,70 +97,6 @@ fn create_collection_flow_box () -> FlowBox {
. build ()
}
pub enum FilmsSortedBy { Name , ReleaseDate , Runtime }
pub enum SeriesSortedBy { Name , FirstReleaseDate }
pub struct FilmsContainer {
films : Vec <Film> ,
flow_box : FilmsFlowBox ,
widget : gtk4 :: Box ,
sorted_by : & 'static Cell <FilmsSortedBy> ,
}
pub struct SeriesContainer {
series : Vec <Series> ,
flow_box : SeriesFlowBox ,
widget : gtk4 :: Box ,
}
impl FilmsContainer {
pub fn new ( films : Vec <Film> ) -> Self {
let flow_box = FilmsFlowBox :: new ( films . as_slice () ) ;
let sorted_by = leak ( Cell :: new ( FilmsSortedBy :: Name ) ) ;
let widget = create_vertical_box ! (
& create_film_collection_menu ( |new_sorted_by| {
sorted_by . replace (new_sorted_by) ;
} ) ,
& create_collection_scrolled_window ( flow_box . get_widget () ) ,
) ;
Self { films , flow_box , widget , sorted_by }
}
pub fn set_films ( & mut self , films : Vec <Film> ) {
self . films = films ;
self . flow_box . set_films ( self . films . as_slice () ) ;
}
pub fn get_widget ( & self ) -> & gtk4 :: Box { & self . widget }
}
impl SeriesContainer {
pub fn new ( series : Vec <Series> ) -> Self {
let flow_box = SeriesFlowBox :: new ( series . as_slice () ) ;
let widget = create_vertical_box ! (
& create_series_collection_menu ( |sorted_by| {
// TODO
} ) ,
& create_collection_scrolled_window ( flow_box . get_widget () ) ,
) ;
Self { series, flow_box , widget }
}
pub fn set_series ( & mut self , series : Vec <Series> ) {
self . series = series ;
self . flow_box . set_series ( self . series . as_slice () ) ;
}
pub fn get_widget ( & self ) -> & gtk4 :: Box { & self . widget }
}
fn create_collection_scrolled_window ( child : & impl IsA <Widget> ) -> ScrolledWindow {
ScrolledWindow :: builder ()
. child ( & create_vertical_filler_container (child) )
. propagate_natural_height (true)
. build ()
}
pub fn create_film_item ( film : & Film ) -> gtk4 :: Box {
create_collection_item (
film . name . as_str () ,

View file

@ -1,10 +1,14 @@
mod collection_menu ;
mod dynamic_container ;
mod internal ;
mod utility ;
use { gtk4 :: prelude :: * , libadwaita :: * } ;
use crate :: { collection :: * , ui :: { internal :: * , utility :: * } } ;
use crate :: {
collection :: * ,
ui :: { dynamic_container :: * , internal :: * , utility :: * } ,
} ;