inspector: setup basic modes window (empty), dock

This commit is contained in:
Mitchell Hashimoto
2023-10-21 15:47:22 -07:00
parent 844baf7148
commit a1a398be4d
2 changed files with 51 additions and 17 deletions

View File

@ -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,
); );
// Flip this boolean to true whenever you want to see the ImGui demo
// window which can help you figure out how to use various ImGui widgets.
if (false) {
var show: bool = true; var show: bool = true;
cimgui.c.igShowDemoWindow(&show); 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;
} }

View File

@ -201,9 +201,12 @@ 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);
// Setup our frame. We render twice because some ImGui behaviors
// take multiple renders to process. I don't know how to make this
// more efficient.
for (0..2) |_| {
cimgui.c.ImGui_ImplOpenGL3_NewFrame(); cimgui.c.ImGui_ImplOpenGL3_NewFrame();
self.newFrame() catch |err| { self.newFrame() catch |err| {
log.err("failed to setup frame: {}", .{err}); log.err("failed to setup frame: {}", .{err});
@ -216,6 +219,7 @@ fn gtkRender(area: *c.GtkGLArea, ctx: *c.GdkGLContext, ud: ?*anyopaque) callconv
// Render // Render
cimgui.c.igRender(); 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);