diff options
Diffstat (limited to 'src/gui/gui.zig')
| -rw-r--r-- | src/gui/gui.zig | 92 |
1 files changed, 34 insertions, 58 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 63cee882..36850377 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -47,15 +47,6 @@ const image_frag_spv = @embedFile("image.frag.spv"); const bg_default = [3]u8{ 18, 18, 18 }; const fg_default = [3]u8{ 204, 204, 204 }; -const Ground = struct { - rgb: [3]u8, - clear: bool, - - fn opaqueRgb(rgb: [3]u8) Ground { - return .{ .rgb = rgb, .clear = false }; - } -}; - const p9_arrow_clr = [32]u8{ 0xFF, 0xFF, 0x80, 0x01, 0x80, 0x02, 0x80, 0x0C, 0x80, 0x10, 0x80, 0x10, 0x80, 0x08, 0x80, 0x04, @@ -5331,7 +5322,7 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { /// The glide's picture: the pane's body rows moved by the offset, and in /// the gap it opens the rows that left, as `emitScrollRows` draws a /// touchpad's fraction. -fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 { +fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: [3]u8, held: u16) u32 { const glide = &g.glide; for (surface.panelTracks()) |track| if (track.active() and track.pane == glide.pane) return 0; @@ -5760,7 +5751,7 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { if (g.scroll_lag == 0) resetScroll(g); } -fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 { +fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: [3]u8, held: u16) u32 { g.scroll_held_px = 0; if (g.glide.follow.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page, held); const scroll_pane = g.scroll_pane orelse return 0; @@ -6398,14 +6389,14 @@ fn renderFrame( coverFrame(previous_covered, surface.cols, surface.rows, surface.previous_body_layers, surface.previous_tag_layers, surface.previous_regions); try buildDecor(g, gpa, surface, &groups, layout, win_w, win_h, cursors_shown); - const page: Ground = .opaqueRgb(chrome.page orelse bg_default); + const page = chrome.page orelse bg_default; const background_opacity = backgroundOpacity(g.applied_window_opacity); var color_target = std.mem.zeroes(c.SDL_GPUColorTargetInfo); color_target.texture = scene; - color_target.clear_color = if (page.clear) .{ .r = 0, .g = 0, .b = 0, .a = 0 } else .{ - .r = @as(f32, @floatFromInt(page.rgb[0])) / 255.0 * background_opacity, - .g = @as(f32, @floatFromInt(page.rgb[1])) / 255.0 * background_opacity, - .b = @as(f32, @floatFromInt(page.rgb[2])) / 255.0 * background_opacity, + color_target.clear_color = .{ + .r = @as(f32, @floatFromInt(page[0])) / 255.0 * background_opacity, + .g = @as(f32, @floatFromInt(page[1])) / 255.0 * background_opacity, + .b = @as(f32, @floatFromInt(page[2])) / 255.0 * background_opacity, .a = background_opacity, }; color_target.load_op = c.SDL_GPU_LOADOP_CLEAR; @@ -6642,7 +6633,7 @@ fn renderFrame( if (cell_decor.nplaques != 0) { const space_u = @as(f32, @floatFromInt(g.space_slot.u)) / @as(f32, @floatFromInt(atlas_w)); const space_v = @as(f32, @floatFromInt(g.space_slot.v)) / @as(f32, @floatFromInt(atlas_h)); - if (page.clear or plaque_through_len > plaque_through.len) cell_decor.inked_clear = true; + if (plaque_through_len > plaque_through.len) cell_decor.inked_clear = true; for (plaque_through[0..@min(plaque_through_len, plaque_through.len)]) |at| { const instance = &instances[at]; // A grip's button takes its cell's ground back (emitSurfaceCell). @@ -6804,7 +6795,6 @@ const ResolvedCell = struct { fg: [3]u8, bg: [3]u8, role: pardes.FontRole, - clear_bg: bool = false, }; const taglineBandOffset = pardes.taglineBandOffset; @@ -6821,11 +6811,10 @@ test "tagline bands center in their cells and Tagbottom faces the window edge" { /// The colours and atlas slot of `line[at]`. `cursor` is where the cursor sits /// in `line`, block or bar: shaping breaks around it. -fn resolveCell(g: *Gui, line: []const pardes.Cell, at: usize, cursor: ?usize, role: pardes.FontRole, is_cursor: bool, page: Ground) ResolvedCell { +fn resolveCell(g: *Gui, line: []const pardes.Cell, at: usize, cursor: ?usize, role: pardes.FontRole, is_cursor: bool, page: [3]u8) ResolvedCell { const cell = &line[at]; var fg = fg_default; - var bg = page.rgb; - var clear_bg = page.clear; + var bg = page; var reverse = is_cursor; if (!cell.default) { const st = cell.style; @@ -6836,14 +6825,8 @@ fn resolveCell(g: *Gui, line: []const pardes.Cell, at: usize, cursor: ?usize, ro }; switch (st.bg) { .default => {}, - .index => |i| { - bg = palColor(i); - clear_bg = false; - }, - .rgb => |rgb| { - bg = rgb; - clear_bg = false; - }, + .index => |i| bg = palColor(i), + .rgb => |rgb| bg = rgb, } if (st.reverse) reverse = !reverse; if (st.invisible) { @@ -6856,17 +6839,13 @@ fn resolveCell(g: *Gui, line: []const pardes.Cell, at: usize, cursor: ?usize, ro ch.* = @intCast(@as(u16, ch.*) * 6 / 10); }; } - if (reverse) { - std.mem.swap([3]u8, &fg, &bg); - clear_bg = false; - } + if (reverse) std.mem.swap([3]u8, &fg, &bg); return .{ .slot = cellSlot(g, line, at, cursor, role), .fg = fg, .bg = bg, .role = role, - .clear_bg = clear_bg, }; } @@ -6874,15 +6853,13 @@ fn cellFontRole(cell: *const pardes.Cell) pardes.FontRole { return if (cell.default) .body else cell.style.font_role; } -test "concealed terminal text emits no ink on opaque or transparent ground" { +test "concealed terminal text emits no ink on its ground" { var g = testGui(10, 20, 6, 12); var cell: pardes.Cell = .{ .default = false, .style = .{ .invisible = true, .ul = .single } }; cell.text[0] = 'X'; - for ([_]Ground{ .opaqueRgb(bg_default), .{ .rgb = bg_default, .clear = true } }) |page| { - const resolved = resolveCell(&g, (&cell)[0..1], 0, null, .body, false, page); - try std.testing.expectEqualDeep(g.space_slot, resolved.slot); - try std.testing.expectEqual(page.rgb, resolved.bg); - } + const resolved = resolveCell(&g, (&cell)[0..1], 0, null, .body, false, bg_default); + try std.testing.expectEqualDeep(g.space_slot, resolved.slot); + try std.testing.expectEqual(bg_default, resolved.bg); } fn cellInstanceCount(cell: *const pardes.Cell) u32 { @@ -6988,7 +6965,7 @@ fn tagLayerCellCount(g: *const Gui, layer: *const pardes.Layer) u32 { return @min(layer.cols, (pixels + g.tagline_width - 1) / g.tagline_width); } -fn emitTagLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const pardes.Layer, win_w: f32, win_h: f32, track: ?pardes.animation.Track, page: Ground, show_cursor: bool, old_layer: bool) void { +fn emitTagLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const pardes.Layer, win_w: f32, win_h: f32, track: ?pardes.animation.Track, page: [3]u8, show_cursor: bool, old_layer: bool) void { const bw: f32 = @floatFromInt(g.cell_w); const bh: f32 = @floatFromInt(g.cell_h); const tw: f32 = @floatFromInt(g.tagline_width); @@ -7055,7 +7032,7 @@ fn clipBodyInstance(instance: *CellInstance, bottom: f32, win_h: f32) void { instance.y1 = limit; } -fn emitBodyLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const pardes.Layer, win_w: f32, win_h: f32, track: ?pardes.animation.Track, page: Ground, show_cursor: bool, old_layer: bool, border_rgb: [3]u8) void { +fn emitBodyLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const pardes.Layer, win_w: f32, win_h: f32, track: ?pardes.animation.Track, page: [3]u8, show_cursor: bool, old_layer: bool, border_rgb: [3]u8) void { const bw: f32 = @floatFromInt(g.cell_w); const bh: f32 = @floatFromInt(g.cell_h); const tw: f32 = @floatFromInt(g.tagline_width); @@ -7192,7 +7169,7 @@ fn emitSurfaceCell( cursor: ?usize, old_layer: bool, is_cursor: bool, - page: Ground, + page: [3]u8, ) void { const role = cellFontRole(&line[at]); if (role == .tagline) { @@ -7351,7 +7328,7 @@ test "every pixel of a grip column is band, button or ring, and the button sits const row: u16 = grip.rect.y + @as(u16, @intCast(line)); const at = @as(usize, row) * s.cols; var next: u32 = 0; - emitSurfaceCell(&g, &s.chrome, &instances, &next, col, row, layout, win_w, win_h, null, s.cells[at..][0..s.cols], cover[at..][0..s.cols], col, null, false, false, Ground.opaqueRgb(bg_default)); + emitSurfaceCell(&g, &s.chrome, &instances, &next, col, row, layout, win_w, win_h, null, s.cells[at..][0..s.cols], cover[at..][0..s.cols], col, null, false, false, bg_default); for (instances[0..next]) |i| paint.quad(pixels, i.x0, i.y0, i.x1, i.y1, .{ i.br, i.bg, i.bb }, win_w, win_h, x_px, y_px, w_px, h_px); }; for (g.decor.items) |i| if (i.fr >= 1 and i.clip_x1 < i.clip_x0) paint.quad(pixels, i.x0, i.y0, i.x1, i.y1, .{ i.br, i.bg, i.bb }, win_w, win_h, x_px, y_px, w_px, h_px); @@ -7418,7 +7395,7 @@ test "small tagline fonts leave no background gutters between adjacent tags" { var next: u32 = 0; for (0..3) |row| { // Column 1: past the anchor's inset edge at the column's left. - emitSurfaceCell(&g, &chrome, &instances, &next, 1, @intCast(row), fixedCellLayout(&g), 800, 480, null, (&cell)[0..1], &.{.{}}, 0, null, false, false, Ground.opaqueRgb(bg_default)); + emitSurfaceCell(&g, &chrome, &instances, &next, 1, @intCast(row), fixedCellLayout(&g), 800, 480, null, (&cell)[0..1], &.{.{}}, 0, null, false, false, bg_default); const base = instances[row * 2]; const ink = instances[row * 2 + 1]; try std.testing.expectApproxEqAbs(@as(f32, 20.0 / 480.0 * 2), base.y0 - base.y1, 0.0001); @@ -7431,12 +7408,12 @@ test "small tagline fonts leave no background gutters between adjacent tags" { // Column 0 is an anchor's edge: its ink is inset by the band's margin // (2 px here) and its underlay still covers the whole cell. next = 0; - emitSurfaceCell(&g, &chrome, &instances, &next, 0, 1, fixedCellLayout(&g), 800, 480, null, (&cell)[0..1], &.{.{ .anchor = true }}, 0, null, false, false, Ground.opaqueRgb(bg_default)); + emitSurfaceCell(&g, &chrome, &instances, &next, 0, 1, fixedCellLayout(&g), 800, 480, null, (&cell)[0..1], &.{.{ .anchor = true }}, 0, null, false, false, bg_default); try std.testing.expectApproxEqAbs(@as(f32, 10.0 / 800.0 * 2), instances[0].x1 - instances[0].x0, 0.0001); try std.testing.expectApproxEqAbs(@as(f32, 8.0 / 800.0 * 2), instances[1].x1 - instances[1].x0, 0.0001); try std.testing.expectApproxEqAbs(@as(f32, 8) / atlas_w, instances[1].u1 - instances[1].u0, 0.0001); next = 0; - emitSurfaceCell(&g, &chrome, &instances, &next, 0, 2, fixedCellLayout(&g), 800, 480, null, (&cell)[0..1], &.{.{}}, 0, null, true, false, Ground.opaqueRgb(bg_default)); + emitSurfaceCell(&g, &chrome, &instances, &next, 0, 2, fixedCellLayout(&g), 800, 480, null, (&cell)[0..1], &.{.{}}, 0, null, true, false, bg_default); try std.testing.expectEqual(@as(u32, 2), next); try std.testing.expectApproxEqAbs(@as(f32, 16.0 / 480.0 * 2), instances[1].y0 - instances[1].y1, 0.0001); } @@ -7457,7 +7434,7 @@ fn emitInstance( cursor: ?usize, old_layer: bool, is_cursor: bool, - page: Ground, + page: [3]u8, ) void { const resolved = resolveCell(g, line, at, cursor, role, is_cursor, page); @@ -7505,7 +7482,6 @@ fn emitInstance( if (track) |active| panelCellCoord(active, col, row) else 0, ); if (old_layer) instances[idx].effect |= old_layer_bit; - if (resolved.clear_bg) instances[idx].effect |= clear_bg_bit; // A block cursor is foreground UI ink, even though its color is carried // in the reversed cell background. Keep it visible at WindowOpacity 0. if (is_cursor) instances[idx].effect |= opaque_bg_bit; @@ -7518,7 +7494,7 @@ fn emitInstance( (cell_decor.inPlaque(px0 + 0.5, py0 + 0.5) or cell_decor.inPlaque(px0 + layout.w - 0.5, py0 + 0.5))) plaqueThrough(instances, idx); if (cell_decor.dots) |dotted| { - if (!resolved.clear_bg and std.mem.eql(u8, &resolved.bg, &dotted)) { + if (std.mem.eql(u8, &resolved.bg, &dotted)) { instances[idx].effect |= dotted_bit; // G13: the dots under a body move with its text, a quarter // as far; the serial slot carries it (the shader reads it @@ -7537,7 +7513,7 @@ test "block cursor alone overrides transparent cell background" { const cell: pardes.Cell = .{}; var instances: [2]CellInstance = undefined; for ([_]bool{ false, true }, 0..) |cursor, i| { - emitInstance(&g, &instances, @intCast(i), 0, 0, fixedCellLayout(&g), 800, 480, null, .body, (&cell)[0..1], 0, null, false, cursor, Ground.opaqueRgb(bg_default)); + emitInstance(&g, &instances, @intCast(i), 0, 0, fixedCellLayout(&g), 800, 480, null, .body, (&cell)[0..1], 0, null, false, cursor, bg_default); try std.testing.expectEqual(cursor, instances[i].effect & opaque_bg_bit != 0); } } @@ -7563,14 +7539,14 @@ test "lapis dots only the page's own ground and shadows only a file name, never .{ .cell = title, .role = .tagline, .cursor = true, .dotted = false, .shadowed = false }, .{ .cell = plain_tag, .role = .tagline, .cursor = false, .dotted = false, .shadowed = false }, }) |case| { - emitInstance(&g, &instances, 0, 0, 0, fixedCellLayout(&g), 800, 480, null, case.role, (&case.cell)[0..1], 0, null, false, case.cursor, Ground.opaqueRgb(page)); + emitInstance(&g, &instances, 0, 0, 0, fixedCellLayout(&g), 800, 480, null, case.role, (&case.cell)[0..1], 0, null, false, case.cursor, page); try std.testing.expectEqual(case.dotted, instances[0].effect & dotted_bit != 0); try std.testing.expectEqual(case.shadowed, instances[0].effect & title_bit != 0); } // A theme without decor marks nothing. chrome = .{ .page = page }; cell_decor = CellDecor.of(&chrome); - emitInstance(&g, &instances, 0, 0, 0, fixedCellLayout(&g), 800, 480, null, .body, (&on_page)[0..1], 0, null, false, false, Ground.opaqueRgb(page)); + emitInstance(&g, &instances, 0, 0, 0, fixedCellLayout(&g), 800, 480, null, .body, (&on_page)[0..1], 0, null, false, false, page); try std.testing.expectEqual(@as(u32, 0), instances[0].effect & (dotted_bit | title_bit)); } @@ -8280,7 +8256,7 @@ test "pane indicator halves share dissolve changes and safe exhausted atlas" { var instances: [4]CellInstance = undefined; var next: u32 = 0; for (0..2) |col| { - emitSurfaceCell(&g, &chrome, &instances, &next, @intCast(col), 0, fixedCellLayout(&g), 100, 100, null, cells[0..6], cover[0..6], col, null, old, false, Ground.opaqueRgb(bg_default)); + emitSurfaceCell(&g, &chrome, &instances, &next, @intCast(col), 0, fixedCellLayout(&g), 100, 100, null, cells[0..6], cover[0..6], col, null, old, false, bg_default); try std.testing.expectEqual(@as(f32, 0), instances[col * 2 + 1].u0); try std.testing.expectEqual(old, instances[col * 2 + 1].effect & old_layer_bit != 0); } @@ -10773,7 +10749,7 @@ test "compact body layer rendering fills recovered rows and clips the final glyp layer.setContextLines(&.{ 0, 4, 5, 6 }); var instances: [32]CellInstance = undefined; var next: u32 = 0; - emitBodyLayer(&g, &instances, &next, &layer, 200, 200, null, Ground.opaqueRgb(bg_default), false, false, .{ 80, 90, 100 }); + emitBodyLayer(&g, &instances, &next, &layer, 200, 200, null, bg_default, false, false, .{ 80, 90, 100 }); // Four compact header rows (48px), then three body rows: two complete // and a third clipped to the remaining12px of the100px viewport. try std.testing.expectEqual(@as(u32, 20), next); @@ -10789,7 +10765,7 @@ test "compact body layer rendering fills recovered rows and clips the final glyp layer.viewport.w = 1; for ([_]bool{ false, true }) |old| { next = 0; - emitBodyLayer(&g, &instances, &next, &layer, 200, 200, null, Ground.opaqueRgb(bg_default), false, old, .{ 80, 90, 100 }); + emitBodyLayer(&g, &instances, &next, &layer, 200, 200, null, bg_default, false, old, .{ 80, 90, 100 }); for (instances[0..next]) |instance| try std.testing.expect(instance.x1 <= -0.6 + 0.0001); } } @@ -10800,14 +10776,14 @@ test "compact tag layers fill available width and clip at their physical edge" { const layer: pardes.Layer = .{ .kind = .pane, .id = 0, .serial = 7, .viewport = .{ .x = 2, .y = 3, .w = 3, .h = 1 }, .cols = 6, .rows = 1, .cells = &cells, .bg = .{ 20, 30, 40 } }; var instances: [8]CellInstance = undefined; var next: u32 = 0; - emitTagLayer(&g, &instances, &next, &layer, 100, 100, null, Ground.opaqueRgb(bg_default), false, false); + emitTagLayer(&g, &instances, &next, &layer, 100, 100, null, bg_default, false, false); // Five six-pixel cells fit in the three body-column viewport. try std.testing.expectEqual(@as(u32, 6), next); try std.testing.expectApproxEqAbs(@as(f32, -0.6), instances[1].x0, 0.0001); try std.testing.expectApproxEqAbs(@as(f32, 0), instances[5].x1, 0.0001); g.tagline_width = 8; next = 0; - emitTagLayer(&g, &instances, &next, &layer, 100, 100, null, Ground.opaqueRgb(bg_default), false, false); + emitTagLayer(&g, &instances, &next, &layer, 100, 100, null, bg_default, false, false); try std.testing.expectEqual(@as(u32, 5), next); try std.testing.expectApproxEqAbs(@as(f32, 0), instances[4].x1, 0.0001); try std.testing.expectApproxEqAbs(@as(f32, 6) / atlas_w, instances[4].u1 - instances[4].u0, 0.0001); |
