diff options
author | Matthias Clasen <mclasen@redhat.com> | 2023-05-12 14:48:45 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2023-05-12 15:00:13 -0400 |
commit | 494cff94d6c4fb0410ae2086d4c82db825eafade (patch) | |
tree | 670cd6336f808fd96dc39a71a329e509601262d3 | |
parent | 17644b12a55f67e4a1c8f70c155be07eef568bc3 (diff) | |
download | gtk+-494cff94d6c4fb0410ae2086d4c82db825eafade.tar.gz |
css: Make some corner values static
Provide static value for uniform corners
with lengths from 0 to 8px. This covers
the majority of corners in widget-factory.
-rw-r--r-- | gtk/gtkcsscornervalue.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/gtk/gtkcsscornervalue.c b/gtk/gtkcsscornervalue.c index c5dbf51c16..0986d77eeb 100644 --- a/gtk/gtkcsscornervalue.c +++ b/gtk/gtkcsscornervalue.c @@ -88,7 +88,7 @@ gtk_css_value_corner_transition (GtkCssValue *start, static void gtk_css_value_corner_print (const GtkCssValue *corner, - GString *string) + GString *string) { _gtk_css_value_print (corner->x, string); if (!_gtk_css_value_equal (corner->x, corner->y)) @@ -109,12 +109,57 @@ static const GtkCssValueClass GTK_CSS_VALUE_CORNER = { gtk_css_value_corner_print }; +static GtkCssValue corner_singletons[] = { + { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL }, + { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL }, + { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL }, + { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL }, + { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL }, + { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL }, + { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL }, + { >K_CSS_VALUE_CORNER, 1, TRUE, NULL, NULL }, +}; + +static inline void +initialize_corner_singletons (void) +{ + static gboolean initialized = FALSE; + + if (initialized) + return; + + for (unsigned int i = 0; i < G_N_ELEMENTS (corner_singletons); i++) + { + corner_singletons[i].x = gtk_css_dimension_value_new (i, GTK_CSS_PX); + corner_singletons[i].y = gtk_css_value_ref (corner_singletons[i].x); + } + + initialized = TRUE; +} + GtkCssValue * _gtk_css_corner_value_new (GtkCssValue *x, GtkCssValue *y) { GtkCssValue *result; + if (x == y && + gtk_css_number_value_get_dimension (x) == GTK_CSS_DIMENSION_LENGTH) + { + initialize_corner_singletons (); + + for (unsigned int i = 0; i < G_N_ELEMENTS (corner_singletons); i++) + { + if (corner_singletons[i].x == x) + { + gtk_css_value_unref (x); + gtk_css_value_unref (y); + + return gtk_css_value_ref (&corner_singletons[i]); + } + } + } + result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_CORNER); result->x = x; result->y = y; |