summaryrefslogtreecommitdiff
path: root/core/colors.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/colors.zig')
-rw-r--r--core/colors.zig257
1 files changed, 25 insertions, 232 deletions
diff --git a/core/colors.zig b/core/colors.zig
index 7be5f008..711abfad 100644
--- a/core/colors.zig
+++ b/core/colors.zig
@@ -411,8 +411,8 @@ fn clip(l: f32, a: f32, b: f32) [3]u8 {
/// R0: `ink` held to `floor` on every one of `grounds` by its OKLab
/// lightness alone, toward whichever end reads better, its hue kept and its
-/// chroma as the gamut allows there: a red stays red where `pushAway`
-/// washes it toward white. Found by halves, eight mixes; where no
+/// chroma as the gamut allows there: a red stays red where a push toward
+/// white would wash it out. Found by halves, eight mixes; where no
/// lightness reads, the end.
fn hold(ink: [3]u8, grounds: []const [3]u8, floor: f32) [3]u8 {
if (leastContrast(ink, grounds) >= floor) return ink;
@@ -605,8 +605,9 @@ pub const Chrome = struct {
selection: Selection,
};
/// A selection on a ground, and that ground halfway to it (OKLab): a
- /// second range, a hovered word (B5).
- pub const Selection = struct { ground: [3]u8, text: [3]u8, dim: [3]u8, secondary: [3]u8 };
+ /// second range, a hovered word (B5); the key and match inks held on
+ /// the selection, a ground of its own (B1.3: a list's cursor row).
+ pub const Selection = struct { ground: [3]u8, text: [3]u8, dim: [3]u8, secondary: [3]u8, key: [3]u8, match: [3]u8 };
pub const Ground = enum(u1) { plain, focus };
pub const Severity = enum(u2) { @"error", warning, info, hint };
/// A diff's rows: a row's ground, its changed words', a faint line's,
@@ -1012,6 +1013,8 @@ fn groundInks(th: *const Theme, ground: [3]u8, text: [3]u8, sel: [3]u8, sel_text
.text = sel_text,
.dim = towardOf(sel_text, sel, Chrome.dim_floor),
.secondary = mixOklab(ground, sel, 0.5),
+ .key = hold(th.accent, &.{sel}, Chrome.text_floor),
+ .match = hold(hue, &.{sel}, Chrome.text_floor),
},
};
}
@@ -1430,9 +1433,8 @@ pub const ChromeTheme = struct {
column_box_dim: [3]u8,
scroll_track: [3]u8,
scroll_thumb: [3]u8,
- roles: Roles,
/// Everything B4 derives (`Chrome`), what the surfaces move to; the
- /// fields above and `roles` are the old derivations' values, kept for
+ /// fields above are the old derivations' values, kept for
/// the surfaces that still read them until they do (the themes
/// programme's L2 lines), so no frame moves before its surface does.
resolved: Chrome,
@@ -1487,7 +1489,6 @@ pub const ChromeTheme = struct {
.column_box_dim = th.column_box_dim orelse mix(th.column_box orelse th.num, th.tag_bg),
.scroll_track = th.scroll_track,
.scroll_thumb = th.scroll_thumb,
- .roles = .of(th, th.tag_bg, active_bg, reading),
.resolved = resolved,
.view = th.*,
};
@@ -1515,176 +1516,12 @@ fn viewOf(theme: *const Theme, r: *const Chrome) LegacyTheme {
});
}
-/// A tag's ground in the walk UI (UX DESIGN.md D4): the plain tag's, the
-/// focused one's tint, a reading pane's tint, focused or not (its ink is
-/// the focused tag's while it has the keyboard).
-pub const TagGround = enum { plain, focused, reading, reading_focused };
-
-/// The inks drawn on one ground: labels and rows (`text`, 4.5:1 at least),
-/// hints, meta and forward steps (`dim`, 3.5:1, never under 3), and the
-/// spines and the rules between steps (`rule`, 2:1).
-pub const RoleInks = struct { ground: [3]u8, text: [3]u8, dim: [3]u8, rule: [3]u8 };
-
-/// The walk UI's colour roles (UX DESIGN.md D4), worked out from a theme
-/// once, with its chrome (never a frame), each held to its floor on every
-/// ground it is drawn on: a tag's four (`tag`) and a band's cursor row on
-/// each of them (`selected`, its ground that tag's selection).
-pub const Roles = struct {
- tag: [4]RoleInks,
- selected: [4]RoleInks,
- /// The notice row's (the tagline's ground): its dim words.
- notice: RoleInks,
- /// Key cells, a level's or a row's key letters, `▶`, `•`, a target's
- /// keys: 4.5:1 on every tag ground and on the selection.
- key: [3]u8,
- /// The letters a query matched: an ink, never a ground, 4.5:1 on every
- /// tag ground and on the selection.
- match: [3]u8,
- /// A message's ink by its kind (Messages.ink): 4.5:1 on the tags and
- /// the page.
- err: [3]u8,
- warn: [3]u8,
- question: [3]u8,
- hint: [3]u8,
-
- pub const text_floor: f32 = 4.5;
- pub const dim_floor: f32 = 3;
- pub const rule_floor: f32 = 1.8;
- pub const rule_ceiling: f32 = 2.5;
- pub const ink_floor: f32 = 4.5;
- pub const reading_distance: f32 = 0.04;
-
- pub fn on(r: *const Roles, ground: TagGround) *const RoleInks {
- return &r.tag[@backingInt(ground)];
- }
-
- pub fn selectedOn(r: *const Roles, ground: TagGround) *const RoleInks {
- return &r.selected[@backingInt(ground)];
- }
-
- /// The selection's floor off a tag's ground: 1.4:1 on a dark tag, 1.25
- /// on a light one.
- pub fn selectionFloor(ground: [3]u8) f32 {
- return if (relativeLuminance(ground) < 0.18) 1.4 else 1.25;
- }
-
- fn of(th: *const LegacyTheme, plain: [3]u8, focused: [3]u8, reading: [3]u8) Roles {
- const grounds = [4][3]u8{ plain, focused, reading, reading };
- const plain_ink = th.tag_fg;
- const focused_ink = th.tag_active_fg orelse th.tag_fg;
- const texts = [4][3]u8{ plain_ink, focused_ink, plain_ink, focused_ink };
- var r: Roles = undefined;
- for (&r.tag, &r.selected, grounds, texts) |*inks, *selected, ground, ink| {
- inks.* = inksOn(ground, ink);
- selected.* = inksOn(selectionOf(th.tag_sel_bg orelse th.sel_bg, ground, inks.text), inks.text);
- }
- r.notice = inksOn(th.tagline_bg orelse th.tag_bg, th.tagline_fg orelse th.tag_fg);
- const tag_grounds = [_][3]u8{ plain, focused, reading, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground };
- 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 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);
- 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);
- return r;
- }
-};
-
-/// A tag's text, dim and rule inks on `ground`, from its ink (pushed to the
-/// text floor where it has less).
-fn inksOn(ground: [3]u8, ink: [3]u8) RoleInks {
- const text = pushAway(ink, &.{ground}, Roles.text_floor);
- return .{ .ground = ground, .text = text, .dim = toward(text, ground, 3.5), .rule = toward(text, ground, 2) };
-}
-
-/// `ink` mixed toward `ground` (OKLab) by hundredths as far as it still
-/// reads at `floor` on it: found by halves (its contrast falls as it nears
-/// the ground), seven mixes where a walk took up to a hundred (the first
-/// frame's bodyChrome derives them too).
-fn toward(ink: [3]u8, ground: [3]u8, floor: f32) [3]u8 {
- const a = toOklab(ink);
- const b = toOklab(ground);
- var best = ink;
- var lo: u32 = 0;
- var hi: u32 = 101;
- while (hi - lo > 1) {
- const mid = (lo + hi) / 2;
- const t = @as(f32, @floatFromInt(mid)) / 100;
- const c = fromOklab(.{ a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t });
- if (contrast(c, ground) >= floor) {
- lo = mid;
- best = c;
- } else hi = mid;
- }
- return best;
-}
-
-/// `ink` pushed by fiftieths toward white or black, whichever reads better
-/// on all its grounds, until it reads at `floor` on every one; where no ink
-/// does (solarized's mid-grey tag), that end, the most any ink reaches.
-pub fn pushAway(ink: [3]u8, grounds: []const [3]u8, floor: f32) [3]u8 {
- const white: [3]u8 = @splat(255);
- const black: [3]u8 = @splat(0);
- if (leastContrast(ink, grounds) >= floor) return ink;
- const end = if (leastContrast(white, grounds) >= leastContrast(black, grounds)) white else black;
- const a = toOklab(ink);
- const b = toOklab(end);
- var step: f32 = 0;
- while (step <= 50) : (step += 1) {
- const t = step / 50;
- const c = fromOklab(.{ a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t });
- if (leastContrast(c, grounds) >= floor) return c;
- }
- return end;
-}
-
fn leastContrast(ink: [3]u8, grounds: []const [3]u8) f32 {
var least: f32 = 21;
for (grounds) |g| least = @min(least, contrast(ink, g));
return least;
}
-/// The match's hue: the search's ink where it is a hue of its own (a port's
-/// is often the page's or the tag's, set for the search's ground), else the
-/// theme's warm accent.
-fn matchHue(th: *const LegacyTheme) [3]u8 {
- const own = th.search_fg orelse return th.num;
- const lab = toOklab(own);
- return if (@sqrt(lab[1] * lab[1] + lab[2] * lab[2]) >= name_tint_chroma) own else th.num;
-}
-
-/// The selection a band's cursor row is drawn on over `ground`: the
-/// theme's where it stands off it, else moved by hundredths toward the
-/// text, then away from it, to the first that does with the text still at
-/// 4.5:1 on it; where none does (a tag whose text has no contrast to
-/// spare), the one furthest off it.
-fn selectionOf(own: [3]u8, ground: [3]u8, text: [3]u8) [3]u8 {
- var best = own;
- var best_off: f32 = 0;
- const away: [3]u8 = if (relativeLuminance(text) > relativeLuminance(own)) @splat(0) else @splat(255);
- if (contrast(own, ground) >= Roles.selectionFloor(ground) and contrast(text, own) >= Roles.text_floor) return own;
- const o = toOklab(own);
- for ([2][3]u8{ text, away }) |end| {
- const e = toOklab(end);
- var step: f32 = 0;
- while (step <= 100) : (step += 1) {
- const t = step / 100;
- const c = fromOklab(.{ o[0] + (e[0] - o[0]) * t, o[1] + (e[1] - o[1]) * t, o[2] + (e[2] - o[2]) * t });
- if (contrast(text, c) < Roles.text_floor) break;
- const off = contrast(c, ground) / Roles.selectionFloor(ground);
- if (off >= 1) return c;
- if (off > best_off) {
- best = c;
- best_off = off;
- }
- }
- }
- return best;
-}
-
/// 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
@@ -1692,7 +1529,8 @@ fn selectionOf(own: [3]u8, ground: [3]u8, text: [3]u8) [3]u8 {
/// contrast, and further where the bytes cannot show so small a step (a
/// near-black tag).
fn readingOf(th: *const LegacyTheme) [3]u8 {
- if (th.tag_reading_bg) |own| if (oklabDistance(toOklab(own), toOklab(th.tag_bg)) >= Roles.reading_distance) return own;
+ const reading_distance = 0.04;
+ if (th.tag_reading_bg) |own| if (oklabDistance(toOklab(own), toOklab(th.tag_bg)) >= reading_distance) return own;
const tag = toOklab(th.tag_bg);
const paper = toOklab(.{ 0xdc, 0xc8, 0x78 });
const da = paper[1] - tag[1];
@@ -1704,11 +1542,11 @@ fn readingOf(th: *const LegacyTheme) [3]u8 {
const inks = [2][3]u8{ th.tag_fg, th.tag_active_fg orelse th.tag_fg };
var best = th.tag_bg;
var best_text: f32 = -21;
- var reach = Roles.reading_distance;
+ var reach: f32 = reading_distance;
while (reach <= 0.2) : (reach *= 1.25) {
for ([_]f32{ sign * 0.5, 0, away * 0.5, away, away * 1.5 }) |lean| {
const c = fromOklab(.{ tag[0] + lean * reach, tag[1] + da / n * reach, tag[2] + db / n * reach });
- if (oklabDistance(toOklab(c), tag) < Roles.reading_distance) continue;
+ if (oklabDistance(toOklab(c), tag) < reading_distance) continue;
// Each ink by its own floor: 7:1, or what it has on the tag.
var text: f32 = 21;
for (inks) |ink| text = @min(text, contrast(ink, c) - (@min(7, contrast(ink, th.tag_bg)) - 0.01));
@@ -2461,64 +2299,6 @@ test "every theme tints its names off the tag's ink, and they read on both groun
}
}
-test "every theme's walk UI roles meet their floors on every ground they are drawn on, dark and light" {
- // Where a theme's own colours leave no room for a floor, the most it
- // allows: an ink's on a mid-grey tag (solarized's) is the better of
- // white and black there; a ground's is where the ink it carries would
- // drop under its floor.
- const white: [3]u8 = @splat(255);
- const black: [3]u8 = @splat(0);
- const Reach = struct {
- fn of(grounds: []const [3]u8) f32 {
- return @max(leastContrast(white, grounds), leastContrast(black, grounds));
- }
- };
- const a = std.testing.allocator;
- const Check = struct { what: []const u8, got: f32, floor: f32 };
- var checks: std.ArrayList(Check) = .empty;
- defer checks.deinit(a);
- var failed: usize = 0;
- for (&themes) |*ring_theme| {
- const view = ChromeTheme.ofTheme(ring_theme).view;
- const th = &view;
- checks.clearRetainingCapacity();
- const chrome = ChromeTheme.fromTheme(th);
- const r = &chrome.roles;
- const page = th.bg orelse null_page;
- 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| {
- const text = contrast(inks.text, inks.ground);
- try checks.append(a, .{ .what = "text", .got = text, .floor = @min(Roles.text_floor, Reach.of(&.{inks.ground})) });
- try checks.append(a, .{ .what = "dim", .got = contrast(inks.dim, inks.ground), .floor = @min(Roles.dim_floor, text) });
- try checks.append(a, .{ .what = "dim under text", .got = text - contrast(inks.dim, inks.ground), .floor = 0 });
- }
- try checks.append(a, .{ .what = "key", .got = leastContrast(r.key, &tags), .floor = @min(Roles.ink_floor, Reach.of(&tags)) });
- try checks.append(a, .{ .what = "match", .got = leastContrast(r.match, &tags), .floor = @min(Roles.ink_floor, Reach.of(&tags)) });
- for (r.tag) |inks| {
- try checks.append(a, .{ .what = "rule", .got = contrast(inks.rule, inks.ground), .floor = Roles.rule_floor });
- try checks.append(a, .{ .what = "rule ceiling", .got = Roles.rule_ceiling - contrast(inks.rule, inks.ground), .floor = 0 });
- }
- for ([_][3]u8{ r.err, r.warn, r.question, r.hint }) |ink|
- try checks.append(a, .{ .what = "message", .got = leastContrast(ink, &messages), .floor = @min(Roles.ink_floor, Reach.of(&messages)) });
- // A selection off its tag by 1.4:1 (1.25 light) with the text at
- // 4.5:1 on it, where the text has that much over the tag.
- for (r.tag, r.selected) |inks, selected| {
- const floor = Roles.selectionFloor(inks.ground);
- const room = contrast(inks.text, inks.ground) >= floor * Roles.text_floor * 1.03;
- try checks.append(a, .{ .what = "selection", .got = contrast(selected.ground, inks.ground), .floor = if (room) floor else 0 });
- }
- 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 });
- 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 });
- };
- }
- try std.testing.expectEqual(0, failed);
-}
-
test "neonotte84's and acme's inks on the plain tag, their reading mark and their hits are B4's (DESIGN.md B4, D4's goldens re-pinned where B4 moves them)" {
const Want = struct { name: []const u8, text: [3]u8, dim: [3]u8, rule: [3]u8, key: [3]u8, match: [3]u8, mode: [3]u8, hit: [3]u8, hit_current: [3]u8 };
const wants = [_]Want{
@@ -2745,8 +2525,21 @@ fn ringFailures(th: *const Theme, c: *const Chrome, designed_here: bool) std.Enu
const most = leastContrast(hold(th.keyword, &both, 21), &both);
low = low or leastContrast(g.kind, &both) < @min(4.5, most) - 0.01;
low = low or contrast(g.selection.text, g.selection.ground) < @min(4.5, reach(g.selection.ground));
+ // The keys and the matched letters on its selection, a ground of
+ // its own (a list's cursor row, B1.3).
+ for ([2][3]u8{ g.selection.key, g.selection.match }) |i| low = low or contrast(i, g.selection.ground) < @min(4.5, reach(g.selection.ground));
if (low) f.insert(.inks);
}
+ // A message's mark on each fill a grid's grip has, at rest and reading
+ // on the plain tag too, where a window's grip is hollow (Grip.marks):
+ // 4.5:1 where its hue reaches it there.
+ for (c.grip.marks, [4][3]u8{ c.grip.focus, c.grip.dirty, c.grip.ring, c.grip.mode }, 0..) |m, fill, i| {
+ const both = [2][3]u8{ fill, c.tag[0].ground };
+ const grounds = if (i < @intFromEnum(Chrome.Fill.ring)) both[0..1] else both[0..];
+ for (m.severity[0..3], c.tag[0].severity[0..3]) |mark, own| {
+ if (leastContrast(mark, grounds) < @min(4.5, leastContrast(hold(own, grounds, 21), grounds)) - 0.01) f.insert(.inks);
+ }
+ }
return f;
}