mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
put some config in the devmode UI
This commit is contained in:
@ -3,10 +3,14 @@ const c = @import("c.zig");
|
||||
const imgui = @import("main.zig");
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
pub const fltMax = c.igGET_FLT_MAX;
|
||||
pub const fltMin = c.igGET_FLT_MIN;
|
||||
pub const newFrame = c.igNewFrame;
|
||||
pub const endFrame = c.igEndFrame;
|
||||
pub const getTextLineHeight = c.igGetTextLineHeight;
|
||||
pub const render = c.igRender;
|
||||
pub const end = c.igEnd;
|
||||
pub const endTable = c.igEndTable;
|
||||
pub const beginTooltip = c.igBeginTooltip;
|
||||
pub const endTooltip = c.igEndTooltip;
|
||||
pub const spacing = c.igSpacing;
|
||||
@ -19,6 +23,8 @@ pub const getFontSize = c.igGetFontSize;
|
||||
pub const pushTextWrapPos = c.igPushTextWrapPos;
|
||||
pub const popTextWrapPos = c.igPopTextWrapPos;
|
||||
pub const treePop = c.igTreePop;
|
||||
pub const tableHeadersRow = c.igTableHeadersRow;
|
||||
pub const tableNextColumn = c.igTableNextColumn;
|
||||
|
||||
pub fn showDemoWindow(open: ?*bool) void {
|
||||
c.igShowDemoWindow(@ptrCast([*c]bool, if (open) |v| v else null));
|
||||
@ -60,6 +66,54 @@ pub fn treeNode(
|
||||
);
|
||||
}
|
||||
|
||||
pub fn beginTable(
|
||||
id: [:0]const u8,
|
||||
cols: c_int,
|
||||
flags: TableFlags,
|
||||
) bool {
|
||||
return c.igBeginTable(
|
||||
id.ptr,
|
||||
cols,
|
||||
@bitCast(c_int, flags),
|
||||
.{ .x = 0, .y = 0 },
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn tableNextRow(min_height: f32) void {
|
||||
c.igTableNextRow(0, min_height);
|
||||
}
|
||||
|
||||
pub fn tableSetupColumn(
|
||||
label: [:0]const u8,
|
||||
flags: TableColumnFlags,
|
||||
init_size: f32,
|
||||
) void {
|
||||
c.igTableSetupColumn(
|
||||
label.ptr,
|
||||
@bitCast(c_int, flags),
|
||||
init_size,
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn inputTextMultiline(
|
||||
label: [:0]const u8,
|
||||
buf: []u8,
|
||||
size: c.ImVec2,
|
||||
flags: InputTextFlags,
|
||||
) bool {
|
||||
return c.igInputTextMultiline(
|
||||
label.ptr,
|
||||
buf.ptr,
|
||||
buf.len,
|
||||
size,
|
||||
@bitCast(c_int, flags),
|
||||
null,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
pub const WindowFlags = packed struct {
|
||||
no_title_bar: bool = false,
|
||||
no_resize: bool = false,
|
||||
@ -119,6 +173,93 @@ pub const TreeNodeFlags = packed struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub const TableFlags = packed struct(u32) {
|
||||
resizable: bool = false,
|
||||
reorderable: bool = false,
|
||||
hideable: bool = false,
|
||||
sortable: bool = false,
|
||||
no_saved_settings: bool = false,
|
||||
context_menu_in_body: bool = false,
|
||||
row_bg: bool = false,
|
||||
borders_inner_h: bool = false,
|
||||
borders_outer_h: bool = false,
|
||||
borders_inner_v: bool = false,
|
||||
borders_outer_v: bool = false,
|
||||
no_borders_in_body: bool = false,
|
||||
no_borders_in_body_until_resize: bool = false,
|
||||
sizing_fixed_fit: bool = false,
|
||||
sizing_fixed_same: bool = false,
|
||||
sizing_stretch_prop: bool = false,
|
||||
sizing_stretch_same: bool = false,
|
||||
no_host_extend_x: bool = false,
|
||||
no_host_extend_y: bool = false,
|
||||
no_keep_columns_visible: bool = false,
|
||||
precise_widths: bool = false,
|
||||
no_clip: bool = false,
|
||||
pad_outer_x: bool = false,
|
||||
no_pad_outer_x: bool = false,
|
||||
no_pad_inner_x: bool = false,
|
||||
scroll_x: bool = false,
|
||||
scroll_y: bool = false,
|
||||
sort_multi: bool = false,
|
||||
sort_tristate: bool = false,
|
||||
_padding: u3 = 0,
|
||||
};
|
||||
|
||||
pub const TableColumnFlags = packed struct(u32) {
|
||||
disabled: bool = false,
|
||||
default_hide: bool = false,
|
||||
default_sort: bool = false,
|
||||
width_stretch: bool = false,
|
||||
width_fixed: bool = false,
|
||||
no_resize: bool = false,
|
||||
no_reorder: bool = false,
|
||||
no_hide: bool = false,
|
||||
no_clip: bool = false,
|
||||
no_sort: bool = false,
|
||||
no_sort_ascending: bool = false,
|
||||
no_sort_descending: bool = false,
|
||||
no_header_label: bool = false,
|
||||
no_header_width: bool = false,
|
||||
prefer_sort_ascending: bool = false,
|
||||
prefer_sort_descending: bool = false,
|
||||
indent_enable: bool = false,
|
||||
indent_disable: bool = false,
|
||||
is_enabled: bool = false,
|
||||
is_visible: bool = false,
|
||||
is_sorted: bool = false,
|
||||
is_hovered: bool = false,
|
||||
_unused: u10 = 0,
|
||||
};
|
||||
|
||||
pub const InputTextFlags = packed struct(c_int) {
|
||||
chars_decimal: bool = false,
|
||||
chars_hexadecimal: bool = false,
|
||||
chars_uppercase: bool = false,
|
||||
chars_no_blank: bool = false,
|
||||
auto_select_all: bool = false,
|
||||
enter_returns_true: bool = false,
|
||||
callback_completion: bool = false,
|
||||
callback_history: bool = false,
|
||||
callback_always: bool = false,
|
||||
callback_char_filter: bool = false,
|
||||
allow_tab_input: bool = false,
|
||||
ctrl_enter_for_newline: bool = false,
|
||||
no_horizontal_scroll: bool = false,
|
||||
always_overwrite: bool = false,
|
||||
read_only: bool = false,
|
||||
password: bool = false,
|
||||
no_undo_redo: bool = false,
|
||||
chars_scientific: bool = false,
|
||||
callback_resize: bool = false,
|
||||
callback_edit: bool = false,
|
||||
_padding: u12 = 0,
|
||||
|
||||
test {
|
||||
try std.testing.expectEqual(@bitSizeOf(c_int), @bitSizeOf(InputTextFlags));
|
||||
}
|
||||
};
|
||||
|
||||
pub const HoveredFlags = packed struct {
|
||||
child_windows: bool = false,
|
||||
root_window: bool = false,
|
||||
|
@ -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.* = .{
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user