From c3dfa5b459835c159f67b53ccfba48afe10ff54d Mon Sep 17 00:00:00 2001 From: Reinout Meliesie Date: Fri, 7 Feb 2025 16:22:34 +0100 Subject: [PATCH] Collection items are now clickable --- src/application.css | 4 ++ src/ui/collatable_container/collated_grid.rs | 50 +++++++++++--------- src/ui/utility.rs | 13 +++++ 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/application.css b/src/application.css index 09ba739..5b26221 100644 --- a/src/application.css +++ b/src/application.css @@ -12,3 +12,7 @@ #series-collation-menu row:not(:selected) image { opacity : 0 ; } + +.open-collection-item-button { + font-weight : normal ; /* No bold text by default for this kind of button */ +} diff --git a/src/ui/collatable_container/collated_grid.rs b/src/ui/collatable_container/collated_grid.rs index ac65b14..c7b34c4 100644 --- a/src/ui/collatable_container/collated_grid.rs +++ b/src/ui/collatable_container/collated_grid.rs @@ -17,11 +17,11 @@ use crate :: ui :: component :: * ; pub struct CollatedFilmsGrid { - film_widget_pairs : RefCell < Vec < ( FilmOverview , Box ) > > , + film_widget_pairs : RefCell < Vec < ( FilmOverview , Button ) > > , grid_widget : FlowBox , } pub struct CollatedSeriesGrid { - series_widget_pairs : RefCell < Vec < ( SeriesOverview , Box ) > > , + series_widget_pairs : RefCell < Vec < ( SeriesOverview , Button ) > > , grid_widget : FlowBox , } @@ -42,8 +42,7 @@ impl CollatedFilmsGrid { for film in films . as_slice () { widgets . push ( create_film_entry (film) . await ) ; } - * self . film_widget_pairs . borrow_mut () = zip ( films , widgets ) - . collect () ; + self . film_widget_pairs . replace ( zip ( films , widgets ) . collect () ) ; for ( _ , film_widget ) in self . sort_film_widget_pairs (sorting) { self . grid_widget . append ( & film_widget ) ; @@ -58,7 +57,7 @@ impl CollatedFilmsGrid { } } - fn sort_film_widget_pairs ( & self , sorting : FilmsSorting ) -> Vec < ( FilmOverview , Box ) > { + fn sort_film_widget_pairs ( & self , sorting : FilmsSorting ) -> Vec < ( FilmOverview , Button ) > { let mut sorted = Vec :: from ( self . film_widget_pairs . borrow () . as_slice () ) ; @@ -93,8 +92,7 @@ impl CollatedSeriesGrid { for series in series . as_slice () { widgets . push ( create_series_entry (series) . await ) ; } - * self . series_widget_pairs . borrow_mut () = zip ( series , widgets ) - . collect () ; + self . series_widget_pairs . replace ( zip ( series , widgets ) . collect () ) ; for ( _ , series_widget ) in self . sort_series_widget_pairs (sorting) { self . grid_widget . append ( & series_widget ) ; @@ -109,7 +107,7 @@ impl CollatedSeriesGrid { } } - fn sort_series_widget_pairs ( & self , sorting : SeriesSorting ) -> Vec < ( SeriesOverview , Box ) > { + fn sort_series_widget_pairs ( & self , sorting : SeriesSorting ) -> Vec < ( SeriesOverview , Button ) > { let mut sorted = Vec :: from ( self . series_widget_pairs . borrow () . as_slice () ) ; @@ -133,21 +131,29 @@ impl Component for CollatedSeriesGrid { fn get_widget ( & self ) -> & FlowBox { & self . grid_widget } } -pub async fn create_film_entry ( film : & FilmOverview ) -> Box { - create_collection_item ( - film . name . as_str () , - film . original_name . as_deref () , - film . poster_file_path . as_deref () , - & create_film_details (film) , - ) . await +async fn create_film_entry ( film : & FilmOverview ) -> Button { + button ! ( + @ css_classes : & [ "flat" , "open-collection-item-button" ] ; + @ connect_clicked : |_| todo ! () ; + & create_collection_item ( + film . name . as_str () , + film . original_name . as_deref () , + film . poster_file_path . as_deref () , + & create_film_details (film) , + ) . await , + ) } -pub async fn create_series_entry ( series : & SeriesOverview ) -> Box { - create_collection_item ( - series . name . as_str () , - series . original_name . as_deref () , - series . poster_file_path . as_deref () , - & create_series_details (series) , - ) . await +async fn create_series_entry ( series : & SeriesOverview ) -> Button { + button ! ( + @ css_classes : & [ "flat" , "open-collection-item-button" ] ; + @ connect_clicked : |_| todo ! () ; + & create_collection_item ( + series . name . as_str () , + series . original_name . as_deref () , + series . poster_file_path . as_deref () , + & create_series_details (series) , + ) . await , + ) } async fn create_collection_item ( diff --git a/src/ui/utility.rs b/src/ui/utility.rs index 07b04b8..df0f42f 100644 --- a/src/ui/utility.rs +++ b/src/ui/utility.rs @@ -90,6 +90,18 @@ macro_rules ! list_box { ( container } } } +macro_rules ! button { ( + $ ( @ css_classes : $ css_classes : expr ; ) ? + $ ( @ connect_clicked : $ connect_clicked : expr ; ) ? + $ ( $ child : expr ) ? $ (,) ? +) => { { + let button = gtk4 :: Button :: new () ; + $ ( button . set_css_classes ( $ css_classes ) ; ) ? + $ ( button . connect_clicked ( $ connect_clicked ) ; ) ? + $ ( button . set_child ( Some ( $ child ) ) ; ) ? + button +} } } + macro_rules ! split_button { ( $ ( @ popover : $ popover : expr ; ) ? $ child : expr $ (,) ? @@ -214,6 +226,7 @@ pub (crate) use { g_box , view_stack , list_box , + button , split_button , popover , image ,