[gtk/wip/otte/canvas: 33/36] canvas: Give variable vectors a name
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/canvas: 33/36] canvas: Give variable vectors a name
- Date: Tue, 5 Jul 2022 05:41:42 +0000 (UTC)
commit 5ce8c1d397bfb9d57c05b9d60d7167a740557870
Author: Benjamin Otte <otte redhat com>
Date: Tue Jul 5 06:39:29 2022 +0200
canvas: Give variable vectors a name
And use it when printing.
gtk/gtkcanvas.c | 2 +-
gtk/gtkcanvasbox.c | 19 +++++++++++++++----
gtk/gtkcanvasboxprivate.h | 4 +++-
gtk/gtkcanvasitem.c | 12 ++++++------
gtk/gtkcanvasvectorimpl.c | 26 ++++++++++++++++++++------
gtk/gtkcanvasvectorprivate.h | 5 ++++-
6 files changed, 49 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkcanvas.c b/gtk/gtkcanvas.c
index 57116c66f2..348eb13921 100644
--- a/gtk/gtkcanvas.c
+++ b/gtk/gtkcanvas.c
@@ -381,7 +381,7 @@ gtk_canvas_init (GtkCanvas *self)
{
self->item_lookup = g_hash_table_new (g_direct_hash, g_direct_equal);
- gtk_canvas_vector_init_variable (&self->viewport_size);
+ gtk_canvas_vector_init_variable (&self->viewport_size, "viewport.size");
}
/**
diff --git a/gtk/gtkcanvasbox.c b/gtk/gtkcanvasbox.c
index 72fe87c428..56388c2bab 100644
--- a/gtk/gtkcanvasbox.c
+++ b/gtk/gtkcanvasbox.c
@@ -64,11 +64,22 @@ gtk_canvas_box_finish (GtkCanvasBox *self)
}
void
-gtk_canvas_box_init_variable (GtkCanvasBox *self)
+gtk_canvas_box_init_variable (GtkCanvasBox *self,
+ const char *format,
+ ...)
{
- gtk_canvas_vector_init_variable (&self->point);
- gtk_canvas_vector_init_variable (&self->size);
- gtk_canvas_vector_init_variable (&self->origin);
+ char *name;
+ va_list args;
+
+ va_start (args, format);
+ name = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ gtk_canvas_vector_init_variable (&self->point, "%s.point", name);
+ gtk_canvas_vector_init_variable (&self->size, "%s.size", name);
+ gtk_canvas_vector_init_variable (&self->origin, "%s.origin", name);
+
+ g_free (name);
}
void
diff --git a/gtk/gtkcanvasboxprivate.h b/gtk/gtkcanvasboxprivate.h
index 7aa13e61a3..1d6256495e 100644
--- a/gtk/gtkcanvasboxprivate.h
+++ b/gtk/gtkcanvasboxprivate.h
@@ -23,7 +23,9 @@ void gtk_canvas_box_init_copy (GtkCanvasBox
const GtkCanvasBox *source);
void gtk_canvas_box_finish (GtkCanvasBox *self);
-void gtk_canvas_box_init_variable (GtkCanvasBox *self);
+void gtk_canvas_box_init_variable (GtkCanvasBox *self,
+ const char *format,
+ ...) G_GNUC_PRINTF(2,3);
void gtk_canvas_box_update_variable (GtkCanvasBox *self,
const GtkCanvasBox *other);
diff --git a/gtk/gtkcanvasitem.c b/gtk/gtkcanvasitem.c
index 893f505b98..0ed91e7291 100644
--- a/gtk/gtkcanvasitem.c
+++ b/gtk/gtkcanvasitem.c
@@ -205,17 +205,17 @@ gtk_canvas_item_class_init (GtkCanvasItemClass *klass)
static void
gtk_canvas_item_init (GtkCanvasItem *self)
{
- int i;
-
- for (i = 0; i < 4; i++)
- gtk_canvas_vector_init_variable (&self->size_vecs[i]);
+ gtk_canvas_vector_init_variable (&self->size_vecs[0], "item%p.min_for_min", self);
+ gtk_canvas_vector_init_variable (&self->size_vecs[1], "item%p.min_for_nat", self);
+ gtk_canvas_vector_init_variable (&self->size_vecs[2], "item%p.nat_for_min", self);
+ gtk_canvas_vector_init_variable (&self->size_vecs[3], "item%p.nat_for_nat", self);
gtk_canvas_vector_init_constant (&self->bounds.point, 0, 0);
gtk_canvas_vector_init_copy (&self->bounds.size, &self->size_vecs[GTK_CANVAS_ITEM_MEASURE_NAT_FOR_NAT]);
gtk_canvas_vector_init_constant (&self->bounds.origin, 0.5, 0.5);
- gtk_canvas_box_init_variable (&self->bounds_var);
+ gtk_canvas_box_init_variable (&self->bounds_var, "item%p.bounds", self);
gtk_canvas_box_update_variable (&self->bounds_var, &self->bounds);
- gtk_canvas_box_init_variable (&self->allocation_var);
+ gtk_canvas_box_init_variable (&self->allocation_var, "item%p.allocation", self);
}
GtkCanvasItem *
diff --git a/gtk/gtkcanvasvectorimpl.c b/gtk/gtkcanvasvectorimpl.c
index dd57bfb74b..6b1d657b38 100644
--- a/gtk/gtkcanvasvectorimpl.c
+++ b/gtk/gtkcanvasvectorimpl.c
@@ -361,6 +361,7 @@ gtk_canvas_vector_init_multiply (GtkCanvasVector *vector,
static void
gtk_canvas_vector_init_variable_with_variable (GtkCanvasVector *vector,
+ const char *name,
GtkCanvasVector *variable);
static void
@@ -369,7 +370,9 @@ gtk_canvas_vector_variable_copy (GtkCanvasVector *vector,
{
const GtkCanvasVectorVariable *source = &source_vector->variable;
- gtk_canvas_vector_init_variable_with_variable (vector, g_rc_box_acquire (source->variable));
+ gtk_canvas_vector_init_variable_with_variable (vector,
+ source->name,
+ g_rc_box_acquire (source->variable));
}
static void
@@ -377,6 +380,7 @@ gtk_canvas_vector_variable_finish (GtkCanvasVector *vector)
{
const GtkCanvasVectorVariable *self = &vector->variable;
+ g_free (self->name);
g_rc_box_release (self->variable);
}
@@ -386,9 +390,7 @@ gtk_canvas_vector_variable_print (const GtkCanvasVector *vector,
{
const GtkCanvasVectorVariable *self = &vector->variable;
- g_string_append (string, "(");
- gtk_canvas_vector_print (self->variable, string);
- g_string_append (string, ")");
+ g_string_append (string, self->name);
}
static gboolean
@@ -411,24 +413,36 @@ static const GtkCanvasVectorClass GTK_CANVAS_VECTOR_VARIABLE_CLASS =
static void
gtk_canvas_vector_init_variable_with_variable (GtkCanvasVector *vector,
+ const char *name,
GtkCanvasVector *variable)
{
GtkCanvasVectorVariable *self = &vector->variable;
self->class = >K_CANVAS_VECTOR_VARIABLE_CLASS;
+ self->name = g_strdup (name);
self->variable = variable;
}
void
-gtk_canvas_vector_init_variable (GtkCanvasVector *vector)
+gtk_canvas_vector_init_variable (GtkCanvasVector *vector,
+ const char *format,
+ ...)
{
GtkCanvasVector *variable;
+ char *name;
+ va_list args;
variable = g_rc_box_new (GtkCanvasVector);
gtk_canvas_vector_init_invalid (variable);
- gtk_canvas_vector_init_variable_with_variable (vector, variable);
+ va_start (args, format);
+ name = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ gtk_canvas_vector_init_variable_with_variable (vector, name, variable);
+
+ g_free (name);
}
GtkCanvasVector *
diff --git a/gtk/gtkcanvasvectorprivate.h b/gtk/gtkcanvasvectorprivate.h
index 596fc079ed..86171e62fb 100644
--- a/gtk/gtkcanvasvectorprivate.h
+++ b/gtk/gtkcanvasvectorprivate.h
@@ -63,6 +63,7 @@ struct _GtkCanvasVectorVariable
{
const GtkCanvasVectorClass *class;
+ char *name;
/* a GtkRcBox */
GtkCanvasVector *variable;
};
@@ -102,7 +103,9 @@ void gtk_canvas_vector_init_multiply (GtkCanvasVector
const GtkCanvasVector *a,
const GtkCanvasVector *b);
-void gtk_canvas_vector_init_variable (GtkCanvasVector *vector);
+void gtk_canvas_vector_init_variable (GtkCanvasVector *vector,
+ const char *format,
+ ...) G_GNUC_PRINTF(2,3);
GtkCanvasVector * gtk_canvas_vector_get_variable (GtkCanvasVector *vector);
gboolean gtk_canvas_vector_is_invalid (GtkCanvasVector *vector);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]