diff options
Diffstat (limited to 'core/colors.zig')
| -rw-r--r-- | core/colors.zig | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/core/colors.zig b/core/colors.zig index b2069465..4f58aed5 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -586,7 +586,8 @@ pub const ChromeTheme = struct { .search_bg = th.search_bg orelse th.sel_bg, .search_fg = th.search_fg orelse th.sel_fg, .tag_reading_bg = reading, - .diagnostic_error = th.diagnostic_error orelse (th.fg orelse th.tag_fg), + // A theme's error ink, else its palette's red (UX E3). + .diagnostic_error = th.diagnostic_error orelse if (th.palette) |pal| pal[1] else (th.fg orelse th.tag_fg), .diagnostic_warning = th.diagnostic_warning orelse (th.fg orelse th.tag_fg), .diagnostic_info = th.diagnostic_info orelse (th.fg orelse th.tag_fg), .diagnostic_hint = th.diagnostic_hint orelse (th.fg orelse th.tag_fg), @@ -643,8 +644,8 @@ pub const Roles = struct { pub const rule_floor: f32 = 1.8; pub const rule_ceiling: f32 = 2.5; pub const ink_floor: f32 = 4.5; - pub const hit_floor: f32 = 1.25; - pub const hit_current_floor: f32 = 1.6; + pub const hit_floor: f32 = 1.5; + pub const hit_current_floor: f32 = 1.9; pub const reading_distance: f32 = 0.04; pub fn on(r: *const Roles, ground: TagGround) *const Inks { @@ -692,7 +693,7 @@ pub const Roles = struct { if (contrast(r.hit_current, page) < contrast(r.hit, page)) r.hit_current = r.hit; const message_grounds = [_][3]u8{ plain, focused, reading, page }; const ink = th.fg orelse th.tag_fg; - r.err = pushAway(th.diagnostic_error orelse ink, &message_grounds, ink_floor); + r.err = pushAway(th.diagnostic_error orelse if (th.palette) |pal| pal[1] else ink, &message_grounds, ink_floor); r.warn = pushAway(th.diagnostic_warning orelse ink, &message_grounds, ink_floor); r.question = pushAway(th.diagnostic_info orelse ink, &message_grounds, ink_floor); r.hint = pushAway(th.diagnostic_hint orelse ink, &message_grounds, ink_floor); @@ -794,8 +795,10 @@ fn selectionOf(own: [3]u8, ground: [3]u8, text: [3]u8) [3]u8 { /// A ground off `page` toward `hue` at `t` (past 1, beyond the hue, as far /// as the gamut goes), held where the body's `ink` reads on it at 4.5:1 -/// (or its own on the page, where that is less); moved on toward the ink -/// until it stands off the page at `floor`, as far as the ink allows. +/// (or its own on the page, where that is less); on toward the hue, the +/// least way that stands off the page at `floor`, where the ink still +/// reads on it; else moved on toward the ink until it stands off the page +/// at `floor`, as far as the ink allows. fn hitOf(page: [3]u8, hue: [3]u8, ink: [3]u8, t: f32, floor: f32) [3]u8 { const a = toOklab(page); const b = toOklab(hue); @@ -806,6 +809,22 @@ fn hitOf(page: [3]u8, hue: [3]u8, ink: [3]u8, t: f32, floor: f32) [3]u8 { k -= t / 50; c = fromOklab(.{ a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k }); } + // Found by halves, seven mixes: the nearer the hue, the further off + // the page (UX E7 7b: a landing line 1.5:1, its span 1.9:1). + if (contrast(c, page) < floor and k < 1 and contrast(hue, page) >= floor) { + var lo = k; + var hi: f32 = 1; + var far = hue; + for (0..7) |_| { + const mid = (lo + hi) / 2; + const m = fromOklab(.{ a[0] + (b[0] - a[0]) * mid, a[1] + (b[1] - a[1]) * mid, a[2] + (b[2] - a[2]) * mid }); + if (contrast(m, page) < floor) lo = mid else { + hi = mid; + far = m; + } + } + if (contrast(ink, far) >= ink_floor) c = far; + } const start = c; var step: f32 = 1; while (contrast(c, page) < floor and step <= 50) : (step += 1) { @@ -1586,7 +1605,9 @@ test "every theme's walk UI roles meet their floors on every ground they are dra for ([_][3]u8{ th.tag_fg, th.tag_active_fg orelse th.tag_fg }) |ink| try checks.append(a, .{ .what = "text on reading", .got = contrast(ink, chrome.tag_reading_bg), .floor = @min(7, contrast(ink, th.tag_bg)) - 0.02 }); const ink_floor = @min(Roles.ink_floor, contrast(body_ink, page)); - for ([_][3]u8{ r.hit, r.hit_current }, [_]f32{ Roles.hit_floor, Roles.hit_current_floor }) |ground, floor| { + // A preview's landing line 1.5:1 off the page, its matched span (the + // current hit) a step stronger, 1.9:1 (UX E7 7b: 1.29 read as faint). + for ([_][3]u8{ r.hit, r.hit_current }, [_]f32{ 1.5, 1.9 }) |ground, floor| { const on = contrast(body_ink, ground); try checks.append(a, .{ .what = "hit", .got = contrast(ground, page), .floor = if (on < ink_floor + 0.3) 0 else floor }); try checks.append(a, .{ .what = "ink on hit", .got = on, .floor = ink_floor - 0.01 }); @@ -1602,13 +1623,15 @@ test "every theme's walk UI roles meet their floors on every ground they are dra test "neonotte84's and acme's roles are the ones UX derived (DESIGN.md D4, tools/roles.py)" { const Want = struct { name: []const u8, text: ?[3]u8, dim: [3]u8, rule: [3]u8, key: [3]u8, match: [3]u8, reading: [3]u8, hit: [3]u8, hit_current: [3]u8 }; + // The hit grounds past UX's 18 % / 32 % mix, to 1.5:1 and 1.9:1 off the + // page (UX E7 7b). const wants = [_]Want{ - .{ .name = "neonotte84", .text = .{ 0xb5, 0xbf, 0xe3 }, .dim = .{ 0x70, 0x76, 0x8f }, .rule = .{ 0x4c, 0x50, 0x63 }, .key = .{ 0xf8, 0xde, 0xd9 }, .match = .{ 0xf1, 0xa2, 0x71 }, .reading = .{ 0x29, 0x27, 0x1e }, .hit = .{ 0x36, 0x28, 0x2a }, .hit_current = .{ 0x52, 0x38, 0x31 } }, + .{ .name = "neonotte84", .text = .{ 0xb5, 0xbf, 0xe3 }, .dim = .{ 0x70, 0x76, 0x8f }, .rule = .{ 0x4c, 0x50, 0x63 }, .key = .{ 0xf8, 0xde, 0xd9 }, .match = .{ 0xf1, 0xa2, 0x71 }, .reading = .{ 0x29, 0x27, 0x1e }, .hit = .{ 0x47, 0x32, 0x2e }, .hit_current = .{ 0x5f, 0x3f, 0x33 } }, // acme's key and match a little darker than UX's #5c5c8d and // #974d00 (which hold on its tag and its #9eeeee): a reading pane's // band's selection is pushed off the reading ground (#9eeeee is // 1.12:1 off #f3f0cc), and they read on that one too. - .{ .name = "acme", .text = null, .dim = .{ 0x7a, 0x86, 0x86 }, .rule = .{ 0xa8, 0xb7, 0xb7 }, .key = .{ 0x55, 0x55, 0x83 }, .match = .{ 0x8f, 0x48, 0x00 }, .reading = .{ 0xf3, 0xf0, 0xcc }, .hit = .{ 0xec, 0xd8, 0xbb }, .hit_current = .{ 0xdd, 0xbc, 0x99 } }, + .{ .name = "acme", .text = null, .dim = .{ 0x7a, 0x86, 0x86 }, .rule = .{ 0xa8, 0xb7, 0xb7 }, .key = .{ 0x55, 0x55, 0x83 }, .match = .{ 0x8f, 0x48, 0x00 }, .reading = .{ 0xf3, 0xf0, 0xcc }, .hit = .{ 0xe6, 0xcd, 0xae }, .hit_current = .{ 0xd9, 0xb4, 0x90 } }, }; for (wants) |want| { const chrome = ChromeTheme.fromTheme(&themes[themeIndex(want.name).?]); @@ -1621,3 +1644,16 @@ test "neonotte84's and acme's roles are the ones UX derived (DESIGN.md D4, tools }; } } + +test "the err role falls back from diagnostic.error's ink to error's, then to the theme's red (UX E3): neonotte84's (its diagnostic.error an underline only) is its red, acme's its palette's" { + const neonotte = &themes[themeIndex("neonotte84").?]; + // neonotte.toml: "error" = { fg = "red" }, its palette's red #ff7ea2. + try std.testing.expectEqual([3]u8{ 0xff, 0x7e, 0xa2 }, neonotte.diagnostic_error.?); + for ([_][]const u8{ "neonotte84", "acme" }) |name| { + const chrome = ChromeTheme.fromTheme(&themes[themeIndex(name).?]); + const err = chrome.roles.err; + // Red: its red channel well over the others, on the page and the tags. + try std.testing.expect(err[0] > err[1] + 40 and err[0] > err[2] + 40); + } + try std.testing.expectEqual([3]u8{ 0xaa, 0x22, 0x22 }, ChromeTheme.fromTheme(&themes[themeIndex("acme").?]).diagnostic_error); +} |
