enable drawing cursor on top or bottom based on style

This commit is contained in:
Daniel
2025-07-04 18:50:23 -04:00
parent de3e77570e
commit a9fc3b6fa0
2 changed files with 14 additions and 7 deletions

View File

@ -141,12 +141,19 @@ pub const Contents = struct {
} }
/// Set the cursor value. If the value is null then the cursor is hidden. /// Set the cursor value. If the value is null then the cursor is hidden.
pub fn setCursor(self: *Contents, v: ?shaderpkg.CellText) void { pub fn setCursor(self: *Contents, v: ?shaderpkg.CellText, cursor_style: ?renderer.CursorStyle) void {
self.fg_rows.lists[0].clearRetainingCapacity(); self.fg_rows.lists[0].clearRetainingCapacity();
self.fg_rows.lists[self.size.rows + 1].clearRetainingCapacity(); self.fg_rows.lists[self.size.rows + 1].clearRetainingCapacity();
if (v) |cell| { if (v) |cell| {
self.fg_rows.lists[0].appendAssumeCapacity(cell); if (cursor_style) |style| {
switch (style) {
// Block cursors should be drawn first
.block => self.fg_rows.lists[0].appendAssumeCapacity(cell),
// Other cursor styles should be drawn last
.block_hollow, .bar, .underline, .lock => self.fg_rows.lists[self.size.rows + 1].appendAssumeCapacity(cell),
}
}
} }
} }
@ -374,17 +381,17 @@ test Contents {
} }
} }
// Add a cursor. // Add a block cursor.
const cursor_cell: shaderpkg.CellText = .{ const cursor_cell: shaderpkg.CellText = .{
.mode = .cursor, .mode = .cursor,
.grid_pos = .{ 2, 3 }, .grid_pos = .{ 2, 3 },
.color = .{ 0, 0, 0, 1 }, .color = .{ 0, 0, 0, 1 },
}; };
c.setCursor(cursor_cell); c.setCursor(cursor_cell, .block);
try testing.expectEqual(cursor_cell, c.fg_rows.lists[0].items[0]); try testing.expectEqual(cursor_cell, c.fg_rows.lists[0].items[0]);
// And remove it. // And remove it.
c.setCursor(null); c.setCursor(null, null);
try testing.expectEqual(0, c.fg_rows.lists[0].items.len); try testing.expectEqual(0, c.fg_rows.lists[0].items.len);
} }

View File

@ -2791,7 +2791,7 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
// Setup our cursor rendering information. // Setup our cursor rendering information.
cursor: { cursor: {
// By default, we don't handle cursor inversion on the shader. // By default, we don't handle cursor inversion on the shader.
self.cells.setCursor(null); self.cells.setCursor(null, null);
self.uniforms.cursor_pos = .{ self.uniforms.cursor_pos = .{
std.math.maxInt(u16), std.math.maxInt(u16),
std.math.maxInt(u16), std.math.maxInt(u16),
@ -3162,7 +3162,7 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
@intCast(render.glyph.offset_x), @intCast(render.glyph.offset_x),
@intCast(render.glyph.offset_y), @intCast(render.glyph.offset_y),
}, },
}); }, cursor_style);
} }
fn addPreeditCell( fn addPreeditCell(