[gnome-notes/136-implement-the-list-row-pattern-in-main-view: 14/15] list-view-row: add colors
- From: Isaque Galdino de Araujo <igaldino src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-notes/136-implement-the-list-row-pattern-in-main-view: 14/15] list-view-row: add colors
- Date: Thu, 2 Jul 2020 02:34:05 +0000 (UTC)
commit f2465b72a83d8252c38a819c214abac071d7cc06
Author: Isaque Galdino <igaldino gmail com>
Date: Mon Jun 15 00:41:43 2020 -0300
list-view-row: add colors
src/bjb-controller.c | 11 +++++++++--
src/bjb-controller.h | 1 +
src/bjb-list-view-row.c | 19 ++++++++++++++++++-
3 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index 82d5400..ba4116d 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -95,6 +95,7 @@ bjb_controller_init (BjbController *self)
G_TYPE_STRING, // BJB_MODEL_COLUMN_TITLE
G_TYPE_STRING, // BJB_MODEL_COLUMN_TEXT
G_TYPE_INT64, // BJB_MODEL_COLUMN_MTIME
+ G_TYPE_STRING, // BJB_MODEL_COLUMN_COLOR
G_TYPE_BOOLEAN); // BJB_MODEL_COLUMN_SELECTED
self->model = GTK_TREE_MODEL (store);
@@ -230,8 +231,10 @@ bjb_controller_add_item (BjbController *self,
gboolean prepend,
GtkTreeIter *sibling)
{
- GtkTreeIter iter;
- GtkListStore *store;
+ GtkTreeIter iter;
+ GtkListStore *store;
+ GdkRGBA note_color;
+ g_autofree char *color = NULL;
g_return_if_fail (BIJI_IS_ITEM (item));
store = GTK_LIST_STORE (self->model);
@@ -251,12 +254,16 @@ bjb_controller_add_item (BjbController *self,
else
gtk_list_store_append (store, &iter);
+ if (biji_note_obj_get_rgba (BIJI_NOTE_OBJ (item), ¬e_color))
+ color = gdk_rgba_to_string (¬e_color);
+
gtk_list_store_set (store,
&iter,
BJB_MODEL_COLUMN_UUID, biji_item_get_uuid (item),
BJB_MODEL_COLUMN_TITLE, biji_item_get_title (item),
BJB_MODEL_COLUMN_TEXT, biji_note_obj_get_raw_text (BIJI_NOTE_OBJ (item)),
BJB_MODEL_COLUMN_MTIME, biji_item_get_mtime (item),
+ BJB_MODEL_COLUMN_COLOR, color,
-1);
}
diff --git a/src/bjb-controller.h b/src/bjb-controller.h
index d3015c2..975e9de 100644
--- a/src/bjb-controller.h
+++ b/src/bjb-controller.h
@@ -33,6 +33,7 @@ typedef enum {
BJB_MODEL_COLUMN_TITLE,
BJB_MODEL_COLUMN_TEXT,
BJB_MODEL_COLUMN_MTIME,
+ BJB_MODEL_COLUMN_COLOR,
BJB_MODEL_COLUMN_SELECTED,
BJB_MODEL_COLUMN_LAST
} BjbModelColumnsType;
diff --git a/src/bjb-list-view-row.c b/src/bjb-list-view-row.c
index d8dc21b..2c36735 100644
--- a/src/bjb-list-view-row.c
+++ b/src/bjb-list-view-row.c
@@ -27,6 +27,7 @@ struct _BjbListViewRow
{
GtkListBoxRow parent_instance;
+ GtkCssProvider *css_provider;
BjbListView *view;
GtkCheckButton *select_button;
GtkLabel *title;
@@ -70,11 +71,14 @@ bjb_list_view_row_setup (BjbListViewRow *self,
char *uuid;
char *title;
char *text;
+ char *color;
gint64 mtime;
- g_autofree char *updated_time = NULL;
+ GdkRGBA rgba;
g_auto (GStrv) lines = NULL;
g_autofree char *one_line = NULL;
g_autofree char *preview = NULL;
+ g_autofree char *updated_time = NULL;
+ g_autofree char *css_style = NULL;
self->view = view;
@@ -89,6 +93,7 @@ bjb_list_view_row_setup (BjbListViewRow *self,
BJB_MODEL_COLUMN_TITLE, &title,
BJB_MODEL_COLUMN_TEXT, &text,
BJB_MODEL_COLUMN_MTIME, &mtime,
+ BJB_MODEL_COLUMN_COLOR, &color,
-1);
updated_time = bjb_utils_get_human_time (mtime);
@@ -106,6 +111,17 @@ bjb_list_view_row_setup (BjbListViewRow *self,
}
if (updated_time)
gtk_label_set_text (self->updated_time, updated_time);
+ if (color && gdk_rgba_parse (&rgba, color))
+ {
+ css_style = g_strdup_printf ("row {color: %s; background-color: %s} row:hover {background-color:
darker(%s)}",
+ BJB_UTILS_COLOR_INTENSITY ((&rgba)) < 0.5 ? "white" : "black",
+ color, color);
+ self->css_provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (self->css_provider, css_style, -1, 0);
+ gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (self)),
+ GTK_STYLE_PROVIDER (self->css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ }
}
void
@@ -139,6 +155,7 @@ bjb_list_view_row_finalize (GObject *object)
{
BjbListViewRow *self = BJB_LIST_VIEW_ROW (object);
+ g_clear_object (&self->css_provider);
g_free (self->uuid);
g_free (self->model_iter);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]