[gnome-builder/wip/gtk4-port: 1049/1774] libide/tree: use cell renderer pixbuf for git status
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1049/1774] libide/tree: use cell renderer pixbuf for git status
- Date: Mon, 11 Jul 2022 22:31:32 +0000 (UTC)
commit 92b53f46bd5d7206822ef80315fab6f7a4ce4ab5
Author: Christian Hergert <chergert redhat com>
Date: Tue May 17 14:03:42 2022 -0700
libide/tree: use cell renderer pixbuf for git status
This doesn't need custom drawing that can't be cached by the renderer
easily. Instead we will just switch to using a couple icons and rely on
symbolic loading and caching at lower levels.
.../actions/builder-vcs-added-symbolic.svg | 39 ++++
.../actions/builder-vcs-changed-symbolic.svg | 39 ++++
src/libide/tree/ide-cell-renderer-status.c | 198 +++------------------
src/libide/tree/ide-cell-renderer-status.h | 8 +-
src/libide/tree/ide-tree.c | 4 +-
5 files changed, 105 insertions(+), 183 deletions(-)
---
diff --git a/data/icons/hicolor/scalable/actions/builder-vcs-added-symbolic.svg
b/data/icons/hicolor/scalable/actions/builder-vcs-added-symbolic.svg
new file mode 100644
index 000000000..39924e697
--- /dev/null
+++ b/data/icons/hicolor/scalable/actions/builder-vcs-added-symbolic.svg
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ height="16px"
+ viewBox="0 0 16 16"
+ width="16px"
+ version="1.1"
+ id="svg95"
+ sodipodi:docname="builder-vcs-added-symbolic.svg"
+ inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg">
+ <defs
+ id="defs99" />
+ <sodipodi:namedview
+ id="namedview97"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageshadow="2"
+ inkscape:pageopacity="0.0"
+ inkscape:pagecheckerboard="0"
+ showgrid="false"
+ inkscape:zoom="72.25"
+ inkscape:cx="7.9930796"
+ inkscape:cy="8"
+ inkscape:window-width="2560"
+ inkscape:window-height="1371"
+ inkscape:window-x="0"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="svg95" />
+ <path
+ d="M 8,2.75 C 5.1083983,2.75 2.75,5.1083983 2.75,8 c 0,2.891602 2.3583983,5.25 5.25,5.25 2.891602,0
5.25,-2.358398 5.25,-5.25 C 13.25,5.1083983 10.891602,2.75 8,2.75 Z m 0,0"
+ fill="#2e3436"
+ id="path93"
+ style="stroke-width:0.75" />
+</svg>
diff --git a/data/icons/hicolor/scalable/actions/builder-vcs-changed-symbolic.svg
b/data/icons/hicolor/scalable/actions/builder-vcs-changed-symbolic.svg
new file mode 100644
index 000000000..4b7485e10
--- /dev/null
+++ b/data/icons/hicolor/scalable/actions/builder-vcs-changed-symbolic.svg
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ height="16px"
+ viewBox="0 0 16 16"
+ width="16px"
+ version="1.1"
+ id="svg183"
+ sodipodi:docname="builder-vcs-changed-symbolic.svg"
+ inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg">
+ <defs
+ id="defs187" />
+ <sodipodi:namedview
+ id="namedview185"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageshadow="2"
+ inkscape:pageopacity="0.0"
+ inkscape:pagecheckerboard="0"
+ showgrid="false"
+ inkscape:zoom="54.5625"
+ inkscape:cx="8"
+ inkscape:cy="8"
+ inkscape:window-width="1458"
+ inkscape:window-height="1088"
+ inkscape:window-x="26"
+ inkscape:window-y="23"
+ inkscape:window-maximized="0"
+ inkscape:current-layer="svg183" />
+ <path
+ d="M 7.9999998,2.75 C 5.1083982,2.75 2.75,5.1083983 2.75,8.0000002 2.75,10.891601 5.1083982,13.25
7.9999998,13.25 10.891602,13.25 13.25,10.891601 13.25,8.0000002 13.25,5.1083983 10.891602,2.75 7.9999998,2.75
Z m 0,1.5 C 10.065429,4.25 11.75,5.9345706 11.75,8.0000002 11.75,10.06543 10.065429,11.75 7.9999998,11.75
5.9345704,11.75 4.2499999,10.06543 4.2499999,8.0000002 4.2499999,5.9345706 5.9345704,4.25 7.9999998,4.25 Z m
0,0"
+ fill="#2e3436"
+ id="path181"
+ style="stroke-width:0.75" />
+</svg>
diff --git a/src/libide/tree/ide-cell-renderer-status.c b/src/libide/tree/ide-cell-renderer-status.c
index 1ca087bd2..7be50bddb 100644
--- a/src/libide/tree/ide-cell-renderer-status.c
+++ b/src/libide/tree/ide-cell-renderer-status.c
@@ -22,189 +22,37 @@
#include "config.h"
-#include <math.h>
-
#include "ide-cell-renderer-status.h"
-#define CELL_HEIGHT 16
-#define CELL_WIDTH 16
-#define RPAD 8
-#define LPAD 3
-
-struct _IdeCellRendererStatus
-{
- GtkCellRenderer parent_instance;
- IdeTreeNodeFlags flags;
-};
-
-enum {
- PROP_0,
- PROP_FLAGS,
- N_PROPS
-};
-
-G_DEFINE_FINAL_TYPE (IdeCellRendererStatus, ide_cell_renderer_status, GTK_TYPE_CELL_RENDERER)
-
-static GParamSpec *properties [N_PROPS];
-
-static void
-ide_cell_renderer_status_get_preferred_height (GtkCellRenderer *cell,
- GtkWidget *widget,
- gint *min_size,
- gint *nat_size)
-{
- g_assert (IDE_IS_CELL_RENDERER_STATUS (cell));
- g_assert (GTK_IS_WIDGET (widget));
-
- if (min_size)
- *min_size = CELL_HEIGHT;
-
- if (nat_size)
- *nat_size = CELL_HEIGHT;
-}
-
-static void
-ide_cell_renderer_status_get_preferred_width (GtkCellRenderer *cell,
- GtkWidget *widget,
- gint *min_size,
- gint *nat_size)
-{
- g_assert (IDE_IS_CELL_RENDERER_STATUS (cell));
- g_assert (GTK_IS_WIDGET (widget));
-
- if (min_size)
- *min_size = LPAD + CELL_WIDTH + RPAD;
-
- if (nat_size)
- *nat_size = LPAD + CELL_WIDTH + RPAD;
-}
-
-static void
-ide_cell_renderer_status_snapshot (GtkCellRenderer *cell,
- GtkSnapshot *snapshot,
- GtkWidget *widget,
- const GdkRectangle *bg_area,
- const GdkRectangle *cell_area,
- GtkCellRendererState state)
-{
- IdeCellRendererStatus *self = (IdeCellRendererStatus *)cell;
- GtkStyleContext *style_context;
- cairo_t *cr;
- GdkRGBA color;
-
- g_assert (IDE_IS_CELL_RENDERER_STATUS (self));
- g_assert (GTK_IS_WIDGET (widget));
- g_assert (bg_area != NULL);
- g_assert (cell_area != NULL);
-
- /* FIXME-GTK4: This should be ported to use symbolic icons instead */
-
- if (self->flags == 0)
- return;
-
- style_context = gtk_widget_get_style_context (widget);
- gtk_style_context_get_color (style_context, &color);
-
- cr = gtk_snapshot_append_cairo (snapshot,
- &GRAPHENE_RECT_INIT (cell_area->x,
- cell_area->y,
- cell_area->width,
- cell_area->height));
-
- cairo_translate (cr, cell_area->x, cell_area->y);
-
- cairo_arc (cr,
- cell_area->width - RPAD - (CELL_WIDTH/2),
- (cell_area->height / 2),
- 3,
- 0,
- M_PI * 2);
+#define VALUE_INIT_STATIC_STRING(name) \
+ { \
+ .g_type = G_TYPE_STRING, \
+ .data = { \
+ { .v_pointer = (char *)name }, \
+ { .v_uint = G_VALUE_NOCOPY_CONTENTS }, \
+ }, \
+ }
- gdk_cairo_set_source_rgba (cr, &color);
- if (self->flags & IDE_TREE_NODE_FLAGS_ADDED)
- cairo_fill_preserve (cr);
- cairo_stroke (cr);
-
- cairo_destroy (cr);
-}
-
-static void
-ide_cell_renderer_status_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- IdeCellRendererStatus *self = IDE_CELL_RENDERER_STATUS (object);
-
- switch (prop_id)
- {
- case PROP_FLAGS:
- g_value_set_uint (value, self->flags);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-ide_cell_renderer_status_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- IdeCellRendererStatus *self = IDE_CELL_RENDERER_STATUS (object);
-
- switch (prop_id)
- {
- case PROP_FLAGS:
- self->flags = g_value_get_uint (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-ide_cell_renderer_status_class_init (IdeCellRendererStatusClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkCellRendererClass *renderer_class = GTK_CELL_RENDERER_CLASS (klass);
-
- object_class->get_property = ide_cell_renderer_status_get_property;
- object_class->set_property = ide_cell_renderer_status_set_property;
-
- renderer_class->get_preferred_height = ide_cell_renderer_status_get_preferred_height;
- renderer_class->get_preferred_width = ide_cell_renderer_status_get_preferred_width;
- renderer_class->snapshot = ide_cell_renderer_status_snapshot;
-
- properties [PROP_FLAGS] =
- g_param_spec_uint ("flags",
- "Flags",
- "The flags for the state",
- 0, G_MAXUINT, 0,
- (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_properties (object_class, N_PROPS, properties);
-}
-
-static void
-ide_cell_renderer_status_init (IdeCellRendererStatus *self)
-{
-}
+static GValue added = VALUE_INIT_STATIC_STRING ("builder-vcs-added-symbolic");
+static GValue changed = VALUE_INIT_STATIC_STRING ("builder-vcs-changed-symbolic");
+static GValue empty = VALUE_INIT_STATIC_STRING (NULL);
GtkCellRenderer *
ide_cell_renderer_status_new (void)
{
- return g_object_new (IDE_TYPE_CELL_RENDERER_STATUS, NULL);
+ return g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF,
+ "xpad", 3,
+ NULL);
}
void
-ide_cell_renderer_status_set_flags (IdeCellRendererStatus *self,
- IdeTreeNodeFlags flags)
-{
- g_return_if_fail (IDE_IS_CELL_RENDERER_STATUS (self));
-
- self->flags = flags;
+ide_cell_renderer_status_set_flags (GtkCellRenderer *renderer,
+ IdeTreeNodeFlags flags)
+{
+ if (flags & IDE_TREE_NODE_FLAGS_ADDED)
+ g_object_set_property ((GObject *)renderer, "icon-name", &added);
+ else if (flags & IDE_TREE_NODE_FLAGS_CHANGED)
+ g_object_set_property ((GObject *)renderer, "icon-name", &changed);
+ else
+ g_object_set_property ((GObject *)renderer, "icon-name", &empty);
}
diff --git a/src/libide/tree/ide-cell-renderer-status.h b/src/libide/tree/ide-cell-renderer-status.h
index 1ed489c58..6ff70ce05 100644
--- a/src/libide/tree/ide-cell-renderer-status.h
+++ b/src/libide/tree/ide-cell-renderer-status.h
@@ -26,12 +26,8 @@
G_BEGIN_DECLS
-#define IDE_TYPE_CELL_RENDERER_STATUS (ide_cell_renderer_status_get_type())
-
-G_DECLARE_FINAL_TYPE (IdeCellRendererStatus, ide_cell_renderer_status, IDE, CELL_RENDERER_STATUS,
GtkCellRenderer)
-
GtkCellRenderer *ide_cell_renderer_status_new (void);
-void ide_cell_renderer_status_set_flags (IdeCellRendererStatus *self,
- IdeTreeNodeFlags flags);
+void ide_cell_renderer_status_set_flags (GtkCellRenderer *cell,
+ IdeTreeNodeFlags flags);
G_END_DECLS
diff --git a/src/libide/tree/ide-tree.c b/src/libide/tree/ide-tree.c
index 272c25a86..8917d8b07 100644
--- a/src/libide/tree/ide-tree.c
+++ b/src/libide/tree/ide-tree.c
@@ -144,7 +144,7 @@ state_cell_func (GtkCellLayout *layout,
if ((node = ide_tree_model_get_node (IDE_TREE_MODEL (model), iter)))
flags = ide_tree_node_get_flags (node);
- ide_cell_renderer_status_set_flags (IDE_CELL_RENDERER_STATUS (cell), flags);
+ ide_cell_renderer_status_set_flags (cell, flags);
}
static void
@@ -610,7 +610,7 @@ ide_tree_init (IdeTree *self)
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, TRUE);
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), cell, text_cell_func, self, NULL);
- cell = g_object_new (IDE_TYPE_CELL_RENDERER_STATUS, NULL);
+ cell = ide_cell_renderer_status_new ();
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), cell, state_cell_func, self, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]