Commit 8226d617 authored by Christian Hergert's avatar Christian Hergert

tree-node: add support for setting foreground color

This allows specifying a foreground color for a row. Currently,
that only supports the text field. We may want something in the
future that allows more control over the pango attr list, but
I'd prefer to avoid the attr lists for now.
parent f8483d21
......@@ -19,6 +19,7 @@
#define G_LOG_DOMAIN "dzl-tree-node"
#include <glib/gi18n.h>
#include <string.h>
#include "tree/dzl-tree.h"
#include "tree/dzl-tree-node.h"
......@@ -34,18 +35,21 @@ struct _DzlTreeNode
GObject *item;
gchar *text;
DzlTree *tree;
GIcon *gicon;
GList *emblems;
GQuark icon_name;
GQuark expanded_icon_name;
guint use_markup : 1;
guint needs_build_children : 1;
guint is_dummy : 1;
GdkRGBA foreground_rgba;
guint children_possible : 1;
guint use_dim_label : 1;
guint is_dummy : 1;
guint foreground_rgba_set : 1;
guint needs_build_children : 1;
guint reset_on_collapse : 1;
guint use_dim_label : 1;
guint use_markup : 1;
};
typedef struct
......@@ -1312,3 +1316,51 @@ dzl_tree_node_nth_child (DzlTreeNode *self,
return NULL;
}
/**
* dzl_tree_node_get_foreground_rgba:
* @self: a #DzlTreeNode
*
* Gets the foreground-rgba to use for row text.
*
* If %NULL, the default foreground color should be used.
*
* Returns: (nullable) (transfer none): A #GdkRGBA or %NULL
*
* Since: 3.28
*/
const GdkRGBA *
dzl_tree_node_get_foreground_rgba (DzlTreeNode *self)
{
g_return_val_if_fail (DZL_IS_TREE_NODE (self), NULL);
if (self->foreground_rgba_set)
return &self->foreground_rgba;
return NULL;
}
/**
* dzl_tree_node_set_foreground_rgba:
* @self: a #DzlTreeNode
* @foreground_rgba: (nullable): A #GdkRGBA or %NULL
*
* Sets the foreground-rgba to be used by the row text.
*
* If @foreground_rgba is %NULL, the value is reset to the default.
*
* Since: 3.28
*/
void
dzl_tree_node_set_foreground_rgba (DzlTreeNode *self,
const GdkRGBA *foreground_rgba)
{
g_return_if_fail (DZL_IS_TREE_NODE (self));
if (foreground_rgba != NULL)
self->foreground_rgba = *foreground_rgba;
else
memset (&self->foreground_rgba, 0, sizeof self->foreground_rgba);
self->foreground_rgba_set = !!foreground_rgba;
}
......@@ -128,6 +128,11 @@ gboolean dzl_tree_node_get_reset_on_collapse (DzlTreeNode *sel
DZL_AVAILABLE_IN_3_28
void dzl_tree_node_set_reset_on_collapse (DzlTreeNode *self,
gboolean reset_on_collapse);
DZL_AVAILABLE_IN_3_28
const GdkRGBA *dzl_tree_node_get_foreground_rgba (DzlTreeNode *self);
DZL_AVAILABLE_IN_3_28
void dzl_tree_node_set_foreground_rgba (DzlTreeNode *self,
const GdkRGBA *foreground_rgba);
G_END_DECLS
......
......@@ -460,7 +460,7 @@ text_func (GtkCellLayout *cell_layout,
if (node)
{
GdkRGBA *rgba = NULL;
const GdkRGBA *rgba = NULL;
const gchar *text;
gboolean use_markup;
......@@ -469,6 +469,8 @@ text_func (GtkCellLayout *cell_layout,
if (dzl_tree_node_get_use_dim_label (node))
rgba = &priv->dim_foreground;
else
rgba = dzl_tree_node_get_foreground_rgba (node);
g_object_set (cell,
use_markup ? "markup" : "text", text,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment