[libdazzle] tree: allow builders to hook into cell data func



commit 9867b453d604b27bab6a06db45834b5d78a74894
Author: Christian Hergert <chergert redhat com>
Date:   Tue Dec 12 03:04:01 2017 -0800

    tree: allow builders to hook into cell data func
    
    This allows hooking into the cell data function so that nodes
    do not need to contain static information. This can reduce lots
    of allocations necessary to do custom text styling.
    
    Currently, we only use this for the text cell func, but we can
    probably add the pixbuf cell in the future. The signature
    reflects that by using GtkCellRenderer and not the leaf type.

 src/tree/dzl-tree-builder.h |    5 ++++-
 src/tree/dzl-tree.c         |   10 +++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/tree/dzl-tree-builder.h b/src/tree/dzl-tree-builder.h
index 2bfba3b..0fb8c22 100644
--- a/src/tree/dzl-tree-builder.h
+++ b/src/tree/dzl-tree-builder.h
@@ -74,9 +74,12 @@ struct _DzlTreeBuilderClass
                                        GtkSelectionData    *data);
   gboolean (*drag_node_delete)        (DzlTreeBuilder      *builder,
                                        DzlTreeNode         *node);
+  void     (*cell_data_func)          (DzlTreeBuilder      *tree,
+                                       DzlTreeNode         *node,
+                                       GtkCellRenderer     *cell);
 
   /*< private >*/
-  gpointer _padding[12];
+  gpointer _padding[11];
 };
 
 DZL_AVAILABLE_IN_ALL
diff --git a/src/tree/dzl-tree.c b/src/tree/dzl-tree.c
index 6662687..2c047b2 100644
--- a/src/tree/dzl-tree.c
+++ b/src/tree/dzl-tree.c
@@ -458,7 +458,7 @@ text_func (GtkCellLayout   *cell_layout,
 
   gtk_tree_model_get (tree_model, iter, 0, &node, -1);
 
-  if (node)
+  if G_LIKELY (node != NULL)
     {
       const GdkRGBA *rgba = NULL;
       const gchar *text;
@@ -476,6 +476,14 @@ text_func (GtkCellLayout   *cell_layout,
                     use_markup ? "markup" : "text", text,
                     "foreground-rgba", rgba,
                     NULL);
+
+      for (guint i = 0; i < priv->builders->len; i++)
+        {
+          DzlTreeBuilder *builder = g_ptr_array_index (priv->builders, i);
+
+          if (DZL_TREE_BUILDER_GET_CLASS (builder)->cell_data_func)
+            DZL_TREE_BUILDER_GET_CLASS (builder)->cell_data_func (builder, node, cell);
+        }
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]