mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-20 18:56:08 +03:00
inspector: setup basic modes window (empty), dock
This commit is contained in:
@ -6,6 +6,11 @@ const Inspector = @This();
|
|||||||
const cimgui = @import("cimgui");
|
const cimgui = @import("cimgui");
|
||||||
const Surface = @import("Surface.zig");
|
const Surface = @import("Surface.zig");
|
||||||
|
|
||||||
|
/// The window names. These are used with docking so we need to have access.
|
||||||
|
const window_modes = "Modes";
|
||||||
|
|
||||||
|
show_modes_window: bool = true,
|
||||||
|
|
||||||
/// 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 {
|
||||||
const io: *cimgui.c.ImGuiIO = cimgui.c.igGetIO();
|
const io: *cimgui.c.ImGuiIO = cimgui.c.igGetIO();
|
||||||
@ -16,6 +21,10 @@ pub fn setup() void {
|
|||||||
// Our colorspace is sRGB.
|
// Our colorspace is sRGB.
|
||||||
io.ConfigFlags |= cimgui.c.ImGuiConfigFlags_IsSRGB;
|
io.ConfigFlags |= cimgui.c.ImGuiConfigFlags_IsSRGB;
|
||||||
|
|
||||||
|
// Disable the ini file to save layout
|
||||||
|
io.IniFilename = null;
|
||||||
|
io.LogFilename = null;
|
||||||
|
|
||||||
// Use our own embedded font
|
// Use our own embedded font
|
||||||
{
|
{
|
||||||
// TODO: This will have to be recalculated for different screen DPIs.
|
// TODO: This will have to be recalculated for different screen DPIs.
|
||||||
@ -46,14 +55,35 @@ pub fn deinit(self: *Inspector) void {
|
|||||||
|
|
||||||
/// Render the frame.
|
/// Render the frame.
|
||||||
pub fn render(self: *Inspector) void {
|
pub fn render(self: *Inspector) void {
|
||||||
_ = self;
|
const dock_id = cimgui.c.igDockSpaceOverViewport(
|
||||||
|
|
||||||
_ = cimgui.c.igDockSpaceOverViewport(
|
|
||||||
cimgui.c.igGetMainViewport(),
|
cimgui.c.igGetMainViewport(),
|
||||||
cimgui.c.ImGuiDockNodeFlags_None,
|
cimgui.c.ImGuiDockNodeFlags_None,
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
||||||
var show: bool = true;
|
// Flip this boolean to true whenever you want to see the ImGui demo
|
||||||
cimgui.c.igShowDemoWindow(&show);
|
// window which can help you figure out how to use various ImGui widgets.
|
||||||
|
if (false) {
|
||||||
|
var show: bool = true;
|
||||||
|
cimgui.c.igShowDemoWindow(&show);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.renderModesWindow();
|
||||||
|
|
||||||
|
// Setup our dock. We want all our main windows to be tabs in the main bar.
|
||||||
|
cimgui.c.igDockBuilderDockWindow(window_modes, dock_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The modes window shows the currently active terminal modes and allows
|
||||||
|
/// users to toggle them on and off.
|
||||||
|
fn renderModesWindow(self: *Inspector) void {
|
||||||
|
if (!self.show_modes_window) return;
|
||||||
|
|
||||||
|
// Start our window. If we're collapsed we do nothing.
|
||||||
|
defer cimgui.c.igEnd();
|
||||||
|
if (!cimgui.c.igBegin(
|
||||||
|
window_modes,
|
||||||
|
&self.show_modes_window,
|
||||||
|
cimgui.c.ImGuiWindowFlags_None,
|
||||||
|
)) return;
|
||||||
}
|
}
|
||||||
|
@ -201,21 +201,25 @@ fn gtkRender(area: *c.GtkGLArea, ctx: *c.GdkGLContext, ud: ?*anyopaque) callconv
|
|||||||
_ = area;
|
_ = area;
|
||||||
_ = ctx;
|
_ = ctx;
|
||||||
const self: *ImguiWidget = @ptrCast(@alignCast(ud.?));
|
const self: *ImguiWidget = @ptrCast(@alignCast(ud.?));
|
||||||
|
|
||||||
// Setup our frame
|
|
||||||
cimgui.c.igSetCurrentContext(self.ig_ctx);
|
cimgui.c.igSetCurrentContext(self.ig_ctx);
|
||||||
cimgui.c.ImGui_ImplOpenGL3_NewFrame();
|
|
||||||
self.newFrame() catch |err| {
|
|
||||||
log.err("failed to setup frame: {}", .{err});
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
cimgui.c.igNewFrame();
|
|
||||||
|
|
||||||
// Build our UI
|
// Setup our frame. We render twice because some ImGui behaviors
|
||||||
if (self.render_callback) |cb| cb(self.render_userdata);
|
// take multiple renders to process. I don't know how to make this
|
||||||
|
// more efficient.
|
||||||
|
for (0..2) |_| {
|
||||||
|
cimgui.c.ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
self.newFrame() catch |err| {
|
||||||
|
log.err("failed to setup frame: {}", .{err});
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
cimgui.c.igNewFrame();
|
||||||
|
|
||||||
// Render
|
// Build our UI
|
||||||
cimgui.c.igRender();
|
if (self.render_callback) |cb| cb(self.render_userdata);
|
||||||
|
|
||||||
|
// Render
|
||||||
|
cimgui.c.igRender();
|
||||||
|
}
|
||||||
|
|
||||||
// OpenGL final render
|
// OpenGL final render
|
||||||
gl.clearColor(0x28 / 0xFF, 0x2C / 0xFF, 0x34 / 0xFF, 1.0);
|
gl.clearColor(0x28 / 0xFF, 0x2C / 0xFF, 0x34 / 0xFF, 1.0);
|
||||||
|
Reference in New Issue
Block a user