diff --git a/src/ui/collection_menu.rs b/src/ui/collection_menu.rs index 38675e4..457d6cf 100644 --- a/src/ui/collection_menu.rs +++ b/src/ui/collection_menu.rs @@ -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 () } - diff --git a/src/ui/dynamic_container.rs b/src/ui/dynamic_container.rs new file mode 100644 index 0000000..5083b75 --- /dev/null +++ b/src/ui/dynamic_container.rs @@ -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 , + flow_box : FilmsFlowBox , + widget : gtk4 :: Box , + sorted_by : & 'static Cell , +} +pub struct SeriesContainer { + series : Vec , + flow_box : SeriesFlowBox , + widget : gtk4 :: Box , +} + +impl FilmsContainer { + pub fn new ( films : Vec ) -> 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 ) { + 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 ) -> 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 ) { + 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 ) -> ScrolledWindow { + ScrolledWindow :: builder () + . child ( & create_vertical_filler_container (child) ) + . propagate_natural_height (true) + . build () +} diff --git a/src/ui/internal.rs b/src/ui/internal.rs index 63b9d3c..e4fe47a 100644 --- a/src/ui/internal.rs +++ b/src/ui/internal.rs @@ -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 , - flow_box : FilmsFlowBox , - widget : gtk4 :: Box , - sorted_by : & 'static Cell , -} -pub struct SeriesContainer { - series : Vec , - flow_box : SeriesFlowBox , - widget : gtk4 :: Box , -} - -impl FilmsContainer { - pub fn new ( films : Vec ) -> 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 ) { - 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 ) -> 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 ) { - 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 ) -> 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 () , diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 4190518..dcc8d70 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -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 :: * } , +} ;