diff options
author | fiaxh <git@lightrise.org> | 2021-08-14 20:22:52 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2021-08-17 22:32:33 +0200 |
commit | 447464f4d1ac0c184764f103ac9e51f7ff2dce91 (patch) | |
tree | df4aab32001564c5aa706500ce6e7d68904e2d47 /main/src/ui/util | |
parent | cf8501ba30e26bbc02b42204acf5cff650b338f4 (diff) | |
download | dino-447464f4d1ac0c184764f103ac9e51f7ff2dce91.tar.gz dino-447464f4d1ac0c184764f103ac9e51f7ff2dce91.zip |
Display message delivery error, color text using theme colors
fixes #672
Diffstat (limited to 'main/src/ui/util')
-rw-r--r-- | main/src/ui/util/helper.vala | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index 07c81167..d5967ef3 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -154,10 +154,33 @@ public static void image_set_from_scaled_pixbuf(Image image, Gdk.Pixbuf pixbuf, image.set_from_surface(surface); } +public static Gdk.RGBA get_label_pango_color(Label label, string css_color) { + Gtk.CssProvider provider = force_color(label, css_color); + Gdk.RGBA color_rgba = label.get_style_context().get_color(StateFlags.NORMAL); + label.get_style_context().remove_provider(provider); + return color_rgba; +} + +public static Gdk.RGBA get_label_pango_class_color(Label label, string css_class) { + label.get_style_context().add_class(css_class); + Gdk.RGBA color_rgba = label.get_style_context().get_color(StateFlags.NORMAL); + label.get_style_context().remove_class(css_class); + return color_rgba; +} + +public static string rgba_to_hex(Gdk.RGBA rgba) { + return "#%02x%02x%02x%02x".printf( + (uint)(Math.round(rgba.red*255)), + (uint)(Math.round(rgba.green*255)), + (uint)(Math.round(rgba.blue*255)), + (uint)(Math.round(rgba.alpha*255))) + .up(); +} + private const string force_background_css = "%s { background-color: %s; }"; private const string force_color_css = "%s { color: %s; }"; -public static void force_css(Gtk.Widget widget, string css) { +public static Gtk.CssProvider force_css(Gtk.Widget widget, string css) { var p = new Gtk.CssProvider(); try { p.load_from_data(css); @@ -165,14 +188,15 @@ public static void force_css(Gtk.Widget widget, string css) { } catch (GLib.Error err) { // handle err } + return p; } public static void force_background(Gtk.Widget widget, string color, string selector = "*") { force_css(widget, force_background_css.printf(selector, color)); } -public static void force_color(Gtk.Widget widget, string color, string selector = "*") { - force_css(widget, force_color_css.printf(selector, color)); +public static Gtk.CssProvider force_color(Gtk.Widget widget, string color, string selector = "*") { + return force_css(widget, force_color_css.printf(selector, color)); } public static void force_error_color(Gtk.Widget widget, string selector = "*") { |