mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
use our built-in font for dev mode
This commit is contained in:
34
pkg/imgui/font_atlas.zig
Normal file
34
pkg/imgui/font_atlas.zig
Normal file
@ -0,0 +1,34 @@
|
||||
const std = @import("std");
|
||||
const c = @import("c.zig");
|
||||
const imgui = @import("main.zig");
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
pub const FontAtlas = opaque {
|
||||
pub fn addFontFromMemoryTTF(
|
||||
self: *FontAtlas,
|
||||
data: []const u8,
|
||||
size_px: f32,
|
||||
) void {
|
||||
// We never want the data to be copied by the Atlas, its not
|
||||
// very Zig-like, so we just always set this to false.
|
||||
var cfg = c.ImFontConfig_ImFontConfig();
|
||||
cfg.*.FontDataOwnedByAtlas = false;
|
||||
defer c.ImFontConfig_destroy(cfg);
|
||||
|
||||
_ = c.ImFontAtlas_AddFontFromMemoryTTF(
|
||||
self.cval(),
|
||||
@intToPtr(?*anyopaque, @ptrToInt(data.ptr)),
|
||||
@intCast(c_int, data.len),
|
||||
size_px,
|
||||
cfg,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn cval(self: *FontAtlas) *c.ImFontAtlas {
|
||||
return @ptrCast(
|
||||
*c.ImFontAtlas,
|
||||
@alignCast(@alignOf(c.ImFontAtlas), self),
|
||||
);
|
||||
}
|
||||
};
|
@ -2,6 +2,7 @@ pub const c = @import("c.zig");
|
||||
pub usingnamespace @import("context.zig");
|
||||
pub usingnamespace @import("core.zig");
|
||||
pub usingnamespace @import("draw_data.zig");
|
||||
pub usingnamespace @import("font_atlas.zig");
|
||||
pub usingnamespace @import("io.zig");
|
||||
pub usingnamespace @import("style.zig");
|
||||
|
||||
|
@ -513,9 +513,9 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo
|
||||
const io = try imgui.IO.get();
|
||||
io.cval().IniFilename = "ghostty_dev_mode.ini";
|
||||
|
||||
// On Mac imgui handles scaling automatically just fine. On Linux
|
||||
// and other platforms we need to apply a scaling factor.
|
||||
if (builtin.os.tag != .macos) io.cval().FontGlobalScale = content_scale.x_scale;
|
||||
// Add our built-in fonts so it looks slightly better
|
||||
const dev_atlas = @ptrCast(*imgui.FontAtlas, io.cval().Fonts);
|
||||
dev_atlas.addFontFromMemoryTTF(face_ttf, @intToFloat(f32, font_size.pixels()));
|
||||
|
||||
const style = try imgui.Style.get();
|
||||
style.colorsDark();
|
||||
|
Reference in New Issue
Block a user