diff options
| -rw-r--r-- | src/Layer.zig | 10 | ||||
| -rw-r--r-- | src/draw.zig | 5 | ||||
| -rw-r--r-- | src/gui/gui.zig | 8 |
3 files changed, 13 insertions, 10 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) }; +} diff --git a/src/draw.zig b/src/draw.zig index b0fede3b..b2884641 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -197,10 +197,7 @@ fn focusedCursorBox(p: *const Pardes, s: *const Surface) ?animation.Box { if (layer.rows == 0 or layer.viewport.y + caret.y != cursor.y) continue; if (cursor.x < layer.viewport.x or cursor.x >= layer.viewport.x + layer.viewport.w) continue; const w = if (caret.bar) tw / bw / 8 else tw / bw; - // A caret past a full row's end sits at the tag's right edge, where - // the grid's is clamped too. - const right = @as(f32, @floatFromInt(layer.viewport.x + layer.viewport.w)); - const x = @min(@as(f32, @floatFromInt(layer.viewport.x)) + @as(f32, @floatFromInt(caret.x)) * tw / bw, right - w); + const x = layer.caretSpan(caret.x, 1, tw / bw, w)[0]; return .{ .x = x, .y = @as(f32, @floatFromInt(cursor.y)) + (bh - th) / 2 / bh, .w = w, .h = th / bh }; } return .{ .x = @floatFromInt(cursor.x), .y = @floatFromInt(cursor.y), .w = if (cursor.bar) 1.0 / 8.0 else 1, .h = 1 }; diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 2533fbef..9768f2de 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -10330,14 +10330,10 @@ fn cursorBoxes(g: *const Gui, surface: *const pardes.Surface, layout: CellLayout const cursor = layer.cursor orelse continue; if (cursor.x >= layer.cols or cursor.y >= layer.rows) continue; const width: f32 = @floatFromInt(g.tagline_width); - const left = @as(f32, @floatFromInt(layer.viewport.x)) * layout.w; - const right = left + @as(f32, @floatFromInt(layer.viewport.w)) * layout.w; - // Past a full row's end the caret sits at the tag's right edge, as - // the grid's does (and the core's cursor box, draw.focusedCursorBox). - const x = @min(left + @as(f32, @floatFromInt(cursor.x)) * width, right - if (cursor.bar) @max(dp(1), width / 8) else width); + const span = layer.caretSpan(cursor.x, layout.w, width, if (cursor.bar) @max(dp(1), width / 8) else width); const y = layer.viewport.y + cursor.y; const top = @as(f32, @floatFromInt(y)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(y, win_h, g.cell_h, g.tagline_height))); - out[n] = .{ .x0 = x, .y0 = top, .x1 = @min(right, x + if (cursor.bar) @max(dp(1), width / 8) else width), .y1 = top + @as(f32, @floatFromInt(g.tagline_height)), .rgb = cursorColor(chrome, &layer.cells[@as(usize, cursor.y) * layer.cols + cursor.x], .tagline), .text = page, .bar = cursor.bar }; + out[n] = .{ .x0 = span[0], .y0 = top, .x1 = span[1], .y1 = top + @as(f32, @floatFromInt(g.tagline_height)), .rgb = cursorColor(chrome, &layer.cells[@as(usize, cursor.y) * layer.cols + cursor.x], .tagline), .text = page, .bar = cursor.bar }; n += 1; } return n; |
