[gtk/emoji-grid: 124/136] flattenlistmodel: Implement GtkSectionModel
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/emoji-grid: 124/136] flattenlistmodel: Implement GtkSectionModel
- Date: Sat, 26 Feb 2022 23:56:17 +0000 (UTC)
commit 5427e59f43133ec41bcbc1a2fc0747d93103cb13
Author: Benjamin Otte <otte redhat com>
Date: Sat Feb 26 04:52:16 2022 +0100
flattenlistmodel: Implement GtkSectionModel
Each child model is reported as one section.
gtk/gtkflattenlistmodel.c | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkflattenlistmodel.c b/gtk/gtkflattenlistmodel.c
index 74f3b7795a..7241d1b66b 100644
--- a/gtk/gtkflattenlistmodel.c
+++ b/gtk/gtkflattenlistmodel.c
@@ -21,9 +21,10 @@
#include "gtkflattenlistmodel.h"
-#include "gtkrbtreeprivate.h"
#include "gtkintl.h"
#include "gtkprivate.h"
+#include "gtksectionmodel.h"
+#include "gtkrbtreeprivate.h"
/**
* GtkFlattenListModel:
@@ -198,8 +199,39 @@ gtk_flatten_list_model_model_init (GListModelInterface *iface)
iface->get_item = gtk_flatten_list_model_get_item;
}
+static void
+gtk_flatten_list_model_get_section (GtkSectionModel *model,
+ guint position,
+ guint *out_start,
+ guint *out_end)
+{
+ GtkFlattenListModel *self = GTK_FLATTEN_LIST_MODEL (model);
+ FlattenNode *node;
+ guint model_pos;
+
+ node = gtk_flatten_list_model_get_nth (self->items, position, &model_pos);
+ if (node == NULL)
+ {
+ *out_start = gtk_flatten_list_model_get_n_items (G_LIST_MODEL (self));
+ *out_end = G_MAXUINT;
+ return;
+ }
+
+ *out_start = position - model_pos;
+ *out_start = position - model_pos + g_list_model_get_n_items (node->model);
+}
+
+static void
+gtk_flatten_list_model_section_model_init (GtkSectionModelInterface *iface)
+{
+ iface->get_section = gtk_flatten_list_model_get_section;
+}
+
G_DEFINE_TYPE_WITH_CODE (GtkFlattenListModel, gtk_flatten_list_model, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_flatten_list_model_model_init))
+ G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
+ gtk_flatten_list_model_model_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_SECTION_MODEL,
+ gtk_flatten_list_model_section_model_init))
static void
gtk_flatten_list_model_items_changed_cb (GListModel *model,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]