diff --git a/src/ui/collated_grid.rs b/src/ui/collatable_container/collated_grid.rs similarity index 95% rename from src/ui/collated_grid.rs rename to src/ui/collatable_container/collated_grid.rs index 3081bee..6e131fe 100644 --- a/src/ui/collated_grid.rs +++ b/src/ui/collatable_container/collated_grid.rs @@ -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 , diff --git a/src/ui/collation_menu.rs b/src/ui/collatable_container/collation_menu/mod.rs similarity index 95% rename from src/ui/collation_menu.rs rename to src/ui/collatable_container/collation_menu/mod.rs index 43527a8..c29e35c 100644 --- a/src/ui/collation_menu.rs +++ b/src/ui/collatable_container/collation_menu/mod.rs @@ -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 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) diff --git a/src/ui/collatable_container/collation_menu/sort_button.rs b/src/ui/collatable_container/collation_menu/sort_button.rs new file mode 100644 index 0000000..e7ba0d5 --- /dev/null +++ b/src/ui/collatable_container/collation_menu/sort_button.rs @@ -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 for FilmSortButton { + fn get_widget ( & self ) -> & SplitButton { & self . widget } +} diff --git a/src/ui/collatable_container.rs b/src/ui/collatable_container/mod.rs similarity index 77% rename from src/ui/collatable_container.rs rename to src/ui/collatable_container/mod.rs index dc58eef..2d7adcf 100644 --- a/src/ui/collatable_container.rs +++ b/src/ui/collatable_container/mod.rs @@ -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 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 () } diff --git a/src/ui/collection_view_stack.rs b/src/ui/collection_view_stack.rs index bbce938..c3610e5 100644 --- a/src/ui/collection_view_stack.rs +++ b/src/ui/collection_view_stack.rs @@ -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 () , ) ; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 4bef6d1..722fa33 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -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 ; diff --git a/src/ui/utility.rs b/src/ui/utility.rs index 0ce11a5..abae8dc 100644 --- a/src/ui/utility.rs +++ b/src/ui/utility.rs @@ -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 ) -> 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 , +} ;