put some config in the devmode UI

This commit is contained in:
Mitchell Hashimoto
2022-11-21 09:09:25 -08:00
parent b4f5107717
commit 9b0fbde838
3 changed files with 185 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ const renderer = @import("renderer.zig");
const font = @import("font/main.zig");
const macos = @import("macos");
const objc = @import("objc");
const DevMode = @import("DevMode.zig");
const log = std.log.scoped(.app);
@@ -62,6 +63,9 @@ pub fn create(alloc: Allocator, config: *const Config) !*App {
var mailbox = try Mailbox.create(alloc);
errdefer mailbox.destroy(alloc);
// If we have DevMode on, store the config so we can show it
if (DevMode.enabled) DevMode.instance.config = config;
var app = try alloc.create(App);
errdefer alloc.destroy(app);
app.* = .{

View File

@@ -10,6 +10,7 @@ const assert = std.debug.assert;
const Atlas = @import("Atlas.zig");
const Window = @import("Window.zig");
const renderer = @import("renderer.zig");
const Config = @import("config.zig").Config;
/// If this is false, the rest of the terminal will be compiled without
/// dev mode support at all.
@@ -22,6 +23,9 @@ pub var instance: DevMode = .{};
/// Whether to show the dev mode UI currently.
visible: bool = false,
/// Our app config
config: ?*const Config = null,
/// The window we're tracking.
window: ?*Window = null,
@@ -32,11 +36,46 @@ window: ?*Window = null,
/// Note: renderers should call their implementation "newFrame" functions
/// prior to this.
pub fn update(self: *const DevMode) !void {
// Buffer that can be used for stuff...
var buf: [1024 * 32]u8 = undefined;
imgui.newFrame();
if (imgui.begin("dev mode", null, .{})) {
defer imgui.end();
if (self.config) |config| {
if (imgui.collapsingHeader("Ghostty Configuration", null, .{})) {
if (imgui.beginTable("config", 2, .{
.row_bg = true,
.borders_inner_h = true,
.borders_outer_h = true,
.borders_inner_v = true,
.borders_outer_v = true,
})) {
// Setup headers
imgui.tableSetupColumn("Key", .{}, 0);
imgui.tableSetupColumn("Value", .{}, 0);
imgui.tableHeadersRow();
// Values
imgui.tableNextRow(0);
_ = imgui.tableNextColumn();
imgui.text("font-family");
_ = imgui.tableNextColumn();
imgui.text((try std.fmt.bufPrintZ(&buf, "{any}", .{config.@"font-family"})).ptr);
defer imgui.endTable();
}
if (imgui.treeNode("Raw Config (Advanced & Ugly)", .{})) {
defer imgui.treePop();
var raw = try std.fmt.bufPrintZ(&buf, "{}", .{config});
imgui.textWrapped("%s", raw.ptr);
}
}
}
if (self.window) |window| {
if (imgui.collapsingHeader("Font Manager", null, .{})) {
imgui.text("Glyphs: %d", window.font_group.glyphs.count());
@@ -71,7 +110,7 @@ pub fn update(self: *const DevMode) !void {
}
// Just demo for now
//imgui.showDemoWindow(null);
imgui.showDemoWindow(null);
}
/// Render the scene and return the draw data. The caller must be imgui-aware