1146e2f0
Add text comparison layout helpers
a73x 2026-04-09 08:17
Commit message
src/main.zig
| Old | New | ||
|---|---|---|---|
| @@ -457,6 +457,45 @@ fn shouldRenderFrame(terminal_dirty: bool, window_dirty: bool, forced: bool) boo | |||
| 457 | return terminal_dirty or window_dirty or forced; | 457 | return terminal_dirty or window_dirty or forced; |
| 458 | } | 458 | } |
| 459 | 459 | ||
| 460 | const ComparisonVariant = struct { | ||
| 461 | label: []const u8, | ||
| 462 | coverage: [2]f32, | ||
| 463 | }; | ||
| 464 | |||
| 465 | fn comparisonVariants() [4]ComparisonVariant { | ||
| 466 | return .{ | ||
| 467 | .{ .label = "baseline", .coverage = renderer.coverageVariantParams(.baseline) }, | ||
| 468 | .{ .label = "mild", .coverage = renderer.coverageVariantParams(.mild) }, | ||
| 469 | .{ .label = "medium", .coverage = renderer.coverageVariantParams(.medium) }, | ||
| 470 | .{ .label = "crisp", .coverage = renderer.coverageVariantParams(.crisp) }, | ||
| 471 | }; | ||
| 472 | } | ||
| 473 | |||
| 474 | fn comparisonSpecimenLines() []const []const u8 { | ||
| 475 | return &.{ | ||
| 476 | "abcdefghijklmnopqrstuvwxyz", | ||
| 477 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
| 478 | "0123456789", | ||
| 479 | "{}[]()/\\|,.;:_-=+", | ||
| 480 | "~/code/rad/waystty $ zig build test", | ||
| 481 | }; | ||
| 482 | } | ||
| 483 | |||
| 484 | fn comparisonPanelOrigins(panel_count: usize, panel_cols: u32, top_margin_rows: u32) [4][2]f32 { | ||
| 485 | var origins = [_][2]f32{.{ 0.0, @floatFromInt(top_margin_rows) }} ** 4; | ||
| 486 | const count = @min(panel_count, origins.len); | ||
| 487 | |||
| 488 | var idx: usize = 0; | ||
| 489 | while (idx < count) : (idx += 1) { | ||
| 490 | origins[idx] = .{ | ||
| 491 | @floatFromInt(idx * @as(usize, panel_cols)), | ||
| 492 | @floatFromInt(top_margin_rows), | ||
| 493 | }; | ||
| 494 | } | ||
| 495 | |||
| 496 | return origins; | ||
| 497 | } | ||
| 498 | |||
| 460 | const RowRefreshState = enum { | 499 | const RowRefreshState = enum { |
| 461 | full, | 500 | full, |
| 462 | partial, | 501 | partial, |
| @@ -1711,6 +1750,27 @@ test "glyphTopOffset uses baseline rather than cell height" { | |||
| 1711 | try std.testing.expectEqual(@as(f32, -3.0), glyphTopOffset(9, 12)); | 1750 | try std.testing.expectEqual(@as(f32, -3.0), glyphTopOffset(9, 12)); |
| 1712 | } | 1751 | } |
| 1713 | 1752 | ||
| 1753 | test "comparisonPanelOrigins splits four panels left to right" { | ||
| 1754 | const origins = comparisonPanelOrigins(4, 80, 24); | ||
| 1755 | try std.testing.expectEqual(@as(f32, 0), origins[0][0]); | ||
| 1756 | try std.testing.expect(origins[1][0] > origins[0][0]); | ||
| 1757 | try std.testing.expect(origins[2][0] > origins[1][0]); | ||
| 1758 | try std.testing.expect(origins[3][0] > origins[2][0]); | ||
| 1759 | } | ||
| 1760 | |||
| 1761 | test "comparisonSpecimenLines remains fixed and non-empty" { | ||
| 1762 | const lines = comparisonSpecimenLines(); | ||
| 1763 | try std.testing.expectEqual(@as(usize, 5), lines.len); | ||
| 1764 | try std.testing.expectEqualStrings("abcdefghijklmnopqrstuvwxyz", lines[0]); | ||
| 1765 | try std.testing.expectEqualStrings("ABCDEFGHIJKLMNOPQRSTUVWXYZ", lines[1]); | ||
| 1766 | try std.testing.expectEqualStrings("0123456789", lines[2]); | ||
| 1767 | try std.testing.expectEqualStrings("{}[]()/\\|,.;:_-=+", lines[3]); | ||
| 1768 | try std.testing.expectEqualStrings("~/code/rad/waystty $ zig build test", lines[4]); | ||
| 1769 | for (lines) |line| { | ||
| 1770 | try std.testing.expect(line.len > 0); | ||
| 1771 | } | ||
| 1772 | } | ||
| 1773 | |||
| 1714 | fn runRenderSmokeTest(alloc: std.mem.Allocator) !void { | 1774 | fn runRenderSmokeTest(alloc: std.mem.Allocator) !void { |
| 1715 | var conn = try wayland_client.Connection.init(); | 1775 | var conn = try wayland_client.Connection.init(); |
| 1716 | defer conn.deinit(); | 1776 | defer conn.deinit(); |