feat(win32 gui): add reset_fontsize and rest_fontface commands

This commit is contained in:
CJ van den Berg 2025-01-14 18:53:53 +01:00
parent a5622af68d
commit 6530a7a51c
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
5 changed files with 61 additions and 1 deletions

View file

@ -1,6 +1,7 @@
{
"project": {
"press": [
["ctrl+0", "reset_fontsize"],
["ctrl+=", "adjust_fontsize", 1.0],
["ctrl+-", "adjust_fontsize", -1.0]
]

View file

@ -1,6 +1,7 @@
{
"project": {
"press": [
["ctrl+0", "reset_fontsize"],
["ctrl+plus", "adjust_fontsize", 1.0],
["ctrl+minus", "adjust_fontsize", -1.0],
["f5", ["create_scratch_buffer", "*test*"], ["shell_execute_insert", "zig", "build", "test"]],

View file

@ -381,11 +381,21 @@ pub fn set_fontsize(self: *Self, fontsize: f32) void {
gui.set_fontsize(hwnd, fontsize);
}
pub fn reset_fontsize(self: *Self) void {
const hwnd = self.hwnd orelse return;
gui.reset_fontsize(hwnd);
}
pub fn set_fontface(self: *Self, fontface: []const u8) void {
const hwnd = self.hwnd orelse return;
gui.set_fontface(hwnd, fontface);
}
pub fn reset_fontface(self: *Self) void {
const hwnd = self.hwnd orelse return;
gui.reset_fontface(hwnd);
}
pub fn set_terminal_cursor_color(self: *Self, color: Color) void {
_ = self;
_ = color;

View file

@ -653,6 +653,12 @@ const cmds = struct {
}
pub const set_fontsize_meta = .{ .arguments = &.{.float} };
pub fn reset_fontsize(_: *Self, _: Ctx) Result {
if (build_options.gui)
tui.current().rdr.reset_fontsize();
}
pub const reset_fontsize_meta = .{ .description = "Reset font to configured size" };
pub fn set_fontface(_: *Self, ctx: Ctx) Result {
var fontface: []const u8 = undefined;
if (!try ctx.args.match(.{tp.extract(&fontface)}))
@ -661,6 +667,12 @@ const cmds = struct {
tui.current().rdr.set_fontface(fontface);
}
pub const set_fontface_meta = .{ .arguments = &.{.float} };
pub fn reset_fontface(_: *Self, _: Ctx) Result {
if (build_options.gui)
tui.current().rdr.reset_fontface();
}
pub const reset_fontface_meta = .{ .description = "Reset font to configured face" };
};
pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result {

View file

@ -28,13 +28,17 @@ const WM_APP_SET_BACKGROUND = win32.WM_APP + 2;
const WM_APP_ADJUST_FONTSIZE = win32.WM_APP + 3;
const WM_APP_SET_FONTSIZE = win32.WM_APP + 4;
const WM_APP_SET_FONTFACE = win32.WM_APP + 5;
const WM_APP_UPDATE_SCREEN = win32.WM_APP + 6;
const WM_APP_RESET_FONTSIZE = win32.WM_APP + 6;
const WM_APP_RESET_FONTFACE = win32.WM_APP + 7;
const WM_APP_UPDATE_SCREEN = win32.WM_APP + 8;
const WM_APP_EXIT_RESULT = 0x45feaa11;
const WM_APP_SET_BACKGROUND_RESULT = 0x369a26cd;
const WM_APP_ADJUST_FONTSIZE_RESULT = 0x79aba9ef;
const WM_APP_SET_FONTSIZE_RESULT = 0x72fa44bc;
const WM_APP_SET_FONTFACE_RESULT = 0x1a49ffa8;
const WM_APP_RESET_FONTSIZE_RESULT = 0x082c4c0c;
const WM_APP_RESET_FONTFACE_RESULT = 0x0101f996;
const WM_APP_UPDATE_SCREEN_RESULT = 0x3add213b;
pub const DropWriter = struct {
@ -453,6 +457,15 @@ pub fn set_fontsize(hwnd: win32.HWND, fontsize: f32) void {
));
}
pub fn reset_fontsize(hwnd: win32.HWND) void {
std.debug.assert(WM_APP_RESET_FONTSIZE_RESULT == win32.SendMessageW(
hwnd,
WM_APP_RESET_FONTSIZE,
0,
0,
));
}
pub fn set_fontface(hwnd: win32.HWND, fontface_utf8: []const u8) void {
const fontface = FontFace.initUtf8(fontface_utf8) catch |e| {
std.log.err("failed to set fontface '{s}' with {s}", .{ fontface_utf8, @errorName(e) });
@ -466,6 +479,15 @@ pub fn set_fontface(hwnd: win32.HWND, fontface_utf8: []const u8) void {
));
}
pub fn reset_fontface(hwnd: win32.HWND) void {
std.debug.assert(WM_APP_RESET_FONTFACE_RESULT == win32.SendMessageW(
hwnd,
WM_APP_RESET_FONTFACE,
0,
0,
));
}
pub fn updateScreen(hwnd: win32.HWND, screen: *const vaxis.Screen) void {
std.debug.assert(WM_APP_UPDATE_SCREEN_RESULT == win32.SendMessageW(
hwnd,
@ -1085,6 +1107,13 @@ fn WndProc(
win32.invalidateHwnd(hwnd);
return WM_APP_SET_FONTSIZE_RESULT;
},
WM_APP_RESET_FONTSIZE => {
const state = stateFromHwnd(hwnd);
global.fontsize = null;
updateWindowSize(hwnd, win32.WMSZ_BOTTOMRIGHT, &state.bounds);
win32.invalidateHwnd(hwnd);
return WM_APP_SET_FONTSIZE_RESULT;
},
WM_APP_SET_FONTFACE => {
const state = stateFromHwnd(hwnd);
const fontface: *FontFace = @ptrFromInt(wparam);
@ -1093,6 +1122,13 @@ fn WndProc(
win32.invalidateHwnd(hwnd);
return WM_APP_SET_FONTFACE_RESULT;
},
WM_APP_RESET_FONTFACE => {
const state = stateFromHwnd(hwnd);
global.fontface = null;
updateWindowSize(hwnd, win32.WMSZ_BOTTOMRIGHT, &state.bounds);
win32.invalidateHwnd(hwnd);
return WM_APP_SET_FONTFACE_RESULT;
},
WM_APP_UPDATE_SCREEN => {
const screen: *const vaxis.Screen = @ptrFromInt(wparam);
_ = global.screen_arena.reset(.retain_capacity);