[baobab/color-unify: 5/5] Use the same colors of the chart for the level bars
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/color-unify: 5/5] Use the same colors of the chart for the level bars
- Date: Sun, 28 Jun 2020 10:59:00 +0000 (UTC)
commit ee4e8244d11f673b72c6fe667321c5c0db0059df
Author: Stefano Facchini <stefano facchini gmail com>
Date: Tue Jun 16 16:19:47 2020 +0200
Use the same colors of the chart for the level bars
data/baobab.css | 24 ----------------
data/ui/baobab-main-window.ui | 1 +
src/baobab-cellrenderers.vala | 64 ++++++++++++++++++++++++++-----------------
3 files changed, 40 insertions(+), 49 deletions(-)
---
diff --git a/data/baobab.css b/data/baobab.css
index d229b4b..4c5ac4e 100644
--- a/data/baobab.css
+++ b/data/baobab.css
@@ -10,30 +10,6 @@
background-color: white;
}
-.cell.baobab-level-cell.fill-block,
-.cell.baobab-level-cell.fill-block:hover,
-.cell.baobab-level-cell.fill-block:selected,
-.cell.baobab-level-cell.fill-block:selected:hover {
- background-color: #edd400;
-}
-
-.cell.baobab-level-cell.fill-block.level-low,
-.cell.baobab-level-cell.fill-block.level-low:hover {
- background-color: #73d216;
-}
-
-.cell.baobab-level-cell.fill-block.level-high,
-.cell.baobab-level-cell.fill-block.level-high:hover {
- background-color: #cc0000;
-}
-
-.cell.baobab-level-cell.fill-block:backdrop,
-.cell.baobab-level-cell.fill-block:hover:backdrop,
-.cell.baobab-level-cell.fill-block.level-low:backdrop,
-.cell.baobab-level-cell.fill-block.level-high:backdrop {
- background-color: @theme_unfocused_text_color;
-}
-
.cell.baobab-cell-error {
color: @error_color;
}
diff --git a/data/ui/baobab-main-window.ui b/data/ui/baobab-main-window.ui
index 09727f4..9cdaf2d 100644
--- a/data/ui/baobab-main-window.ui
+++ b/data/ui/baobab-main-window.ui
@@ -270,6 +270,7 @@
<attributes>
<attribute name="value">1</attribute>
<attribute name="state">6</attribute>
+ <attribute name="color">7</attribute>
</attributes>
</child>
<child>
diff --git a/src/baobab-cellrenderers.vala b/src/baobab-cellrenderers.vala
index 23bae81..e9b7ec4 100644
--- a/src/baobab-cellrenderers.vala
+++ b/src/baobab-cellrenderers.vala
@@ -139,6 +139,15 @@ namespace Baobab {
public class CellRendererProgress : Gtk.CellRendererProgress {
public Scanner.State state { set; get; }
+ public Scanner.Color color { set; get; }
+
+ const string CSS_TEMPLATE = """
+ .cell.baobab-level-cell.fill-block { background: %s; }
+ .cell.baobab-level-cell.fill-block:backdrop,
+ .cell.baobab-level-cell.fill-block:hover:backdrop {
+ background-color: @theme_unfocused_text_color;
+ }""";
+
public override void render (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area,
Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
if (state == Scanner.State.ERROR) {
return;
@@ -161,34 +170,39 @@ namespace Baobab {
context.render_background (cr, x, y, w, h);
context.render_frame (cr, x, y, w, h);
- var border = context.get_border (Gtk.StateFlags.NORMAL);
- x += border.left;
- y += border.top;
- w -= border.left + border.right;
- h -= border.top + border.bottom;
-
- border = context.get_padding (Gtk.StateFlags.NORMAL);
- x += border.left;
- y += border.top;
- w -= border.left + border.right;
- h -= border.top + border.bottom;
-
- var percent = value;
- var perc_w = (w * percent) / 100;
- var x_bar = x;
- if (widget.get_direction () == Gtk.TextDirection.RTL) {
- x_bar += w - perc_w;
- }
+ if (color != null) {
+ var border = context.get_border (Gtk.StateFlags.NORMAL);
+ x += border.left;
+ y += border.top;
+ w -= border.left + border.right;
+ h -= border.top + border.bottom;
+
+ border = context.get_padding (Gtk.StateFlags.NORMAL);
+ x += border.left;
+ y += border.top;
+ w -= border.left + border.right;
+ h -= border.top + border.bottom;
+
+ var percent = value;
+ var perc_w = (w * percent) / 100;
+ var x_bar = x;
+ if (widget.get_direction () == Gtk.TextDirection.RTL) {
+ x_bar += w - perc_w;
+ }
- context.add_class ("fill-block");
+ context.add_class ("fill-block");
- if (percent <= 33) {
- context.add_class ("level-low");
- } else if (percent > 66) {
- context.add_class ("level-high");
- }
+ var provider = new Gtk.CssProvider ();
+ try {
+ provider.load_from_data (CSS_TEMPLATE.printf (color.color.to_string ()));
+ } catch {
+ }
+ context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
- context.render_background (cr, x_bar, y, perc_w, h);
+ context.render_background (cr, x_bar, y, perc_w, h);
+
+ context.remove_provider (provider);
+ }
context.restore ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]