diff --git a/pkg/cimgui/build.zig b/pkg/cimgui/build.zig index cf48cbe22..d0e02ded8 100644 --- a/pkg/cimgui/build.zig +++ b/pkg/cimgui/build.zig @@ -31,6 +31,7 @@ pub fn build(b: *std.Build) !void { defer flags.deinit(); try flags.appendSlice(&.{ "-DCIMGUI_FREETYPE=1", + "-DIMGUI_USE_WCHAR32=1", "-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1", }); if (target.isWindows()) { diff --git a/src/Inspector.zig b/src/Inspector.zig index d4b6978d3..0a5f71072 100644 --- a/src/Inspector.zig +++ b/src/Inspector.zig @@ -4,6 +4,7 @@ const Inspector = @This(); const cimgui = @import("cimgui"); +const Surface = @import("Surface.zig"); /// Setup the ImGui state. This requires an ImGui context to be set. pub fn setup() void { @@ -14,6 +15,25 @@ pub fn setup() void { // Our colorspace is sRGB. io.ConfigFlags |= cimgui.c.ImGuiConfigFlags_IsSRGB; + + // Get our style + const style = cimgui.c.igGetStyle(); + cimgui.c.ImGuiStyle_ScaleAllSizes(style, 2); + + // Use our own embedded font + { + const font_config: *cimgui.c.ImFontConfig = cimgui.c.ImFontConfig_ImFontConfig(); + defer cimgui.c.ImFontConfig_destroy(font_config); + font_config.FontDataOwnedByAtlas = false; + _ = cimgui.c.ImFontAtlas_AddFontFromMemoryTTF( + io.Fonts, + @constCast(@ptrCast(Surface.face_ttf)), + Surface.face_ttf.len, + 24, + font_config, + null, + ); + } } pub fn init() Inspector { diff --git a/src/Surface.zig b/src/Surface.zig index 06bddd57b..23845321f 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2466,7 +2466,7 @@ fn completeClipboardReadOSC52(self: *Surface, data: []const u8, kind: u8) !void self.io_thread.wakeup.notify() catch {}; } -const face_ttf = @embedFile("font/res/FiraCode-Regular.ttf"); -const face_bold_ttf = @embedFile("font/res/FiraCode-Bold.ttf"); -const face_emoji_ttf = @embedFile("font/res/NotoColorEmoji.ttf"); -const face_emoji_text_ttf = @embedFile("font/res/NotoEmoji-Regular.ttf"); +pub const face_ttf = @embedFile("font/res/FiraCode-Regular.ttf"); +pub const face_bold_ttf = @embedFile("font/res/FiraCode-Bold.ttf"); +pub const face_emoji_ttf = @embedFile("font/res/NotoColorEmoji.ttf"); +pub const face_emoji_text_ttf = @embedFile("font/res/NotoEmoji-Regular.ttf"); diff --git a/src/apprt/gtk/ImguiWidget.zig b/src/apprt/gtk/ImguiWidget.zig index 696eee739..1432dc9e7 100644 --- a/src/apprt/gtk/ImguiWidget.zig +++ b/src/apprt/gtk/ImguiWidget.zig @@ -184,14 +184,17 @@ fn gtkResize(area: *c.GtkGLArea, width: c.gint, height: c.gint, ud: ?*anyopaque) scale_factor, }); - io.DisplaySize = .{ - .x = @floatFromInt(@divFloor(width, scale_factor)), - .y = @floatFromInt(@divFloor(height, scale_factor)), - }; - io.DisplayFramebufferScale = .{ - .x = @floatFromInt(scale_factor), - .y = @floatFromInt(scale_factor), - }; + // Our display size is always unscaled. We'll do the scaling in the + // style instead. This creates crisper looking fonts. + io.DisplaySize = .{ .x = @floatFromInt(width), .y = @floatFromInt(height) }; + io.DisplayFramebufferScale = .{ .x = 1, .y = 1 }; + + // Setup a new style and scale it appropriately. + const style = cimgui.c.ImGuiStyle_ImGuiStyle(); + defer cimgui.c.ImGuiStyle_destroy(style); + cimgui.c.ImGuiStyle_ScaleAllSizes(style, @floatFromInt(scale_factor)); + const active_style = cimgui.c.igGetStyle(); + active_style.* = style.*; } fn gtkRender(area: *c.GtkGLArea, ctx: *c.GdkGLContext, ud: ?*anyopaque) callconv(.C) c.gboolean { @@ -231,7 +234,14 @@ fn gtkMouseMotion( const self: *ImguiWidget = @ptrCast(@alignCast(ud.?)); cimgui.c.igSetCurrentContext(self.ig_ctx); const io: *cimgui.c.ImGuiIO = cimgui.c.igGetIO(); - cimgui.c.ImGuiIO_AddMousePosEvent(io, @floatCast(x), @floatCast(y)); + const scale_factor: f64 = @floatFromInt(c.gtk_widget_get_scale_factor( + @ptrCast(self.gl_area), + )); + cimgui.c.ImGuiIO_AddMousePosEvent( + io, + @floatCast(x * scale_factor), + @floatCast(y * scale_factor), + ); self.queueRender(); }