[gtk/wip/otte/sortlistmodel: 3/39] demo: Add faster sorters
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/sortlistmodel: 3/39] demo: Add faster sorters
- Date: Sun, 19 Jul 2020 03:10:39 +0000 (UTC)
commit c91bc17a24da011cd95b2a61a986c226a358fbf6
Author: Benjamin Otte <otte redhat com>
Date: Tue Jul 7 19:05:06 2020 +0200
demo: Add faster sorters
This is just the existing sorters, but without the overhead of GObject
properties.
demos/gtk-demo/listview_colors.c | 60 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
---
diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c
index 449c14b3c6..005c4b0594 100644
--- a/demos/gtk-demo/listview_colors.c
+++ b/demos/gtk-demo/listview_colors.c
@@ -835,6 +835,54 @@ update_selection_average (GListModel *model,
g_object_unref (color);
}
+static int
+compare_red (gconstpointer a,
+ gconstpointer b,
+ gpointer unused)
+{
+ GtkColor *colora = (GtkColor *) a;
+ GtkColor *colorb = (GtkColor *) b;
+
+ if (colora->color.red < colorb->color.red)
+ return GTK_ORDERING_LARGER;
+ else if (colora->color.red > colorb->color.red)
+ return GTK_ORDERING_SMALLER;
+ else
+ return GTK_ORDERING_EQUAL;
+}
+
+static int
+compare_green (gconstpointer a,
+ gconstpointer b,
+ gpointer unused)
+{
+ GtkColor *colora = (GtkColor *) a;
+ GtkColor *colorb = (GtkColor *) b;
+
+ if (colora->color.green < colorb->color.green)
+ return GTK_ORDERING_LARGER;
+ else if (colora->color.green > colorb->color.green)
+ return GTK_ORDERING_SMALLER;
+ else
+ return GTK_ORDERING_EQUAL;
+}
+
+static int
+compare_blue (gconstpointer a,
+ gconstpointer b,
+ gpointer unused)
+{
+ GtkColor *colora = (GtkColor *) a;
+ GtkColor *colorb = (GtkColor *) b;
+
+ if (colora->color.blue < colorb->color.blue)
+ return GTK_ORDERING_LARGER;
+ else if (colora->color.blue > colorb->color.blue)
+ return GTK_ORDERING_SMALLER;
+ else
+ return GTK_ORDERING_EQUAL;
+}
+
static GtkWidget *window = NULL;
GtkWidget *
@@ -1022,18 +1070,30 @@ do_listview_colors (GtkWidget *do_widget)
g_list_store_append (sorters, sorter);
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi_sorter), sorter);
+ sorter = gtk_custom_sorter_new (compare_red, NULL, NULL);
+ set_title (sorter, "Red (fast)");
+ g_list_store_append (sorters, sorter);
+
sorter = gtk_numeric_sorter_new (gtk_property_expression_new (GTK_TYPE_COLOR, NULL, "green"));
gtk_numeric_sorter_set_sort_order (GTK_NUMERIC_SORTER (sorter), GTK_SORT_DESCENDING);
set_title (sorter, "Green");
g_list_store_append (sorters, sorter);
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi_sorter), sorter);
+ sorter = gtk_custom_sorter_new (compare_green, NULL, NULL);
+ set_title (sorter, "Green (fast)");
+ g_list_store_append (sorters, sorter);
+
sorter = gtk_numeric_sorter_new (gtk_property_expression_new (GTK_TYPE_COLOR, NULL, "blue"));
gtk_numeric_sorter_set_sort_order (GTK_NUMERIC_SORTER (sorter), GTK_SORT_DESCENDING);
set_title (sorter, "Blue");
g_list_store_append (sorters, sorter);
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi_sorter), sorter);
+ sorter = gtk_custom_sorter_new (compare_blue, NULL, NULL);
+ set_title (sorter, "Blue (fast)");
+ g_list_store_append (sorters, sorter);
+
set_title (multi_sorter, "RGB");
g_list_store_append (sorters, multi_sorter);
g_object_unref (multi_sorter);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]