summaryrefslogtreecommitdiff
path: root/src/Layer.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Layer.zig')
-rw-r--r--src/Layer.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Layer.zig b/src/Layer.zig
index c43cab03..96250ce4 100644
--- a/src/Layer.zig
+++ b/src/Layer.zig
@@ -267,3 +267,13 @@ pub fn columnAt(p: *const pardes.Pardes, kind: Kind, id: usize, supplied: ?TagHi
}
return if (p.reprojectTagHit(point)) |mapped| mapped.col else null;
}
+
+/// A tag caret `w` wide at glyph `x`, its left and right edges in the unit
+/// `cell` (a grid cell's width) is in, glyphs `pitch` apart: past a full
+/// row's end it sits at the tag's right edge, where the grid's is clamped.
+pub fn caretSpan(layer: *const Layer, x: u16, cell: f32, pitch: f32, w: f32) [2]f32 {
+ const left = @as(f32, @floatFromInt(layer.viewport.x)) * cell;
+ const right = left + @as(f32, @floatFromInt(layer.viewport.w)) * cell;
+ const x0 = @min(left + @as(f32, @floatFromInt(x)) * pitch, right - w);
+ return .{ x0, @min(right, x0 + w) };
+}