Sort icons now reflect sorting direction

This commit is contained in:
Reinout Meliesie 2025-01-31 19:00:15 +01:00
parent 0ae516e898
commit 4f2db1d04d
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6

View file

@ -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 <FilmsSorting> ,
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 <SeriesSorting> ,
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 ) ) ;
}
}