Move films and series containers into separate file
This commit is contained in:
parent
57c1db59b2
commit
f912281700
4 changed files with 84 additions and 81 deletions
|
@ -8,7 +8,7 @@ use {
|
||||||
libadwaita :: * ,
|
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 ()
|
ListBoxRow :: builder () . child ( & container ) . build ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
75
src/ui/dynamic_container.rs
Normal file
75
src/ui/dynamic_container.rs
Normal 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 ()
|
||||||
|
}
|
|
@ -1,27 +1,16 @@
|
||||||
use {
|
use {
|
||||||
gtk4 :: {
|
gtk4 :: {
|
||||||
FlowBox,
|
FlowBox, HeaderBar, Image, Justification, Label, SelectionMode,
|
||||||
HeaderBar,
|
|
||||||
Image,
|
|
||||||
Justification,
|
|
||||||
Label,
|
|
||||||
ScrolledWindow,
|
|
||||||
SelectionMode,
|
|
||||||
Widget,
|
|
||||||
Align :: * ,
|
Align :: * ,
|
||||||
Orientation :: * ,
|
Orientation :: * ,
|
||||||
gdk :: Texture ,
|
gdk :: Texture ,
|
||||||
prelude :: * ,
|
prelude :: * ,
|
||||||
} ,
|
} ,
|
||||||
libadwaita :: { * , ViewSwitcherPolicy :: * } ,
|
libadwaita :: { * , ViewSwitcherPolicy :: * } ,
|
||||||
std :: { cell :: * , path :: * } ,
|
std :: path :: * ,
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
use crate :: {
|
use crate :: collection :: * ;
|
||||||
collection :: * ,
|
|
||||||
ui :: { collection_menu :: * , utility :: * } ,
|
|
||||||
utility :: * ,
|
|
||||||
} ;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,70 +97,6 @@ fn create_collection_flow_box () -> FlowBox {
|
||||||
. build ()
|
. 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 {
|
pub fn create_film_item ( film : & Film ) -> gtk4 :: Box {
|
||||||
create_collection_item (
|
create_collection_item (
|
||||||
film . name . as_str () ,
|
film . name . as_str () ,
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
mod collection_menu ;
|
mod collection_menu ;
|
||||||
|
mod dynamic_container ;
|
||||||
mod internal ;
|
mod internal ;
|
||||||
mod utility ;
|
mod utility ;
|
||||||
|
|
||||||
use { gtk4 :: prelude :: * , libadwaita :: * } ;
|
use { gtk4 :: prelude :: * , libadwaita :: * } ;
|
||||||
|
|
||||||
use crate :: { collection :: * , ui :: { internal :: * , utility :: * } } ;
|
use crate :: {
|
||||||
|
collection :: * ,
|
||||||
|
ui :: { dynamic_container :: * , internal :: * , utility :: * } ,
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue