Sort icons now reflect sorting direction
This commit is contained in:
parent
0ae516e898
commit
4f2db1d04d
1 changed files with 43 additions and 8 deletions
|
@ -1,4 +1,8 @@
|
||||||
use { gtk4 :: { ListBoxRow , Align :: * } , libadwaita :: * , std :: cell :: * } ;
|
use {
|
||||||
|
gtk4 :: { Image , ListBoxRow , Align :: * } ,
|
||||||
|
libadwaita :: * ,
|
||||||
|
std :: cell :: * ,
|
||||||
|
} ;
|
||||||
|
|
||||||
use crate :: {
|
use crate :: {
|
||||||
utility :: * ,
|
utility :: * ,
|
||||||
|
@ -20,27 +24,33 @@ impl FilmSortButton {
|
||||||
pub fn new < F : Fn (FilmsSorting) + 'static > ( on_sort : F ) -> Self {
|
pub fn new < F : Fn (FilmsSorting) + 'static > ( on_sort : F ) -> Self {
|
||||||
let previous_sorting = leak ( RefCell :: new ( FilmsSorting :: default () ) ) ;
|
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 ! (
|
let widget = split_button ! (
|
||||||
@ popover : popover ! (
|
@ popover : popover ! (
|
||||||
@ css_classes : [ "menu" ] ,
|
@ css_classes : [ "menu" ] ,
|
||||||
list_box ! (
|
list_box ! (
|
||||||
@ connect_row_activated : move | _ , row | {
|
@ 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 ! (
|
g_box ! (
|
||||||
@ orientation : Horizontal , @ spacing : 20 ,
|
@ orientation : Horizontal , @ spacing : 20 ,
|
||||||
label ! ( @ hexpand : true , @ halign : Start , "Name" ) ,
|
label ! ( @ hexpand : true , @ halign : Start , "Name" ) ,
|
||||||
icon ! ("view-sort-ascending-symbolic") ,
|
sort_icons [0] ,
|
||||||
) ,
|
) ,
|
||||||
g_box ! (
|
g_box ! (
|
||||||
@ orientation : Horizontal , @ spacing : 20 ,
|
@ orientation : Horizontal , @ spacing : 20 ,
|
||||||
label ! ( @ hexpand : true , @ halign : Start , "Release date" ) ,
|
label ! ( @ hexpand : true , @ halign : Start , "Release date" ) ,
|
||||||
icon ! ("view-sort-ascending-symbolic") ,
|
sort_icons [1] ,
|
||||||
) ,
|
) ,
|
||||||
g_box ! (
|
g_box ! (
|
||||||
@ orientation : Horizontal , @ spacing : 20 ,
|
@ orientation : Horizontal , @ spacing : 20 ,
|
||||||
label ! ( @ hexpand : true , @ halign : Start , "Runtime" ) ,
|
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 {
|
pub fn new < F : Fn (SeriesSorting) + 'static > ( on_sort : F ) -> Self {
|
||||||
let previous_sorting = leak ( RefCell :: new ( SeriesSorting :: default () ) ) ;
|
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 ! (
|
let widget = split_button ! (
|
||||||
@ popover : popover ! (
|
@ popover : popover ! (
|
||||||
@ css_classes : [ "menu" ] ,
|
@ css_classes : [ "menu" ] ,
|
||||||
list_box ! (
|
list_box ! (
|
||||||
@ connect_row_activated : move | _ , row | {
|
@ 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 ! (
|
g_box ! (
|
||||||
@ orientation : Horizontal , @ spacing : 20 ,
|
@ orientation : Horizontal , @ spacing : 20 ,
|
||||||
label ! ( @ hexpand : true , @ halign : Start , "Name" ) ,
|
label ! ( @ hexpand : true , @ halign : Start , "Name" ) ,
|
||||||
icon ! ("view-sort-ascending-symbolic") ,
|
sort_icons [0] ,
|
||||||
) ,
|
) ,
|
||||||
g_box ! (
|
g_box ! (
|
||||||
@ orientation : Horizontal , @ spacing : 20 ,
|
@ orientation : Horizontal , @ spacing : 20 ,
|
||||||
label ! ( @ hexpand : true , @ halign : Start , "First release date" ) ,
|
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 ,
|
row : & ListBoxRow ,
|
||||||
previous_sorting : & RefCell <FilmsSorting> ,
|
previous_sorting : & RefCell <FilmsSorting> ,
|
||||||
on_sort : & F ,
|
on_sort : & F ,
|
||||||
|
sort_icons : & [ Image ] ,
|
||||||
) {
|
) {
|
||||||
let sorting_property = match row . index () {
|
let sorting_property = match row . index () {
|
||||||
0 => FilmProperty :: Name ,
|
0 => FilmProperty :: Name ,
|
||||||
|
@ -104,15 +120,24 @@ fn on_film_sort_activated < F : Fn (FilmsSorting) > (
|
||||||
match previous_sorting_direction {
|
match previous_sorting_direction {
|
||||||
Ascending => {
|
Ascending => {
|
||||||
previous_sorting . replace ( FilmsSorting :: new ( sorting_property , Descending ) ) ;
|
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 ) ) ;
|
on_sort ( FilmsSorting :: new ( sorting_property , Descending ) ) ;
|
||||||
} ,
|
} ,
|
||||||
Descending => {
|
Descending => {
|
||||||
previous_sorting . replace ( FilmsSorting :: new ( sorting_property , Ascending ) ) ;
|
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 ) ) ;
|
on_sort ( FilmsSorting :: new ( sorting_property , Ascending ) ) ;
|
||||||
} ,
|
} ,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
previous_sorting . replace ( FilmsSorting :: new ( sorting_property , Ascending ) ) ;
|
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 ) ) ;
|
on_sort ( FilmsSorting :: new ( sorting_property , Ascending ) ) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +145,7 @@ fn on_series_sort_activated < F : Fn (SeriesSorting) > (
|
||||||
row : & ListBoxRow ,
|
row : & ListBoxRow ,
|
||||||
previous_sorting : & RefCell <SeriesSorting> ,
|
previous_sorting : & RefCell <SeriesSorting> ,
|
||||||
on_sort : & F ,
|
on_sort : & F ,
|
||||||
|
sort_icons : & [ Image ] ,
|
||||||
) {
|
) {
|
||||||
let sorting_property = match row . index () {
|
let sorting_property = match row . index () {
|
||||||
0 => SeriesProperty :: Name ,
|
0 => SeriesProperty :: Name ,
|
||||||
|
@ -132,15 +158,24 @@ fn on_series_sort_activated < F : Fn (SeriesSorting) > (
|
||||||
match previous_sorting_direction {
|
match previous_sorting_direction {
|
||||||
Ascending => {
|
Ascending => {
|
||||||
previous_sorting . replace ( SeriesSorting :: new ( sorting_property , Descending ) ) ;
|
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 ) ) ;
|
on_sort ( SeriesSorting :: new ( sorting_property , Descending ) ) ;
|
||||||
} ,
|
} ,
|
||||||
Descending => {
|
Descending => {
|
||||||
previous_sorting . replace ( SeriesSorting :: new ( sorting_property , Ascending ) ) ;
|
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 ) ) ;
|
on_sort ( SeriesSorting :: new ( sorting_property , Ascending ) ) ;
|
||||||
} ,
|
} ,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
previous_sorting . replace ( SeriesSorting :: new ( sorting_property , Ascending ) ) ;
|
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 ) ) ;
|
on_sort ( SeriesSorting :: new ( sorting_property , Ascending ) ) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue