From: Philip Chimento Date: Thu, 21 Jul 2011 20:58:05 +0000 (+0200) Subject: Add custom renderer X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=b256559c8635baa5c4215804a82019af5ab61107;p=projects%2Fchimara%2Fchimara.git Add custom renderer --- diff --git a/player/browser.c b/player/browser.c index 24d9eb6..51dc6e7 100644 --- a/player/browser.c +++ b/player/browser.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "browser.h" #include "app.h" #include "util.h" @@ -79,6 +80,20 @@ chimara_browser_class_init(ChimaraBrowserClass *klass) g_type_class_add_private(klass, sizeof(ChimaraBrowserPrivate)); } +static void +text_function(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer data) +{ + char *title, *author, *rendered_string; + unsigned year; + gtk_tree_model_get(model, iter, + 1, &title, + 2, &author, + 3, &year, + -1); + rendered_string = g_strdup_printf("%s\nby %s (%d)", title, author, year); + g_object_set(cell, "markup", rendered_string, NULL); +} + static void chimara_browser_init(ChimaraBrowser *self) { @@ -116,6 +131,10 @@ chimara_browser_init(ChimaraBrowser *self) priv->library_model = GTK_LIST_STORE(load_object(builder, "library-model")); g_object_ref(priv->library_model); + GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(load_object(builder, "library-text-column")); + GtkCellRenderer *renderer = GTK_CELL_RENDERER(load_object(builder, "library-text-renderer")); + gtk_tree_view_column_set_cell_data_func(column, renderer, (GtkTreeCellDataFunc)text_function, NULL, NULL); + /* Make up some fake library data */ GdkPixbuf *fake_cover_art = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 120, 120); gdk_pixbuf_fill(fake_cover_art, 0xA4000000); diff --git a/player/chimara.ui b/player/chimara.ui index 1f2856c..db3d886 100644 --- a/player/chimara.ui +++ b/player/chimara.ui @@ -304,6 +304,9 @@ Philip Chimento Text True + + +