DVUI

fromHex

Converts hex color string to Color

If hex_color is invalid, an error is logged and a default color is returned. In comptime an invalid hex_color will cause a compile error.

See tryFromHex for a version that returns an error.

Supports the following formats:

  • #RGB
  • #RGBA
  • #RRGGBB
  • #RRGGBBAA
  • RGB
  • RGBA
  • RRGGBB
  • RRGGBBAA

Parameters

#
hex_color:[]const u8
[]const u8

Source

Implementation

#
pub fn fromHex(hex_color: []const u8) Color {
    return tryFromHex(hex_color) catch |err| if (@inComptime()) {
        @compileError(std.fmt.comptimePrint("Failed to parse hex color string: {any}", .{err}));
    } else {
        std.log.err("Failed to parse hex color string: {any}", .{err});
        return magenta;
    };
}