mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
inspector is scaled to native dpi
This commit is contained in:
@ -31,6 +31,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
defer flags.deinit();
|
defer flags.deinit();
|
||||||
try flags.appendSlice(&.{
|
try flags.appendSlice(&.{
|
||||||
"-DCIMGUI_FREETYPE=1",
|
"-DCIMGUI_FREETYPE=1",
|
||||||
|
"-DIMGUI_USE_WCHAR32=1",
|
||||||
"-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1",
|
"-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1",
|
||||||
});
|
});
|
||||||
if (target.isWindows()) {
|
if (target.isWindows()) {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
const Inspector = @This();
|
const Inspector = @This();
|
||||||
|
|
||||||
const cimgui = @import("cimgui");
|
const cimgui = @import("cimgui");
|
||||||
|
const Surface = @import("Surface.zig");
|
||||||
|
|
||||||
/// Setup the ImGui state. This requires an ImGui context to be set.
|
/// Setup the ImGui state. This requires an ImGui context to be set.
|
||||||
pub fn setup() void {
|
pub fn setup() void {
|
||||||
@ -14,6 +15,25 @@ pub fn setup() void {
|
|||||||
|
|
||||||
// Our colorspace is sRGB.
|
// Our colorspace is sRGB.
|
||||||
io.ConfigFlags |= cimgui.c.ImGuiConfigFlags_IsSRGB;
|
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 {
|
pub fn init() Inspector {
|
||||||
|
@ -2466,7 +2466,7 @@ fn completeClipboardReadOSC52(self: *Surface, data: []const u8, kind: u8) !void
|
|||||||
self.io_thread.wakeup.notify() catch {};
|
self.io_thread.wakeup.notify() catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const face_ttf = @embedFile("font/res/FiraCode-Regular.ttf");
|
pub const face_ttf = @embedFile("font/res/FiraCode-Regular.ttf");
|
||||||
const face_bold_ttf = @embedFile("font/res/FiraCode-Bold.ttf");
|
pub const face_bold_ttf = @embedFile("font/res/FiraCode-Bold.ttf");
|
||||||
const face_emoji_ttf = @embedFile("font/res/NotoColorEmoji.ttf");
|
pub const face_emoji_ttf = @embedFile("font/res/NotoColorEmoji.ttf");
|
||||||
const face_emoji_text_ttf = @embedFile("font/res/NotoEmoji-Regular.ttf");
|
pub const face_emoji_text_ttf = @embedFile("font/res/NotoEmoji-Regular.ttf");
|
||||||
|
@ -184,14 +184,17 @@ fn gtkResize(area: *c.GtkGLArea, width: c.gint, height: c.gint, ud: ?*anyopaque)
|
|||||||
scale_factor,
|
scale_factor,
|
||||||
});
|
});
|
||||||
|
|
||||||
io.DisplaySize = .{
|
// Our display size is always unscaled. We'll do the scaling in the
|
||||||
.x = @floatFromInt(@divFloor(width, scale_factor)),
|
// style instead. This creates crisper looking fonts.
|
||||||
.y = @floatFromInt(@divFloor(height, scale_factor)),
|
io.DisplaySize = .{ .x = @floatFromInt(width), .y = @floatFromInt(height) };
|
||||||
};
|
io.DisplayFramebufferScale = .{ .x = 1, .y = 1 };
|
||||||
io.DisplayFramebufferScale = .{
|
|
||||||
.x = @floatFromInt(scale_factor),
|
// Setup a new style and scale it appropriately.
|
||||||
.y = @floatFromInt(scale_factor),
|
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 {
|
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.?));
|
const self: *ImguiWidget = @ptrCast(@alignCast(ud.?));
|
||||||
cimgui.c.igSetCurrentContext(self.ig_ctx);
|
cimgui.c.igSetCurrentContext(self.ig_ctx);
|
||||||
const io: *cimgui.c.ImGuiIO = cimgui.c.igGetIO();
|
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();
|
self.queueRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user