From 4f2db1d04d3d627fe0d10fafae31f4567a589664 Mon Sep 17 00:00:00 2001 From: Reinout Meliesie Date: Fri, 31 Jan 2025 19:00:15 +0100 Subject: [PATCH] Sort icons now reflect sorting direction --- .../collation_menu/sort_button.rs | 51 ++++++++++++++++--- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/ui/collatable_container/collation_menu/sort_button.rs b/src/ui/collatable_container/collation_menu/sort_button.rs index 90d3d3e..69c4acf 100644 --- a/src/ui/collatable_container/collation_menu/sort_button.rs +++ b/src/ui/collatable_container/collation_menu/sort_button.rs @@ -1,4 +1,8 @@ -use { gtk4 :: { ListBoxRow , Align :: * } , libadwaita :: * , std :: cell :: * } ; +use { + gtk4 :: { Image , ListBoxRow , Align :: * } , + libadwaita :: * , + std :: cell :: * , +} ; use crate :: { utility :: * , @@ -20,27 +24,33 @@ impl FilmSortButton { pub fn new < F : Fn (FilmsSorting) + 'static > ( on_sort : F ) -> Self { let previous_sorting = leak ( RefCell :: new ( FilmsSorting :: default () ) ) ; + let sort_icons = leak ( [ + icon ! ("view-sort-ascending-symbolic") , + icon ! ("view-sort-ascending-symbolic") , + icon ! ("view-sort-ascending-symbolic") , + ] ) ; + let widget = split_button ! ( @ popover : popover ! ( @ css_classes : [ "menu" ] , list_box ! ( @ connect_row_activated : move | _ , row | { - on_film_sort_activated ( row , previous_sorting , & on_sort ) ; + on_film_sort_activated ( row , previous_sorting , & on_sort , sort_icons ) ; } , g_box ! ( @ orientation : Horizontal , @ spacing : 20 , label ! ( @ hexpand : true , @ halign : Start , "Name" ) , - icon ! ("view-sort-ascending-symbolic") , + sort_icons [0] , ) , g_box ! ( @ orientation : Horizontal , @ spacing : 20 , label ! ( @ hexpand : true , @ halign : Start , "Release date" ) , - icon ! ("view-sort-ascending-symbolic") , + sort_icons [1] , ) , g_box ! ( @ orientation : Horizontal , @ spacing : 20 , label ! ( @ hexpand : true , @ halign : Start , "Runtime" ) , - icon ! ("view-sort-ascending-symbolic") , + sort_icons [2] , ) , ) , ) , @@ -54,22 +64,27 @@ impl SeriesSortButton { pub fn new < F : Fn (SeriesSorting) + 'static > ( on_sort : F ) -> Self { let previous_sorting = leak ( RefCell :: new ( SeriesSorting :: default () ) ) ; + let sort_icons = leak ( [ + icon ! ("view-sort-ascending-symbolic") , + icon ! ("view-sort-ascending-symbolic") , + ] ) ; + let widget = split_button ! ( @ popover : popover ! ( @ css_classes : [ "menu" ] , list_box ! ( @ connect_row_activated : move | _ , row | { - on_series_sort_activated ( row , previous_sorting , & on_sort ) ; + on_series_sort_activated ( row , previous_sorting , & on_sort , sort_icons ) ; } , g_box ! ( @ orientation : Horizontal , @ spacing : 20 , label ! ( @ hexpand : true , @ halign : Start , "Name" ) , - icon ! ("view-sort-ascending-symbolic") , + sort_icons [0] , ) , g_box ! ( @ orientation : Horizontal , @ spacing : 20 , label ! ( @ hexpand : true , @ halign : Start , "First release date" ) , - icon ! ("view-sort-ascending-symbolic") , + sort_icons [1] , ) , ) , ) , @@ -91,6 +106,7 @@ fn on_film_sort_activated < F : Fn (FilmsSorting) > ( row : & ListBoxRow , previous_sorting : & RefCell , on_sort : & F , + sort_icons : & [ Image ] , ) { let sorting_property = match row . index () { 0 => FilmProperty :: Name , @@ -104,15 +120,24 @@ fn on_film_sort_activated < F : Fn (FilmsSorting) > ( match previous_sorting_direction { Ascending => { previous_sorting . replace ( FilmsSorting :: new ( sorting_property , Descending ) ) ; + for icon in sort_icons { + icon . set_icon_name ( Some ("view-sort-descending-symbolic") ) ; + } on_sort ( FilmsSorting :: new ( sorting_property , Descending ) ) ; } , Descending => { previous_sorting . replace ( FilmsSorting :: new ( sorting_property , Ascending ) ) ; + for icon in sort_icons { + icon . set_icon_name ( Some ("view-sort-ascending-symbolic") ) ; + } on_sort ( FilmsSorting :: new ( sorting_property , Ascending ) ) ; } , } } else { previous_sorting . replace ( FilmsSorting :: new ( sorting_property , Ascending ) ) ; + for icon in sort_icons { + icon . set_icon_name ( Some ("view-sort-ascending-symbolic") ) ; + } on_sort ( FilmsSorting :: new ( sorting_property , Ascending ) ) ; } } @@ -120,6 +145,7 @@ fn on_series_sort_activated < F : Fn (SeriesSorting) > ( row : & ListBoxRow , previous_sorting : & RefCell , on_sort : & F , + sort_icons : & [ Image ] , ) { let sorting_property = match row . index () { 0 => SeriesProperty :: Name , @@ -132,15 +158,24 @@ fn on_series_sort_activated < F : Fn (SeriesSorting) > ( match previous_sorting_direction { Ascending => { previous_sorting . replace ( SeriesSorting :: new ( sorting_property , Descending ) ) ; + for icon in sort_icons { + icon . set_icon_name ( Some ("view-sort-descending-symbolic") ) ; + } on_sort ( SeriesSorting :: new ( sorting_property , Descending ) ) ; } , Descending => { previous_sorting . replace ( SeriesSorting :: new ( sorting_property , Ascending ) ) ; + for icon in sort_icons { + icon . set_icon_name ( Some ("view-sort-ascending-symbolic") ) ; + } on_sort ( SeriesSorting :: new ( sorting_property , Ascending ) ) ; } , } } else { previous_sorting . replace ( SeriesSorting :: new ( sorting_property , Ascending ) ) ; + for icon in sort_icons { + icon . set_icon_name ( Some ("view-sort-ascending-symbolic") ) ; + } on_sort ( SeriesSorting :: new ( sorting_property , Ascending ) ) ; } }