[baobab] Move color definitions to the CSS
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab] Move color definitions to the CSS
- Date: Sat, 13 Jun 2020 08:18:07 +0000 (UTC)
commit 7b242fd47dbcf1849709f44a019b9d1bd2967327
Author: Stefano Facchini <stefano facchini gmail com>
Date: Fri Jun 12 19:14:44 2020 +0200
Move color definitions to the CSS
And do some cleanup.
data/baobab.css | 10 ++++++++++
src/baobab-chart.vala | 28 +++++++++++++---------------
src/baobab-ringschart.vala | 9 ++-------
3 files changed, 25 insertions(+), 22 deletions(-)
---
diff --git a/data/baobab.css b/data/baobab.css
index b246959..c6e131b 100644
--- a/data/baobab.css
+++ b/data/baobab.css
@@ -65,6 +65,16 @@ window infobar.error {
border-bottom-color: @borders;
}
+@define-color tango_color_0 #ef2929;
+@define-color tango_color_1 #ad7fa8;
+@define-color tango_color_2 #729fcf;
+@define-color tango_color_3 #8ae234;
+@define-color tango_color_4 #e9b96e;
+@define-color tango_color_5 #fcaf3e;
+
+@define-color level_color #d3d6d1;
+@define-color level_color_hi #e0e2dd;
+
@define-color chart_borders darker(@borders);
ringschart {
padding: 13px 13px 13px 13px;
diff --git a/src/baobab-chart.vala b/src/baobab-chart.vala
index 1e658e7..0e490a7 100644
--- a/src/baobab-chart.vala
+++ b/src/baobab-chart.vala
@@ -54,12 +54,8 @@ namespace Baobab {
protected const uint MAX_DEPTH = 5;
protected const uint MIN_DEPTH = 1;
- const Gdk.RGBA TANGO_COLORS[] = {{0.94, 0.16, 0.16, 1.0}, /* tango: ef2929 */
- {0.68, 0.49, 0.66, 1.0}, /* tango: ad7fa8 */
- {0.45, 0.62, 0.82, 1.0}, /* tango: 729fcf */
- {0.54, 0.89, 0.20, 1.0}, /* tango: 8ae234 */
- {0.91, 0.73, 0.43, 1.0}, /* tango: e9b96e */
- {0.99, 0.68, 0.25, 1.0}}; /* tango: fcaf3e */
+ // Keep in sync with colors defined in CSS
+ const int NUM_TANGO_COLORS = 6;
uint name_column;
uint display_name_column;
@@ -456,23 +452,25 @@ namespace Baobab {
}
protected Gdk.RGBA get_item_color (double rel_position, uint depth, bool highlighted) {
- const Gdk.RGBA level_color = {0.83, 0.84, 0.82, 1.0};
- const Gdk.RGBA level_color_hi = {0.88, 0.89, 0.87, 1.0};
-
+ var context = get_style_context ();
var color = Gdk.RGBA ();
double intensity = 1 - (((depth - 1) * 0.3) / MAX_DEPTH);
if (depth == 0) {
- color = level_color;
+ context.lookup_color ("level_color", out color);
} else {
+ Gdk.RGBA color_a, color_b;
+
int color_number = (int) (rel_position / (100.0/3));
- int next_color_number = (color_number + 1) % 6;
+ int next_color_number = (color_number + 1) % NUM_TANGO_COLORS;
+
+ context.lookup_color ("tango_color_" + color_number.to_string (), out color_a);
+ context.lookup_color ("tango_color_" + next_color_number.to_string (), out color_b);
+
+ color = interpolate_colors (color_a, color_b, (rel_position - color_number * 100/3) /
(100/3));
- color = interpolate_colors (TANGO_COLORS[color_number],
- TANGO_COLORS[next_color_number],
- (rel_position - color_number * 100/3) / (100/3));
color.red *= intensity;
color.green *= intensity;
color.blue *= intensity;
@@ -480,7 +478,7 @@ namespace Baobab {
if (highlighted) {
if (depth == 0) {
- color = level_color_hi;
+ context.lookup_color ("level_color_hi", out color);
} else {
double maximum = double.max (color.red, double.max (color.green, color.blue));
color.red /= maximum;
diff --git a/src/baobab-ringschart.vala b/src/baobab-ringschart.vala
index 0a80067..b1c5e39 100644
--- a/src/baobab-ringschart.vala
+++ b/src/baobab-ringschart.vala
@@ -240,14 +240,11 @@ namespace Baobab {
get_allocation (out allocation);
var context = get_style_context ();
- context.save ();
-
- var toplevel_context = get_toplevel ().get_style_context ();
Gdk.RGBA border_color;
- context.lookup_color ("chart_borders", out border_color);
Gdk.RGBA bg_color;
- toplevel_context.lookup_color ("theme_bg_color", out bg_color);
+ context.lookup_color ("chart_borders", out border_color);
+ context.lookup_color ("theme_bg_color", out bg_color);
var center_x = allocation.width / 2;
var center_y = allocation.height / 2;
@@ -294,8 +291,6 @@ namespace Baobab {
cr.stroke ();
}
}
-
- context.restore ();
}
protected override void calculate_item_geometry (ChartItem item) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]