From a53a1aafb9804e943bdcd720c2bb688ecb90a888 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 23 Oct 2026 11:12:56 -0300 Subject: Audit (colours, drawing): one Surface.tint, shared colour maths, the helix copies of hand-ported themes removed The 22 _helix themes that duplicate a hand-written port are gone; monokai, ayu_dark and nord stay, since others inherit from them. Co-Authored-By: Claude Opus 5.5 --- src/gui/gui.zig | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'src/gui') diff --git a/src/gui/gui.zig b/src/gui/gui.zig index d3734fac..2d01db33 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -8794,37 +8794,25 @@ fn clipToBodies(g: *Gui, gpa: std.mem.Allocator, first: usize, bodies: []const [ /// the decor pipeline blends a colour that is not black): the largest `a` /// that keeps text and page apart by min(their contrast, 4.5). fn lightenCeiling(fg: [3]u8, bg: [3]u8, rgb: [3]u8) f32 { - const contrast = struct { - fn of(a: [3]u8, b: [3]u8) f32 { - const la = luminance(a); - const lb = luminance(b); - return (@max(la, lb) + 0.05) / (@min(la, lb) + 0.05); - } - fn blend(under: [3]u8, over: [3]u8, a: f32) [3]u8 { + const contrast = pardes.colors.contrast; + const blend = struct { + fn of(under: [3]u8, over: [3]u8, a: f32) [3]u8 { var out: [3]u8 = undefined; for (&out, under, over) |*o, x, y| o.* = @intFromFloat(@round(@as(f32, @floatFromInt(x)) * (1 - a) + @as(f32, @floatFromInt(y)) * a)); return out; } - }; - const target = @min(contrast.of(fg, bg), 4.5); + }.of; + const target = @min(contrast(fg, bg), 4.5); var lo: f32 = 0; var hi: f32 = 1; for (0..24) |_| { const mid = (lo + hi) / 2; - if (contrast.of(contrast.blend(fg, rgb, mid), contrast.blend(bg, rgb, mid)) >= target - 1e-3) lo = mid else hi = mid; + if (contrast(blend(fg, rgb, mid), blend(bg, rgb, mid)) >= target - 1e-3) lo = mid else hi = mid; } return lo; } -/// sRGB's relative luminance (WCAG). -fn luminance(rgb: [3]u8) f32 { - var sum: f32 = 0; - for (rgb, [3]f32{ 0.2126, 0.7152, 0.0722 }) |channel, weight| { - const v = @as(f32, @floatFromInt(channel)) / 255; - sum += weight * (if (v <= 0.04045) v / 12.92 else std.math.pow(f32, (v + 0.055) / 1.055, 2.4)); - } - return sum; -} +const luminance = pardes.colors.relativeLuminance; /// How dark a shadow may make the page and its text, both together, before /// the pair drops below its own contrast or 4.5, whichever is lower (ยง8.2): @@ -8853,11 +8841,7 @@ test "a rim never lightens a native theme's text below its contrast or 4.5" { return out; } }.of; - const ratio = struct { - fn of(x: [3]u8, y: [3]u8) f32 { - return (@max(luminance(x), luminance(y)) + 0.05) / (@min(luminance(x), luminance(y)) + 0.05); - } - }.of; + const ratio = pardes.colors.contrast; try std.testing.expect(ratio(blend(fg, light, a), blend(bg, light, a)) >= @min(ratio(fg, bg), 4.5) - 2e-3); } } @@ -9206,11 +9190,7 @@ fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, gr } /// Halfway between two colours. -fn mixRgb(a: [3]u8, b: [3]u8) [3]u8 { - var out: [3]u8 = undefined; - for (&out, a, b) |*o, x, y| o.* = @intCast((@as(u16, x) + y) / 2); - return out; -} +const mixRgb = pardes.colors.mix; /// A rule's width: the theme's own, or one pixel. fn rulePx(chrome: *const pardes.Chrome) f32 { -- cgit v1.3