diff options
| author | Marvin W <git@larma.de> | 2025-04-10 13:05:20 +0200 |
|---|---|---|
| committer | Marvin W <git@larma.de> | 2025-04-10 13:05:20 +0200 |
| commit | 643a31535b44c369edc8c5d601b1b14a3db2f207 (patch) | |
| tree | 1df4d2a9b0b3bb8dffdbee782da5101a9f194e20 /main/src/ui/util/helper.vala | |
| parent | e6e1d4aef4320957ba0856324e2f261ed9e679b0 (diff) | |
Clamp color channel values before converting to hex
This is needed as `GdkRGBA` may return out of range values when doing
colorspace conversion.
See https://gitlab.gnome.org/GNOME/gtk/-/issues/7488
Diffstat (limited to 'main/src/ui/util/helper.vala')
| -rw-r--r-- | main/src/ui/util/helper.vala | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index 60e0e81c..1e3b4c7e 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -90,10 +90,10 @@ public static Gdk.RGBA get_label_pango_color(Label label, string css_color) { 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))) + (uint8)(Math.round(rgba.red.clamp(0,1)*255)), + (uint8)(Math.round(rgba.green.clamp(0,1)*255)), + (uint8)(Math.round(rgba.blue.clamp(0,1)*255)), + (uint8)(Math.round(rgba.alpha.clamp(0,1)*255))) .up(); } |
