window cell size event for changing cell size

This commit is contained in:
Mitchell Hashimoto
2022-11-15 19:54:05 -08:00
parent 657c8540c8
commit 3ce554462a
3 changed files with 37 additions and 0 deletions

View File

@ -527,9 +527,34 @@ pub fn handleMessage(self: *Window, msg: Message) !void {
log.debug("changing title \"{s}\"", .{slice});
try self.window.setTitle(slice.ptr);
},
.cell_size => |size| try self.setCellSize(size),
}
}
/// Change the cell size for the terminal grid. This can happen as
/// a result of changing the font size at runtime.
fn setCellSize(self: *Window, size: renderer.CellSize) !void {
// Update our new cell size for future calcs
self.cell_size = size;
// Update our grid_size
self.grid_size = renderer.GridSize.init(
self.screen_size.subPadding(self.padding),
self.cell_size,
);
// Notify the terminal
_ = self.io_thread.mailbox.push(.{
.resize = .{
.grid_size = self.grid_size,
.screen_size = self.screen_size,
.padding = self.padding,
},
}, .{ .forever = {} });
self.io_thread.wakeup.send() catch {};
}
/// This queues a render operation with the renderer thread. The render
/// isn't guaranteed to happen immediately but it will happen as soon as
/// practical.

View File

@ -18,6 +18,7 @@ const trace = @import("tracy").trace;
const math = @import("../math.zig");
const lru = @import("../lru.zig");
const DevMode = @import("../DevMode.zig");
const Window = @import("../Window.zig");
const log = std.log.scoped(.grid);
@ -80,6 +81,9 @@ focused: bool,
/// Padding options
padding: renderer.Options.Padding,
/// The mailbox for communicating with the window.
window_mailbox: Window.Mailbox,
/// The raw structure that maps directly to the buffer sent to the vertex shader.
/// This must be "extern" so that the field order is not reordered by the
/// Zig compiler.
@ -293,6 +297,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !OpenGL {
.foreground = .{ .r = 255, .g = 255, .b = 255 },
.focused = true,
.padding = options.padding,
.window_mailbox = options.window_mailbox,
};
}
@ -476,8 +481,12 @@ pub fn setFontSize(self: *OpenGL, size: font.face.DesiredSize) !void {
// nothing since the grid size couldn't have possibly changed.
const new_cell_size = .{ .width = metrics.cell_width, .height = metrics.cell_height };
if (std.meta.eql(self.cell_size, new_cell_size)) return;
self.cell_size = new_cell_size;
// Notify the window that the cell size changed.
_ = self.window_mailbox.push(.{
.cell_size = new_cell_size,
}, .{ .forever = {} });
}
/// Reload the font metrics, recalculate cell size, and send that all

View File

@ -9,6 +9,9 @@ pub const Message = union(enum) {
/// the termio message so that we can more efficiently send strings
/// of any length
set_title: [256]u8,
/// Change the cell size.
cell_size: renderer.CellSize,
};
/// A window mailbox.