[gnome-builder] tree: add support for GbTreeNode:use-dim-label



commit 6c9e3790bc04e4e0fa49d2fc85955ad04f1d19a8
Author: Christian Hergert <christian hergert me>
Date:   Sun Jun 21 18:01:49 2015 -0700

    tree: add support for GbTreeNode:use-dim-label
    
    This gproperty will result in the text of the node being rendered with
    a dim label. We need to manually set the style for various themes since
    the alpha value is not extracted from the style context (always set to
    1.0). Possibly a better way to deal with that.
    
    I'm unsure if we should also apply this to the pixbuf renderer.

 data/theme/Adwaita-dark.css |    9 ++++++
 data/theme/Adwaita.css      |    9 ++++++
 src/tree/gb-tree-node.c     |   65 +++++++++++++++++++++++++++++++++++++++----
 src/tree/gb-tree-node.h     |    6 ++++
 src/tree/gb-tree.c          |   46 +++++++++++++++++++++++++-----
 5 files changed, 121 insertions(+), 14 deletions(-)
---
diff --git a/data/theme/Adwaita-dark.css b/data/theme/Adwaita-dark.css
index fa19973..95fe202 100644
--- a/data/theme/Adwaita-dark.css
+++ b/data/theme/Adwaita-dark.css
@@ -27,3 +27,12 @@ GbTerminalView {
   background-color: #2e3436;
   color: #babdb6;
 }
+
+
+GbTree.dim-label {
+  color: #979a99;
+}
+
+GbTree:backdrop.dim-label {
+  color: #6d6f70;
+}
diff --git a/data/theme/Adwaita.css b/data/theme/Adwaita.css
index 0d2557e..ee35d6f 100644
--- a/data/theme/Adwaita.css
+++ b/data/theme/Adwaita.css
@@ -33,3 +33,12 @@ GbTerminalView {
   background-color: #f6f7f8;
   color: #4d4e53;
 }
+
+
+GbTree.dim-label {
+  color: #9a9b98;
+}
+
+GbTree:backdrop.dim-label {
+  color: #b6b7b4;
+}
diff --git a/src/tree/gb-tree-node.c b/src/tree/gb-tree-node.c
index 89ee636..910593e 100644
--- a/src/tree/gb-tree-node.c
+++ b/src/tree/gb-tree-node.c
@@ -37,6 +37,7 @@ struct _GbTreeNode
   guint              needs_build : 1;
   guint              is_dummy : 1;
   guint              children_possible : 1;
+  guint              use_dim_label : 1;
 };
 
 typedef struct
@@ -54,6 +55,7 @@ enum {
   PROP_PARENT,
   PROP_TEXT,
   PROP_TREE,
+  PROP_USE_DIM_LABEL,
   PROP_USE_MARKUP,
   LAST_PROP
 };
@@ -352,14 +354,27 @@ gb_tree_node_set_text (GbTreeNode  *node,
     }
 }
 
