diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-28 00:42:04 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:14 -0300 |
| commit | 425d9beb9c977df364ed83743cb2efdef9429478 (patch) | |
| tree | eaba2e20ff041b50539d1b47fdeb498e59237cf0 /src/tag_layer.zig | |
| parent | 1912878e753ce12fdc1ac72ae2e83ddfc18df002 (diff) | |
| download | pardes-425d9beb9c977df364ed83743cb2efdef9429478.tar.gz pardes-425d9beb9c977df364ed83743cb2efdef9429478.zip | |
File the tag code into tagline.zig and draw tags beside bodies
With tags reduced to Texts, what is left of them is the computed prefix, the
default and saved tails, entering and leaving a tag and the headers: that goes
to tagline.zig, as acme keeps the tag half of a window in wind.c. Tag and
header drawing moves next to body drawing in body_layer.zig, and the tag hit
helpers go to tag_layer.zig with the Hit they read, where sameCell now also
tells the lines of a taller tag apart. The docs describe the tag as a Text.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/tag_layer.zig')
| -rw-r--r-- | src/tag_layer.zig | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/tag_layer.zig b/src/tag_layer.zig index ac7c4ac2..7cfe5bbf 100644 --- a/src/tag_layer.zig +++ b/src/tag_layer.zig @@ -78,3 +78,28 @@ test "tag text capacity uses its own pitch and excludes the physical grip" { try std.testing.expect(layer.hitAt(120, 85, std.math.nan(f32), 20, 6, 12) == null); try std.testing.expect(layer.hitAt(120, 85, 10, 20, 0, 12) == null); } + +/// Whether two pointer hits name the same cell of the same tag line. +pub fn sameCell(a: ?Hit, b: ?Hit) bool { + const first = a orelse return b == null; + const second = b orelse return false; + return first.kind == second.kind and first.id == second.id and first.serial == second.serial and first.line == second.line and first.col == second.col; +} + +/// The tag column a host's pointer is at. Clamped, a point off the tag is +/// brought back onto line `line` of it, for a drag that leaves it. +pub fn columnAt(p: *const pardes.Pardes, kind: Kind, id: usize, supplied: ?Hit, clamp: bool, line: u16) ?u16 { + var point = supplied orelse return null; + if (point.kind != kind or point.id != id) return null; + if (clamp) for (p.surface.tagLayers()) |*layer| { + if (layer.cols == 0 or layer.kind != kind or layer.id != id or layer.serial != point.serial or layer.line != line) continue; + const bw: f32 = @floatFromInt(point.metrics.body_w); + const bh: f32 = @floatFromInt(point.metrics.body_h); + const left = @as(f32, @floatFromInt(layer.viewport.x)) * bw; + const right = @as(f32, @floatFromInt(layer.viewport.x + layer.viewport.w)) * bw; + point.pixel_x = std.math.clamp(point.pixel_x, left, @max(left, right - 0.001)); + point.pixel_y = (@as(f32, @floatFromInt(layer.viewport.y)) + 0.5) * bh; + break; + }; + return if (p.reprojectTagHit(point)) |mapped| mapped.col else null; +} |
