feat(win32 gui): add set_fontface and set_fontsize commands
This commit is contained in:
parent
97cc7be97c
commit
7d138a742c
3 changed files with 72 additions and 1 deletions
|
@ -376,6 +376,16 @@ pub fn adjust_fontsize(self: *Self, amount: f32) void {
|
|||
gui.adjust_fontsize(hwnd, amount);
|
||||
}
|
||||
|
||||
pub fn set_fontsize(self: *Self, fontsize: f32) void {
|
||||
const hwnd = self.hwnd orelse return;
|
||||
gui.set_fontsize(hwnd, fontsize);
|
||||
}
|
||||
|
||||
pub fn set_fontface(self: *Self, fontface: []const u8) void {
|
||||
const hwnd = self.hwnd orelse return;
|
||||
gui.set_fontface(hwnd, fontface);
|
||||
}
|
||||
|
||||
pub fn set_terminal_cursor_color(self: *Self, color: Color) void {
|
||||
_ = self;
|
||||
_ = color;
|
||||
|
|
|
@ -643,6 +643,24 @@ const cmds = struct {
|
|||
tui.current().rdr.adjust_fontsize(amount);
|
||||
}
|
||||
pub const adjust_fontsize_meta = .{ .arguments = &.{.float} };
|
||||
|
||||
pub fn set_fontsize(_: *Self, ctx: Ctx) Result {
|
||||
var fontsize: f32 = undefined;
|
||||
if (!try ctx.args.match(.{tp.extract(&fontsize)}))
|
||||
return error.InvalidArgument;
|
||||
if (build_options.gui)
|
||||
tui.current().rdr.set_fontsize(fontsize);
|
||||
}
|
||||
pub const set_fontsize_meta = .{ .arguments = &.{.float} };
|
||||
|
||||
pub fn set_fontface(_: *Self, ctx: Ctx) Result {
|
||||
var fontface: []const u8 = undefined;
|
||||
if (!try ctx.args.match(.{tp.extract(&fontface)}))
|
||||
return error.InvalidArgument;
|
||||
if (build_options.gui)
|
||||
tui.current().rdr.set_fontface(fontface);
|
||||
}
|
||||
pub const set_fontface_meta = .{ .arguments = &.{.float} };
|
||||
};
|
||||
|
||||
pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result {
|
||||
|
|
|
@ -22,10 +22,14 @@ const HResultError = ddui.HResultError;
|
|||
const WM_APP_EXIT = win32.WM_APP + 1;
|
||||
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_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;
|
||||
|
||||
pub const DropWriter = struct {
|
||||
pub const WriteError = error{};
|
||||
|
@ -176,7 +180,7 @@ fn getFontFace() [:0]const u16 {
|
|||
if (global.fontface == null) {
|
||||
const conf = getConfig();
|
||||
global.fontface = blk: {
|
||||
break :blk std.unicode.utf8ToUtf16LeAllocZ(global.arena, conf.fontface) catch |e| {
|
||||
break :blk std.unicode.utf8ToUtf16LeAllocZ(std.heap.c_allocator, conf.fontface) catch |e| {
|
||||
std.log.err("failed to convert fontface name with {s}", .{@errorName(e)});
|
||||
const default = comptime getFieldDefault(
|
||||
std.meta.fieldInfo(gui_config, .fontface),
|
||||
|
@ -582,6 +586,28 @@ pub fn adjust_fontsize(hwnd: win32.HWND, amount: f32) void {
|
|||
));
|
||||
}
|
||||
|
||||
pub fn set_fontsize(hwnd: win32.HWND, fontsize: f32) void {
|
||||
std.debug.assert(WM_APP_SET_FONTSIZE_RESULT == win32.SendMessageW(
|
||||
hwnd,
|
||||
WM_APP_SET_FONTSIZE,
|
||||
@as(u32, @bitCast(fontsize)),
|
||||
0,
|
||||
));
|
||||
}
|
||||
|
||||
pub fn set_fontface(hwnd: win32.HWND, fontface_utf8: []const u8) void {
|
||||
const fontface = std.unicode.utf8ToUtf16LeAllocZ(std.heap.c_allocator, fontface_utf8) catch |e| {
|
||||
std.log.err("failed to convert fontface name '{s}' with {s}", .{ fontface_utf8, @errorName(e) });
|
||||
return;
|
||||
};
|
||||
std.debug.assert(WM_APP_SET_FONTFACE_RESULT == win32.SendMessageW(
|
||||
hwnd,
|
||||
WM_APP_SET_FONTFACE,
|
||||
@intFromPtr(fontface.ptr),
|
||||
@intCast(fontface.len),
|
||||
));
|
||||
}
|
||||
|
||||
pub fn updateScreen(screen: *const vaxis.Screen) void {
|
||||
global.shared_screen.mutex.lock();
|
||||
defer global.shared_screen.mutex.unlock();
|
||||
|
@ -1272,6 +1298,23 @@ fn WndProc(
|
|||
win32.invalidateHwnd(hwnd);
|
||||
return WM_APP_ADJUST_FONTSIZE_RESULT;
|
||||
},
|
||||
WM_APP_SET_FONTSIZE => {
|
||||
const fontsize: f32 = @bitCast(@as(u32, @intCast(0xFFFFFFFFF & wparam)));
|
||||
global.fontsize = @max(fontsize, 1.0);
|
||||
updateWindowSize(hwnd, win32.WMSZ_BOTTOMRIGHT);
|
||||
win32.invalidateHwnd(hwnd);
|
||||
return WM_APP_SET_FONTSIZE_RESULT;
|
||||
},
|
||||
WM_APP_SET_FONTFACE => {
|
||||
var fontface: [:0]const u16 = undefined;
|
||||
fontface.ptr = @ptrFromInt(wparam);
|
||||
fontface.len = @intCast(lparam);
|
||||
if (global.fontface) |old_fontface| std.heap.c_allocator.free(old_fontface);
|
||||
global.fontface = fontface;
|
||||
updateWindowSize(hwnd, win32.WMSZ_BOTTOMRIGHT);
|
||||
win32.invalidateHwnd(hwnd);
|
||||
return WM_APP_SET_FONTFACE_RESULT;
|
||||
},
|
||||
win32.WM_CREATE => {
|
||||
std.debug.assert(global.state == null);
|
||||
const create_struct: *win32.CREATESTRUCTW = @ptrFromInt(@as(usize, @bitCast(lparam)));
|
||||
|
|
Loading…
Add table
Reference in a new issue