From 72d5352b09d2338cf3dad871bfedb5aab5812681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 12 Mar 2019 19:26:31 +0100 Subject: [PATCH] Change sorting function in order to add capability to sort both ways --- layer-selector.c | 14 ++++++++++++-- layer-selector.h | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/layer-selector.c b/layer-selector.c index f63559b..db98f96 100644 --- a/layer-selector.c +++ b/layer-selector.c @@ -155,19 +155,29 @@ static void analyze_cell_layers(GtkListBox *listbox, struct gds_cell *cell) * @param row1 * @param row2 * @param unused - * @note Do not use this function - * @return + * @note Do not use this function. This is an internal callback + * @return See sort function documentation of GTK+ */ static gint sort_func(GtkListBoxRow *row1, GtkListBoxRow *row2, gpointer unused) { LayerElement *le1, *le2; gint ret; + enum layer_selector_sort_algo default_sort = LAYER_SELECTOR_SORT_DOWN; + enum layer_selector_sort_algo *algo = (enum layer_selector_sort_algo *)unused; + + /* Assume downward sorting */ + if (!algo) + algo = &default_sort; le1 = LAYER_ELEMENT(row1); le2 = LAYER_ELEMENT(row2); + /* Determine sort fow downward sort */ ret = layer_element_get_layer(le1) - layer_element_get_layer(le2); + /* Change order if upward sort is requested */ + ret *= (*algo == LAYER_SELECTOR_SORT_DOWN ? 1 : -1); + return ret; } diff --git a/layer-selector.h b/layer-selector.h index 0fd7c18..23bed29 100644 --- a/layer-selector.h +++ b/layer-selector.h @@ -30,6 +30,11 @@ #include #include "mapping-parser.h" +/** + * @brief Defines how to sort the layer selector list box. + */ +enum layer_selector_sort_algo {LAYER_SELECTOR_SORT_DOWN = 0, LAYER_SELECTOR_SORT_UP}; + /** * @brief Generate layer widgets in \p listbox * @note This clears all previously inserted elements