-static void
-gb_tree_node_set_use_markup (GbTreeNode *node,
+gboolean
+gb_tree_node_get_use_markup (GbTreeNode *self)
+{
+  g_return_val_if_fail (GB_IS_TREE_NODE (self), FALSE);
+
+  return self->use_markup;
+}
+
+void
+gb_tree_node_set_use_markup (GbTreeNode *self,
                              gboolean    use_markup)
 {
-  g_return_if_fail (GB_IS_TREE_NODE (node));
+  g_return_if_fail (GB_IS_TREE_NODE (self));
+
+  use_markup = !!use_markup;
 
-  node->use_markup = !!use_markup;
-  g_object_notify_by_pspec (G_OBJECT (node), gParamSpecs [PROP_USE_MARKUP]);
+  if (self->use_markup != use_markup)
+    {
+      self->use_markup = use_markup;
+      g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_USE_MARKUP]);
+    }
 }
 
 /**
@@ -524,6 +539,10 @@ gb_tree_node_get_property (GObject    *object,
       g_value_set_object (value, gb_tree_node_get_tree (node));
       break;
 
+    case PROP_USE_DIM_LABEL:
+      g_value_set_boolean (value, node->use_dim_label);
+      break;
+
     case PROP_USE_MARKUP:
       g_value_set_boolean (value, node->use_markup);
       break;
@@ -555,6 +574,10 @@ gb_tree_node_set_property (GObject      *object,
       gb_tree_node_set_text (node, g_value_get_string (value));
       break;
 
+    case PROP_USE_DIM_LABEL:
+      gb_tree_node_set_use_dim_label (node, g_value_get_boolean (value));
+      break;
+
     case PROP_USE_MARKUP:
       gb_tree_node_set_use_markup (node, g_value_get_boolean (value));
       break;
@@ -643,7 +666,14 @@ gb_tree_node_class_init (GbTreeNodeClass *klass)
                           _("Use Markup"),
                           _("If text should be translated as markup."),
                           FALSE,
-                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  gParamSpecs [PROP_USE_DIM_LABEL] =
+    g_param_spec_boolean ("use-dim-label",
+                          _("Use Dim Label"),
+                          _("If text should be rendered with a dim label."),
+                          FALSE,
+                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
 }
@@ -861,3 +891,26 @@ gb_tree_node_set_children_possible (GbTreeNode *self,
         }
     }
 }
+
+gboolean
+gb_tree_node_get_use_dim_label (GbTreeNode *self)
+{
+  g_return_val_if_fail (GB_IS_TREE_NODE (self), FALSE);
+
+  return self->use_dim_label;
+}
+
+void
+gb_tree_node_set_use_dim_label (GbTreeNode *self,
+                                gboolean    use_dim_label)
+{
+  g_return_if_fail (GB_IS_TREE_NODE (self));
+
+  use_dim_label = !!use_dim_label;
+
+  if (use_dim_label != self->use_dim_label)
+    {
+      self->use_dim_label = use_dim_label;
+      g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_USE_DIM_LABEL]);
+    }
+}
diff --git a/src/tree/gb-tree-node.h b/src/tree/gb-tree-node.h
index 34e3d23..81506c9 100644
--- a/src/tree/gb-tree-node.h
+++ b/src/tree/gb-tree-node.h
@@ -61,6 +61,12 @@ GbTree        *gb_tree_node_get_tree      (GbTreeNode   *node);
 void           gb_tree_node_set_children_possible
                                           (GbTreeNode   *self,
                                            gboolean      children_possible);
+gboolean       gb_tree_node_get_use_markup        (GbTreeNode   *self);
+void           gb_tree_node_set_use_markup        (GbTreeNode   *self,
+                                                   gboolean      use_markup);
+gboolean       gb_tree_node_get_use_dim_label     (GbTreeNode   *self);
+void           gb_tree_node_set_use_dim_label     (GbTreeNode   *self,
+                                                   gboolean      use_dim_label);
 
 G_END_DECLS
 
diff --git a/src/tree/gb-tree.c b/src/tree/gb-tree.c
index b7c375f..0ca7856 100644
--- a/src/tree/gb-tree.c
+++ b/src/tree/gb-tree.c
@@ -35,6 +35,7 @@ typedef struct
   GtkCellRenderer   *cell_pixbuf;
   GtkCellRenderer   *cell_text;
   GtkTreeStore      *store;
+  GdkRGBA            dim_foreground;
   guint              show_icons : 1;
 } GbTreePrivate;
 
@@ -459,10 +460,11 @@ text_func (GtkCellLayout   *cell_layout,
            GtkTreeIter     *iter,
            gpointer         data)
 {
-  gboolean use_markup = FALSE;
+  GbTree *self = data;
+  GbTreePrivate *priv = gb_tree_get_instance_private (self);
   GbTreeNode *node = NULL;
-  gchar *text = NULL;
 
+  g_assert (GB_IS_TREE (self));
   g_assert (GTK_IS_CELL_LAYOUT (cell_layout));
   g_assert (GTK_IS_CELL_RENDERER_TEXT (cell));
   g_assert (GTK_IS_TREE_MODEL (tree_model));
@@ -472,14 +474,20 @@ text_func (GtkCellLayout   *cell_layout,
 
   if (node)
     {
-      g_object_get (node,
-                    "text", &text,
-                    "use-markup", &use_markup,
-                    NULL);
+      GdkRGBA *rgba = NULL;
+      const gchar *text;
+      gboolean use_markup;
+
+      text = gb_tree_node_get_text (node);
+      use_markup = gb_tree_node_get_use_markup (node);
+
+      if (gb_tree_node_get_use_dim_label (node))
+        rgba = &priv->dim_foreground;
+
       g_object_set (cell,
                     use_markup ? "markup" : "text", text,
+                    "foreground-rgba", rgba,
                     NULL);
-      g_free (text);
     }
 }
 
@@ -831,6 +839,27 @@ gb_tree_add_child (GtkBuildable *buildable,
 }
 
 static void
+gb_tree_style_updated (GtkWidget *widget)
+{
+  GbTree *self = (GbTree *)widget;
+  GbTreePrivate *priv = gb_tree_get_instance_private (self);
+  GtkStyleContext *style_context;
+  GtkStateFlags flags;
+
+  g_assert (GB_IS_TREE (self));
+
+  GTK_WIDGET_CLASS (gb_tree_parent_class)->style_updated (widget);
+
+  flags = gtk_widget_get_state_flags (widget);
+
+  style_context = gtk_widget_get_style_context (widget);
+  gtk_style_context_save (style_context);
+  gtk_style_context_add_class (style_context, "dim-label");
+  gtk_style_context_get_color (style_context, flags, &priv->dim_foreground);
+  gtk_style_context_restore (style_context);
+}
+
+static void
 gb_tree_finalize (GObject *object)
 {
   GbTree *self = GB_TREE (object);
@@ -919,6 +948,7 @@ gb_tree_class_init (GbTreeClass *klass)
 
   widget_class->popup_menu = gb_tree_popup_menu;
   widget_class->button_press_event = gb_tree_button_press_event;
+  widget_class->style_updated = gb_tree_style_updated;
 
   tree_view_class->row_activated = gb_tree_row_activated;
   tree_view_class->row_expanded = gb_tree_row_expanded;
@@ -1009,7 +1039,7 @@ gb_tree_init (GbTree *self)
                        NULL);
   priv->cell_text = cell;
   gtk_cell_layout_pack_start (column, cell, TRUE);
-  gtk_cell_layout_set_cell_data_func (column, cell, text_func, NULL, NULL);
+  gtk_cell_layout_set_cell_data_func (column, cell, text_func, self, NULL);
 
   gtk_tree_view_append_column (GTK_TREE_VIEW (self),
                                GTK_TREE_VIEW_COLUMN (column));


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