summaryrefslogtreecommitdiff
path: root/src/Layer.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 20:26:51 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:17 -0300
commitab0bd455004c0b7374a6183d45e42b85877f370e (patch)
treed35e93c1f4edb82bda0c0d0d701a9aa09d33d6e3 /src/Layer.zig
parent2b388888348860097967ae04d03f68c00a70472c (diff)
downloadpardes-ab0bd455004c0b7374a6183d45e42b85877f370e.tar.gz
pardes-ab0bd455004c0b7374a6183d45e42b85877f370e.zip
tag_layer.zig folds into Layer.zig, whose TagHit its two functions work on
Two functions (sameCell, columnAt) on Layer.TagHit, 32 lines with their imports, used by edit.zig, mouse.zig and look.zig: they sit with the type now, called Layer.sameCell and Layer.columnAt. docs/design.typ names Layer.zig in its place. No behaviour changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/Layer.zig')
-rw-r--r--src/Layer.zig28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Layer.zig b/src/Layer.zig
index a9827304..7a5fcf7e 100644
--- a/src/Layer.zig
+++ b/src/Layer.zig
@@ -199,3 +199,31 @@ test "a taller tag's rows are grid rows, each hit on its own line" {
try std.testing.expect(layer.tagHit(120, 140, 10, 20, 6, 12) == null);
try std.testing.expect(layer.bodyHit(120, 100, 10, 20, 6, 12) == null);
}
+
+// Pointer hits on tag bands: comparing two, and bringing one that left
+// its band back onto it.
+
+/// Whether two pointer hits name the same cell of the same tag line.
+pub fn sameCell(a: ?TagHit, b: ?TagHit) 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: ?TagHit, 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.rows == 0 or layer.kind != kind or layer.id != id or layer.serial != point.serial or line >= layer.rows) 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 + line)) + 0.5) * bh;
+ break;
+ };
+ return if (p.reprojectTagHit(point)) |mapped| mapped.col else null;
+}