summaryrefslogtreecommitdiff
path: root/core/colors.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/colors.zig')
-rw-r--r--core/colors.zig133
1 files changed, 20 insertions, 113 deletions
diff --git a/core/colors.zig b/core/colors.zig
index 315d1fc9..44a2d415 100644
--- a/core/colors.zig
+++ b/core/colors.zig
@@ -553,10 +553,13 @@ pub const Chrome = struct {
selection_secondary: [3]u8,
/// The pointer buttons' sweeps: select, exec, look (acme's meanings).
sweeps: [3]Theme.Sweep,
- /// Search: a hit's ground, and the current one's ground and ink.
+ /// Search: a hit's ground, and the current one's ground and ink; a
+ /// search's last places while its field is no regex, dimmed: the page
+ /// halfway toward the hit (as `selection_secondary` is the selection's).
hit: [3]u8,
hit_current: [3]u8,
hit_current_text: [3]u8,
+ hit_faint: [3]u8,
add: Diff,
del: Diff,
/// The Changes layer's lanes, a pin each (`lanes_len` of them), and
@@ -726,6 +729,7 @@ pub const Chrome = struct {
// ink (vim's IncSearch): room for it in every theme.
c.hit_current = hold(hue, &.{page}, text_floor);
c.hit_current_text = page;
+ c.hit_faint = mixOklab(page, c.hit, 0.5);
// Every ground's inks; on the tags and the status row, the
// tag's selection rebuilt on each where it stands too near it.
@@ -1061,31 +1065,17 @@ pub fn synInk(th: *const LegacyTheme, sy: @import("syntax.zig").Syn) ?[3]u8 {
}
/// The grounds a style byte's high bits name (syntax.ground_add and the
-/// rest) in a theme: a row added or removed on a ground a little way from
-/// the page toward the theme's green or red (its own ANSI ones where it has
-/// a palette), a stronger one, a faint one, and the row's marker in that
-/// hue, pushed toward the ink until it reads on the row's ground. Syntax
-/// colours are drawn over a ground unchanged.
+/// rest) in a theme, for the library: its chrome's added and deleted rows
+/// (R10). Syntax colours are drawn over a ground unchanged.
pub const Grounds = struct {
add: Ground,
del: Ground,
- pub const Ground = struct { row: [3]u8, emph: [3]u8, line: [3]u8, ink: [3]u8 };
+ pub const Ground = Chrome.Diff;
pub fn of(th: *const LegacyTheme) Grounds {
- const page = th.bg orelse th.tag_bg;
- const ink = th.fg orelse th.tag_fg;
- const green: [3]u8 = if (th.palette) |pal| pal[2] else .{ 0x2e, 0xa0, 0x43 };
- const red: [3]u8 = if (th.palette) |pal| pal[1] else .{ 0xcf, 0x22, 0x2e };
- return .{ .add = ground(page, ink, green), .del = ground(page, ink, red) };
- }
-
- fn ground(page: [3]u8, ink: [3]u8, hue: [3]u8) Ground {
- const row = mixOklab(page, hue, 0.18);
- var marker = hue;
- var step: usize = 0;
- while (step < 4 and contrast(marker, row) < 3) : (step += 1) marker = mixOklab(marker, ink, 0.4);
- return .{ .row = row, .emph = mixOklab(page, hue, 0.28), .line = mixOklab(page, hue, 0.07), .ink = marker };
+ const c = Chrome.of(&.fromLegacy(th.*));
+ return .{ .add = c.add, .del = c.del };
}
/// The ground of a byte's hue, if it has one.
@@ -1294,17 +1284,13 @@ pub const ChromeTheme = struct {
border: [3]u8,
empty_col: [3]u8,
search_bg: [3]u8,
- search_fg: [3]u8,
tag_reading_bg: [3]u8,
diagnostic_error: [3]u8,
diagnostic_warning: [3]u8,
- diagnostic_info: [3]u8,
- diagnostic_hint: [3]u8,
box: [3]u8,
box_dim: [3]u8,
column_box: [3]u8,
column_box_dim: [3]u8,
- lineno: [3]u8,
scroll_track: [3]u8,
scroll_thumb: [3]u8,
roles: Roles,
@@ -1342,18 +1328,14 @@ pub const ChromeTheme = struct {
.border = separatorOf(th),
.empty_col = th.empty_col orelse separatorOf(th),
.search_bg = th.search_bg orelse th.sel_bg,
- .search_fg = th.search_fg orelse th.sel_fg,
.tag_reading_bg = reading,
// 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),
.box = th.box,
.box_dim = th.box_dim,
.column_box = th.column_box orelse th.num,
.column_box_dim = th.column_box_dim orelse mix(th.column_box orelse th.num, th.tag_bg),
- .lineno = th.lineno,
.scroll_track = th.scroll_track,
.scroll_thumb = th.scroll_thumb,
.roles = .of(th, th.tag_bg, active_bg, reading),
@@ -1387,10 +1369,6 @@ pub const Roles = struct {
/// The letters a query matched: an ink, never a ground, 4.5:1 on every
/// tag ground and on the selection.
match: [3]u8,
- /// The body's places and a preview's landing line, and the current
- /// one (its matched span): grounds off the page, its ink on them 4.5:1.
- hit: [3]u8,
- hit_current: [3]u8,
/// A message's ink by its kind (Messages.ink): 4.5:1 on the tags and
/// the page.
err: [3]u8,
@@ -1403,8 +1381,6 @@ 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.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 RoleInks {
@@ -1436,20 +1412,6 @@ pub const Roles = struct {
r.key = pushAway(th.box, &tag_grounds, ink_floor);
r.match = pushAway(matchHue(th), &tag_grounds, ink_floor);
const page = th.bg orelse null_page;
- const body_ink = th.fg orelse th.tag_fg;
- const dark = relativeLuminance(page) < 0.18;
- // The theme's search ground where it stands off the page and the
- // body reads on it; else the page a little way toward its hue (the
- // warm accent's without one). The current one as far past the hit
- // as 32 % is past 18 % (38 past 22 on a light page).
- const hue = th.search_bg orelse th.num;
- const own = th.search_bg != null and contrast(hue, page) >= hit_floor and contrast(body_ink, hue) >= ink_floor;
- const at: f32 = if (own) 1 else if (dark) 0.18 else 0.22;
- r.hit = if (own) hue else hitOf(page, hue, body_ink, at, hit_floor);
- const past: f32 = if (dark) 0.32 / 0.18 else 0.38 / 0.22;
- r.hit_current = hitOf(page, hue, body_ink, at * past, hit_current_floor);
- // Never fainter than the hit, where the ink holds both short.
- 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 if (th.palette) |pal| pal[1] else ink, &message_grounds, ink_floor);
@@ -1552,48 +1514,6 @@ fn selectionOf(own: [3]u8, ground: [3]u8, text: [3]u8) [3]u8 {
return best;
}
-/// 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); 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);
- const ink_floor = @min(Roles.ink_floor, contrast(ink, page));
- var k = t;
- var c = fromOklab(.{ a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k });
- while (contrast(ink, c) < ink_floor and k > 0) {
- 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) {
- const next = mixOklab(start, ink, step / 100);
- if (contrast(ink, next) < ink_floor) break;
- c = next;
- }
- return c;
-}
-
/// A reading pane's tag (UX DESIGN.md D4): the theme's own where it stands
/// off the tag, else the tag shifted toward paper yellow by 0.04 in OKLab
/// and lighter by half that on a dark tag (darker on a light), so it reads
@@ -1791,7 +1711,6 @@ pub fn loadThemeFile(p: *Pardes, generation: u32, bytes: []const u8) bool {
theme.name = view.name;
p.theme_chrome = .of(&theme, &view);
- p.body_chrome = .{ .theme = view, .chrome = p.theme_chrome };
const old = p.custom_theme;
p.custom_theme = view;
if (old) |theme_value| p.gpa.free(theme_value.name);
@@ -1828,13 +1747,10 @@ fn inOldNames(source: [:0]const u8) bool {
}
/// The session's theme's chrome, at its start (Pardes.init, a Restore):
-/// never one the window previews (`previewTheme`); the body's copy of it
-/// (Core.bodyChrome's, keyed by the theme) made with it, not again at the
-/// first frame.
+/// never one the window previews (`previewTheme`).
pub fn finishThemeInitialization(p: *Pardes) void {
const theme = if (p.custom_theme) |*custom| custom else &legacy_themes[p.settings.theme];
p.theme_chrome = if (p.custom_theme != null) .fromTheme(theme) else .of(&themes[p.settings.theme], theme);
- p.body_chrome = .{ .theme = theme.*, .chrome = p.theme_chrome };
}
/// Themes near `name`, a line of them, for a Theme given a name there is
@@ -1915,7 +1831,6 @@ pub fn previewTheme(p: *Pardes, index: ?usize) void {
if (p.theme_preview) |had| if (had == i) return;
p.theme_preview = @intCast(i);
p.preview_chrome = .of(&themes[i], &legacy_themes[i]);
- p.body_chrome = .{ .theme = legacy_themes[i], .chrome = p.preview_chrome };
}
pub fn setThemeIndex(p: *Pardes, index: usize) void {
@@ -1923,7 +1838,6 @@ pub fn setThemeIndex(p: *Pardes, index: usize) void {
(p.custom_theme == null and p.theme_file_path.get().len == 0 and
index == @as(usize, p.settings.theme))) return;
p.theme_chrome = .of(&themes[index], &legacy_themes[index]);
- p.body_chrome = .{ .theme = legacy_themes[index], .chrome = p.theme_chrome };
if (p.custom_theme) |theme_value| {
p.custom_theme = null;
p.gpa.free(theme_value.name);
@@ -2131,9 +2045,8 @@ test "native themes keep text and UI roles readable on their own surfaces" {
const chrome = ChromeTheme.fromTheme(&th);
const minimum: f32 = if (std.mem.eql(u8, name, "ink") or std.mem.eql(u8, name, "daybreak")) 7 else 4.5;
const text_colors = [_][3]u8{
- th.fg.?, th.kw, th.str, th.num, th.comment,
- chrome.diagnostic_error, chrome.diagnostic_warning, chrome.diagnostic_info, chrome.diagnostic_hint,
- };
+ th.fg.?, th.kw, th.str, th.num, th.comment,
+ } ++ chrome.resolved.page.severity;
for (text_colors) |fg| try std.testing.expect(contrast(fg, th.bg.?) >= minimum);
// Gutters are orientation aids, not source text: stay visible without
// competing with comments or pulling attention away from the body.
@@ -2153,7 +2066,7 @@ test "native themes keep text and UI roles readable on their own surfaces" {
try std.testing.expect(contrast(chrome.tag_active_bg, th.tag_bg) <= 1.6);
try std.testing.expect(contrast(chrome.tag_active_fg, th.tag_fg) <= 1.6);
try std.testing.expect(contrast(th.sel_fg, th.sel_bg) >= minimum);
- try std.testing.expect(contrast(chrome.search_fg, chrome.search_bg) >= minimum);
+ try std.testing.expect(contrast(chrome.resolved.hit_current_text, chrome.resolved.hit_current) >= Chrome.text_floor);
// ANSI black can intentionally match the page (for backgrounds). All
// other ANSI foregrounds, including bright black, remain legible.
for (th.palette.?[1..]) |fg| try std.testing.expect(contrast(fg, th.bg.?) >= minimum);
@@ -2219,6 +2132,7 @@ test "line numbers stay quiet without a current-line tag background" {
custom.lineno = .{ 70, 70, 70 };
custom.lineno_active = .{ 95, 95, 95 };
p.custom_theme = custom;
+ finishThemeInitialization(p);
p.sync();
const x = p.view().rects[0].x + config.GUTTER;
const y = p.view().rects[0].y + BOX_H;
@@ -2228,10 +2142,13 @@ test "line numbers stay quiet without a current-line tag background" {
try std.testing.expectEqual(Color{ .rgb = custom.bg.? }, surface.at(x, y).style.bg);
try std.testing.expect(surface.at(x, y).style.bold);
try std.testing.expect(!surface.at(x, y + 1).style.bold);
- // Old ThemeFile palettes need no new field, and do not regain the block.
+ // Old ThemeFile palettes need no new field: the current number is the
+ // text toward the page to 4.5:1 (R12), and the block not regained.
p.custom_theme.?.lineno_active = null;
+ finishThemeInitialization(p);
const fallback = try p.render(p.scratch.allocator());
- try std.testing.expectEqual(Color{ .rgb = .{ 70, 70, 70 } }, fallback.at(x, y).style.fg);
+ try std.testing.expectEqual(Color{ .rgb = p.chrome().line_number_current }, fallback.at(x, y).style.fg);
+ try std.testing.expect(contrast(p.chrome().line_number_current, custom.bg.?) >= Chrome.text_floor - 0.05);
try std.testing.expectEqual(Color{ .rgb = custom.bg.? }, fallback.at(x, y).style.bg);
try std.testing.expect(fallback.at(x, y).style.bold);
// Moving the caret clears the previous cue; editing the tag parks it.
@@ -2374,7 +2291,6 @@ test "every theme's walk UI roles meet their floors on every ground they are dra
const chrome = ChromeTheme.fromTheme(th);
const r = &chrome.roles;
const page = th.bg orelse null_page;
- const body_ink = th.fg orelse th.tag_fg;
const tags = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground };
const messages = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, page };
for (r.tag ++ r.selected ++ [1]RoleInks{r.notice}) |inks| {
@@ -2401,15 +2317,6 @@ test "every theme's walk UI roles meet their floors on every ground they are dra
try checks.append(a, .{ .what = "reading", .got = oklabDistance(toOklab(chrome.tag_reading_bg), toOklab(th.tag_bg)), .floor = Roles.reading_distance });
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));
- // 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 });
- }
- try checks.append(a, .{ .what = "current over hit", .got = contrast(r.hit_current, page) - contrast(r.hit, page), .floor = 0 });
for (checks.items) |c| if (c.got < c.floor - 0.005) {
failed += 1;
std.debug.print("{s}: {s} {d:.2} under {d:.2}\n", .{ th.name, c.what, c.got, c.floor });