Move collation components into submodules

This commit is contained in:
Reinout Meliesie 2025-01-31 11:38:06 +01:00
parent 5cccefbd4a
commit ebc8bc0d2f
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
7 changed files with 85 additions and 44 deletions

View file

@ -9,14 +9,10 @@ use {
std :: { cell :: * , iter :: * , path :: Path } ,
} ;
use crate :: { collection :: * , ui :: component :: * } ;
use crate :: { collection :: * , ui :: { collatable_container :: * , component :: * } } ;
# [ derive (PartialEq) ] pub enum FilmsSortedBy { Name , ReleaseDate , Runtime }
# [ derive (PartialEq) ] pub enum SeriesSortedBy { Name , FirstReleaseDate }
# [ derive (PartialEq) ] pub enum SortingDirection { Ascending , Descending }
pub struct CollatedFilmsGrid {
film_widget_pairs : RefCell < Vec < ( Film , Box ) > > ,
grid_widget : FlowBox ,

View file

@ -1,3 +1,5 @@
mod sort_button ;
use {
gtk4 :: {
Box , Image , Label , ListBox , ListBoxRow , Popover ,
@ -10,7 +12,7 @@ use {
} ;
use crate :: {
ui :: { collated_grid :: * , component :: * , utility :: * } ,
ui :: { collatable_container :: * , component :: * , utility :: * } ,
utility :: * ,
} ;
@ -64,7 +66,7 @@ impl Component <Box> for SeriesCollationMenu {
fn create_sort_button ( sort_menu : & Popover ) -> SplitButton {
SplitButton :: builder ()
. child ( & create_label ("Sort") )
. child ( & label ! ("Sort") )
. popover (sort_menu)
. build ()
}
@ -122,7 +124,8 @@ fn create_sort_menu_entry ( label : & str , reverse : bool ) -> ListBoxRow {
true => Image :: from_icon_name ("view-sort-descending-symbolic") ,
} ;
let container = create_horizontal_box ! (
let container = g_box ! (
@ orientation : Horizontal ,
& Label :: builder ()
. label (label)
. hexpand (true)

View file

@ -0,0 +1,21 @@
use libadwaita :: * ;
use crate :: ui :: { * , utility :: * } ;
pub struct FilmSortButton { widget : SplitButton }
impl FilmSortButton {
pub fn new () -> Self {
let widget = SplitButton :: builder ()
. child ( & label ! ("Sort") )
. build () ;
Self { widget }
}
}
impl Component <SplitButton> for FilmSortButton {
fn get_widget ( & self ) -> & SplitButton { & self . widget }
}

View file

@ -1,10 +1,12 @@
use gtk4 :: { * , prelude :: * } ;
mod collated_grid ;
mod collation_menu ;
use gtk4 :: { * , Orientation :: * , prelude :: * } ;
use crate :: {
collection :: * ,
ui :: {
collated_grid :: * ,
collation_menu :: * ,
collatable_container :: { collated_grid :: * , collation_menu :: * } ,
component :: * ,
utility :: * ,
} ,
@ -13,6 +15,10 @@ use crate :: {
# [ derive (PartialEq) ] pub enum FilmsSortedBy { Name , ReleaseDate , Runtime }
# [ derive (PartialEq) ] pub enum SeriesSortedBy { Name , FirstReleaseDate }
# [ derive (PartialEq) ] pub enum SortingDirection { Ascending , Descending }
pub struct CollatableFilmsContainer {
collated_grid : & 'static CollatedFilmsGrid ,
widget : Box ,
@ -29,7 +35,8 @@ impl CollatableFilmsContainer {
let film_collation_menu = FilmCollationMenu :: new ( | sorting , direction |
collated_grid . set_sorting ( sorting , direction ) ) ;
let widget = create_vertical_box ! (
let widget = g_box ! (
@ orientation : Vertical ,
film_collation_menu . get_widget () ,
& create_collection_scrolled_window ( collated_grid . get_widget () ) ,
) ;
@ -49,7 +56,8 @@ impl CollatableSeriesContainer {
collated_grid . set_sorting (sorted_by) ;
} ) ;
let widget = create_vertical_box ! (
let widget = g_box ! (
@ orientation : Vertical ,
series_collation_menu . get_widget () ,
& create_collection_scrolled_window ( collated_grid . get_widget () ) ,
) ;
@ -71,7 +79,7 @@ impl Component <Box> for CollatableSeriesContainer {
fn create_collection_scrolled_window ( child : & FlowBox ) -> ScrolledWindow {
ScrolledWindow :: builder ()
. child ( & create_vertical_filler_container (child) )
. child ( & vertically_filling ! (child) )
. propagate_natural_height (true)
. build ()
}

View file

@ -11,7 +11,7 @@ impl CollectionViewStack {
films_container : & CollatableFilmsContainer ,
series_container : & CollatableSeriesContainer ,
) -> Self {
let widget = create_view_stack ! (
let widget = view_stack ! (
"Films" , "camera-video-symbolic" , films_container . get_widget () ,
"Series" , "video-display-symbolic" , series_container . get_widget () ,
) ;

View file

@ -1,7 +1,5 @@
mod application_header_bar ;
mod collatable_container ;
mod collated_grid ;
mod collation_menu ;
mod collection_view_stack ;
mod component ;
mod utility ;

View file

@ -1,45 +1,60 @@
use { gtk4 :: { Label , Widget , prelude :: * } , libadwaita :: * } ;
macro_rules ! label { (
$ ( @ hexpand : $ hexpand : expr , ) ?
$ ( @ vexpand : $ vexpand : expr , ) ?
$ ( @ halign : $ halign : expr , ) ?
$ ( @ valign : $ valign : expr , ) ?
$ ( $ label : expr ) ? $ (,) ?
) => { {
let label = gtk4 :: Label :: builder () . build () ;
$ ( label . set_hexpand ( $ hexpand ) ; ) ?
$ ( label . set_vexpand ( $ vexpand ) ; ) ?
$ ( label . set_halign ( $ halign ) ; ) ?
$ ( label . set_valign ( $ valign ) ; ) ?
$ ( label . set_label ( $ label ) ; ) ?
label
} } }
pub fn create_label ( label : & str ) -> Label {
Label :: builder () . label (label) . build ()
}
macro_rules ! create_horizontal_box { ( $ ( $ child : expr , ) * ) => { {
let container = gtk4 :: Box :: builder ()
. orientation ( gtk4 :: Orientation :: Horizontal )
. build () ;
macro_rules ! g_box { (
$ ( @ orientation : $ orientation : expr , ) ?
$ ( $ child : expr ) , * $ (,) ?
) => { {
let container = gtk4 :: Box :: builder () . build () ;
$ ( container . set_orientation ( $ orientation ) ; ) ?
$ ( container . append ( $ child ) ; ) *
container
} } }
macro_rules ! create_vertical_box { ( $ ( $ child : expr , ) * ) => { {
let container = gtk4 :: Box :: builder ()
. orientation ( gtk4 :: Orientation :: Vertical)
. build () ;
$ ( container . append ( $ child ) ; ) *
container
} } }
macro_rules ! create_view_stack { (
macro_rules ! view_stack { (
$ ( $ title : expr , $ icon : expr , $ widget : expr , ) *
) => { {
let container = ViewStack :: new () ;
let container = libadwaita :: ViewStack :: new () ;
$ ( container . add_titled_with_icon ( $ widget , None , $ title , $ icon ) ; ) *
container
} } }
pub fn create_vertical_filler_container ( child : & impl IsA <Widget> ) -> gtk4 :: Box {
create_vertical_box ! (
child ,
& Bin :: builder ()
macro_rules ! list_box { ( $ ( $ child : expr , ) * ) => { {
let container = gtk4 :: ListBox :: new () ;
$ ( container . append ( $ child ) ; ) *
container
} } }
macro_rules ! vertically_filling { ( $ child : expr ) => {
g_box ! (
@ orientation : gtk4 :: Orientation :: Vertical ,
$ child ,
& libadwaita :: Bin :: builder ()
. css_name ("filler")
. vexpand (true)
. build () ,
)
}
} }
pub (crate) use { create_horizontal_box , create_vertical_box , create_view_stack } ;
pub (crate) use {
label ,
g_box ,
view_stack ,
list_box ,
vertically_filling ,
} ;