diff --git a/src/config/Config.zig b/src/config/Config.zig index d468cf0e1..7fcae46b6 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1982,7 +1982,7 @@ pub const OptionAsAlt = enum { }; /// Color represents a color using RGB. -pub const Color = struct { +pub const Color = packed struct(u24) { r: u8, g: u8, b: u8, @@ -1992,21 +1992,6 @@ pub const Color = struct { return .{ .r = self.r, .g = self.g, .b = self.b }; } - // Pack into an integer - pub fn toInt(self: Color) u24 { - // u24 covers RGB, typically, an alpha would pack to a full u32 - return (@as(u24, self.r) << 16) + (@as(u24, self.g) << 8) + self.b; - } - - test "toInt" { - const testing = std.testing; - - try testing.exectEqual((Color{ .r = 0, .g = 0, .b = 0 }).toInt(), 0); - try testing.exectEqual((Color{ .r = 255, .g = 255, .b = 255 }).toInt(), 16777215); - try testing.exectEqual((Color{ .r = 100, .g = 20, .b = 12 }).toInt(), 6558732); - try testing.exectEqual((Color{ .r = 55, .g = 63, .b = 202 }).toInt(), 3620810); - } - pub fn parseCLI(input: ?[]const u8) !Color { return fromHex(input orelse return error.ValueRequired); } diff --git a/src/config/c_get.zig b/src/config/c_get.zig index 8032dce46..0305100a6 100644 --- a/src/config/c_get.zig +++ b/src/config/c_get.zig @@ -41,7 +41,7 @@ pub fn get(config: *const Config, k: Key, ptr_raw: *anyopaque) bool { Color => { const ptr: *c_uint = @ptrCast(@alignCast(ptr_raw)); - ptr.* = value.toInt(); + ptr.* = @as(c_uint, @as(u24, @bitCast(value))); }, else => |T| switch (@typeInfo(T)) {