[gtk/wip/jimmac/new-colors-fix9] ColorPicker: quick fix for the 9 column layout
- From: Jakub Steiner <jimmac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/jimmac/new-colors-fix9] ColorPicker: quick fix for the 9 column layout
- Date: Fri, 11 Sep 2020 15:20:01 +0000 (UTC)
commit 4f5be22f748957b7ec00efa2b6d9203691897b03
Author: Jakub Steiner <jimmac gmail com>
Date: Fri Sep 11 17:18:36 2020 +0200
ColorPicker: quick fix for the 9 column layout
- was still getting 9 custom colors so simply adding all the grey shades to
form 9 columns seems like a viable approach
gtk/gtkcolorchooserwidget.c | 100 ++++++++++++++++++++++++++++++++------------
1 file changed, 73 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c
index 5315e85975..1e77e820d9 100644
--- a/gtk/gtkcolorchooserwidget.c
+++ b/gtk/gtkcolorchooserwidget.c
@@ -31,7 +31,6 @@
#include "gtkstylecontext.h"
#include "gtkboxlayout.h"
#include "gtkwidgetprivate.h"
-#include "gdkrgbaprivate.h"
#include <math.h>
@@ -84,8 +83,6 @@ struct _GtkColorChooserWidget
gboolean has_default_palette;
GSettings *settings;
-
- int max_custom;
};
struct _GtkColorChooserWidgetClass
@@ -297,7 +294,8 @@ add_palette (GtkColorChooserWidget *cc,
GtkOrientation orientation,
int colors_per_line,
int n_colors,
- GdkRGBA *colors)
+ GdkRGBA *colors,
+ const char **names)
{
GtkWidget *grid;
GtkWidget *p;
@@ -316,6 +314,7 @@ add_palette (GtkColorChooserWidget *cc,
gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
gtk_grid_set_column_spacing (GTK_GRID (grid), 4);
gtk_box_append (GTK_BOX (cc->palette), grid);
+
left = 0;
right = colors_per_line - 1;
@@ -354,11 +353,6 @@ add_palette (GtkColorChooserWidget *cc,
gtk_grid_attach (GTK_GRID (grid), p, line, pos, 1, 1);
}
}
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- cc->max_custom = MAX (cc->max_custom, colors_per_line);
- else
- cc->max_custom = MAX (cc->max_custom, n_colors / colors_per_line);
}
static void
@@ -369,24 +363,60 @@ remove_default_palette (GtkColorChooserWidget *cc)
remove_palette (cc);
cc->has_default_palette = FALSE;
- cc->max_custom = 0;
}
static void
add_default_palette (GtkColorChooserWidget *cc)
{
- GdkRGBA colors[8*3] = {
- GDK_RGBA("99c1f1"), GDK_RGBA("3584e4"), GDK_RGBA("1a5fb4"), /* Blue */
- GDK_RGBA("8ff0a4"), GDK_RGBA("33d17a"), GDK_RGBA("26a269"), /* Green */
- GDK_RGBA("f9f06b"), GDK_RGBA("f6d32d"), GDK_RGBA("e5a50a"), /* Yellow */
- GDK_RGBA("ffbe6f"), GDK_RGBA("ff7800"), GDK_RGBA("c64600"), /* Orange */
- GDK_RGBA("f66151"), GDK_RGBA("e01b24"), GDK_RGBA("a51d2d"), /* Red */
- GDK_RGBA("dc8add"), GDK_RGBA("9141ac"), GDK_RGBA("613583"), /* Purple */
- GDK_RGBA("cdab8f"), GDK_RGBA("986a44"), GDK_RGBA("63452c"), /* Brown */
- GDK_RGBA("f6f5f4"), GDK_RGBA("9a9996"), GDK_RGBA("3d3846") /* Neutral */
+ const char *default_colors[9][3] = {
+ { "#99c1f1", "#3584e4", "#1a5fb4" }, /* Blue */
+ { "#8ff0a4", "#33d17a", "#26a269" }, /* Green */
+ { "#f9f06b", "#f6d32d", "#e5a50a" }, /* Yellow */
+ { "#ffbe6f", "#ff7800", "#c64600" }, /* Orange */
+ { "#f66151", "#e01b24", "#a51d2d" }, /* Red */
+ { "#dc8add", "#9141ac", "#613583" }, /* Purple */
+ { "#cdab8f", "#986a44", "#63452c" }, /* Brown */
+ { "#f6f5f4", "#deddda", "#c0bfbc" }, /* Neutral */
+ { "#9a9996", "#77767b", "#5e5c64" } /* Neutral */
};
+ const char *color_names[] = {
+ NC_("Color name", "Blue 1"),
+ NC_("Color name", "Blue 2"),
+ NC_("Color name", "Blue 3"),
+ NC_("Color name", "Green 1"),
+ NC_("Color name", "Green 2"),
+ NC_("Color name", "Green 3"),
+ NC_("Color name", "Yellow 1"),
+ NC_("Color name", "Yellow 2"),
+ NC_("Color name", "Yellow 3"),
+ NC_("Color name", "Orange 1"),
+ NC_("Color name", "Orange 2"),
+ NC_("Color name", "Orange 3"),
+ NC_("Color name", "Red 1"),
+ NC_("Color name", "Red 2"),
+ NC_("Color name", "Red 3"),
+ NC_("Color name", "Purple 1"),
+ NC_("Color name", "Purple 2"),
+ NC_("Color name", "Purple 3"),
+ NC_("Color name", "Brown 1"),
+ NC_("Color name", "Brown 2"),
+ NC_("Color name", "Brown 3"),
+ NC_("Color name", "Neutral 1"),
+ NC_("Color name", "Neutral 2"),
+ NC_("Color name", "Neutral 3"),
+ NC_("Color name", "Neutral 4"),
+ NC_("Color name", "Neutral 5"),
+ NC_("Color name", "Neutral 6")
+ };
+
+ GdkRGBA colors[9*3];
+ int i, j;
- add_palette (cc, GTK_ORIENTATION_VERTICAL, 3, 8*3, colors);
+ for (i = 0; i < 9; i++)
+ for (j = 0; j < 3; j++)
+ gdk_rgba_parse (&colors[i*3 + j], default_colors[i][j]);
+
+ add_palette (cc, GTK_ORIENTATION_VERTICAL, 3, 9*3, colors, color_names);
cc->has_default_palette = TRUE;
}
@@ -488,7 +518,7 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
connect_custom_signals (p, cc);
gtk_box_append (GTK_BOX (box), p);
- if (i == 8)
+ if (i == 9)
break;
}
g_variant_unref (variant);
@@ -674,16 +704,16 @@ add_custom_color (GtkColorChooserWidget *cc,
const GdkRGBA *color)
{
GtkWidget *widget;
+ GList *children;
GtkWidget *p;
- int n;
- n = 0;
+ children = NULL;
for (widget = gtk_widget_get_first_child (cc->custom);
widget != NULL;
widget = gtk_widget_get_next_sibling (widget))
- n++;
+ children = g_list_prepend (children, widget);
- while (n >= cc->max_custom)
+ if (g_list_length (children) >= 9)
{
GtkWidget *last = gtk_widget_get_last_child (cc->custom);
@@ -691,8 +721,8 @@ add_custom_color (GtkColorChooserWidget *cc,
cc->current = NULL;
gtk_box_remove (GTK_BOX (cc->custom), last);
- n--;
}
+ g_list_free (children);
p = gtk_color_swatch_new ();
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), color);
@@ -751,7 +781,7 @@ gtk_color_chooser_widget_add_palette (GtkColorChooser *chooser,
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (chooser);
remove_default_palette (cc);
- add_palette (cc, orientation, colors_per_line, n_colors, colors);
+ add_palette (cc, orientation, colors_per_line, n_colors, colors, NULL);
gtk_box_reorder_child_after (GTK_BOX (cc->palette), cc->custom_label, gtk_widget_get_last_child
(cc->palette));
gtk_box_reorder_child_after (GTK_BOX (cc->palette), cc->custom, cc->custom_label);
@@ -765,3 +795,19 @@ gtk_color_chooser_widget_iface_init (GtkColorChooserInterface *iface)
iface->add_palette = gtk_color_chooser_widget_add_palette;
}
+/* Public API {{{1 */
+
+/**
+ * gtk_color_chooser_widget_new:
+ *
+ * Creates a new #GtkColorChooserWidget.
+ *
+ * Returns: a new #GtkColorChooserWidget
+ */
+GtkWidget *
+gtk_color_chooser_widget_new (void)
+{
+ return g_object_new (GTK_TYPE_COLOR_CHOOSER_WIDGET, NULL);
+}
+
+/* vim:set foldmethod=marker: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]