{"id":18228787,"url":"https://github.com/zig-gamedev/zgui","last_synced_at":"2025-04-03T12:30:55.298Z","repository":{"id":260973281,"uuid":"882849476","full_name":"zig-gamedev/zgui","owner":"zig-gamedev","description":"Zig build package and bindings for https://github.com/ocornut/imgui and optional extras.","archived":false,"fork":false,"pushed_at":"2025-03-30T16:57:33.000Z","size":2028,"stargazers_count":32,"open_issues_count":11,"forks_count":27,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-30T17:35:42.739Z","etag":null,"topics":["dearimgui","gamedev","gui","imgui","zig"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zig-gamedev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-03T22:53:14.000Z","updated_at":"2025-03-30T16:57:37.000Z","dependencies_parsed_at":"2024-11-04T01:17:38.068Z","dependency_job_id":"e9e5eddc-cb2c-4c84-9745-e53ae9a692b6","html_url":"https://github.com/zig-gamedev/zgui","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"b353ef8be9ca4ee8925651671ad7dce645aa4bf4"},"previous_names":["zig-gamedev/zgui"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzgui","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzgui/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzgui/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzgui/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zig-gamedev","download_url":"https://codeload.github.com/zig-gamedev/zgui/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247002169,"owners_count":20867415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dearimgui","gamedev","gui","imgui","zig"],"created_at":"2024-11-04T08:03:30.849Z","updated_at":"2025-04-03T12:30:55.277Z","avatar_url":"https://github.com/zig-gamedev.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [zgui](https://github.com/zig-gamedev/zgui)\n\nZig build package and bindings for [Dear Imgui](https://github.com/ocornut/imgui) \u0026 extras.\n\nEasy to use, hand-crafted API with default arguments, named parameters and Zig style text formatting. [Here](https://github.com/michal-z/zig-gamedev/tree/main/samples/minimal_zgpu_zgui) is a simple sample application, and [here](https://github.com/michal-z/zig-gamedev/tree/main/samples/gui_test_wgpu) is a full one.\n\n## Features\n\n* Most public dear imgui API exposed\n* All memory allocations go through user provided Zig allocator\n* [DrawList API](#drawlist-api) for vector graphics, text rendering and custom widgets\n* [Test engine API](#test-engine-api) for automatic testing\n* [Plot API](#plot-api) for advanced data visualizations\n* [Gizmo API](#gizmo-api) for gizmo\n* [Node editor API](#node-editor-api) for node based stuff\n\n## Versions\n\n* [ImGui](https://github.com/ocornut/imgui/tree/v1.91.8-docking) `1.91.8-docking`\n* [ImGui test engine](https://github.com/ocornut/imgui_test_engine/tree/v1.91.8)  `1.91.8`\n* [ImPlot](https://github.com/epezent/implot) `O.17`\n* [ImGuizmo](https://github.com/CedricGuillemet/ImGuizmo) `1.89 WIP`\n* [ImGuiNodeEditor](https://github.com/thedmd/imgui-node-editor/tree/v0.9.3) `O.9.3`\n\n## Getting started\n\nExample `build.zig`:\n```zig\n\npub fn build(b: *std.Build) void {\n    const exe = b.addExecutable(.{ ... });\n\n    const zgui = b.dependency(\"zgui\", .{\n        .shared = false,\n        .with_implot = true,\n    });\n    exe.root_module.addImport(\"zgui\", zgui.module(\"root\"));\n    exe.linkLibrary(zgui.artifact(\"imgui\"));\n    \n    { // Needed for glfw/wgpu rendering backend\n        const zglfw = b.dependency(\"zglfw\", .{});\n        exe.root_module.addImport(\"zglfw\", zglfw.module(\"root\"));\n        exe.linkLibrary(zglfw.artifact(\"glfw\"));\n\n        const zpool = b.dependency(\"zpool\", .{});\n        exe.root_module.addImport(\"zpool\", zpool.module(\"root\"));\n\n        const zgpu = b.dependency(\"zgpu\", .{});\n        exe.root_module.addImport(\"zgpu\", zgpu.module(\"root\"));\n        exe.linkLibrary(zgpu.artifact(\"zdawn\"));\n    }\n}\n```\n\nNow in your code you may import and use `zgui`:\n\n```zig\nconst zgui = @import(\"zgui\");\n\nzgui.init(allocator);\n\n_ = zgui.io.addFontFromFile(content_dir ++ \"Roboto-Medium.ttf\", 16.0);\n\nzgui.backend.init(\n    window,\n    demo.gctx.device,\n    @enumToInt(swapchain_format),\n    @enumToInt(depth_format),\n);\n```\n\n```zig\n// Main loop\nwhile (...) {\n    zgui.backend.newFrame(framebuffer_width, framebuffer_height);\n\n    zgui.bulletText(\n        \"Average :  {d:.3} ms/frame ({d:.1} fps)\",\n        .{ demo.gctx.stats.average_cpu_time, demo.gctx.stats.fps },\n    );\n    zgui.bulletText(\"W, A, S, D :  move camera\", .{});\n    zgui.spacing();\n\n    if (zgui.button(\"Setup Scene\", .{})) {\n        // Button pressed.\n    }\n\n    if (zgui.dragFloat(\"Drag 1\", .{ .v = \u0026value0 })) {\n        // value0 has changed\n    }\n\n    if (zgui.dragFloat(\"Drag 2\", .{ .v = \u0026value0, .min = -1.0, .max = 1.0 })) {\n        // value1 has changed\n    }\n\n    // Setup wgpu render pass here\n\n    zgui.backend.draw(pass);\n}\n```\n\n### Building a shared library\n\nIf your project spans multiple zig modules that both use ImGui, such as an exe paired with a dll, you may want to build the `zgui` dependencies (`zgui_pkg.zgui_c_cpp`) as a shared library. This can be enabled with the `shared` build option. Then, in `build.zig`, use `zgui_pkg.link` to link `zgui` to all the modules that use ImGui.\n\nWhen built this way, the ImGui context will be located in the shared library. However, the `zgui` zig code (which is compiled separately into each module) requires its own memory buffer which has to be initialized separately with `initNoContext`.\n\nIn your executable:\n```zig\nconst zgui = @import(\"zgui\");\nzgui.init(allocator);\ndefer zgui.deinit();\n```\n\nIn your shared library:\n```zig\nconst zgui = @import(\"zgui\");\nzgui.initNoContext(allocator);\ndefer zgui.deinitNoContxt();\n```\n\n### DrawList API\n\n```zig\ndraw_list.addQuad(.{\n    .p1 = .{ 170, 420 },\n    .p2 = .{ 270, 420 },\n    .p3 = .{ 220, 520 },\n    .p4 = .{ 120, 520 },\n    .col = 0xff_00_00_ff,\n    .thickness = 3.0,\n});\ndraw_list.addText(.{ 130, 130 }, 0xff_00_00_ff, \"The number is: {}\", .{7});\ndraw_list.addCircleFilled(.{ .p = .{ 200, 600 }, .r = 50, .col = 0xff_ff_ff_ff });\ndraw_list.addCircle(.{ .p = .{ 200, 600 }, .r = 30, .col = 0xff_00_00_ff, .thickness = 11 });\ndraw_list.addPolyline(\n    \u0026.{ .{ 100, 700 }, .{ 200, 600 }, .{ 300, 700 }, .{ 400, 600 } },\n    .{ .col = 0xff_00_aa_11, .thickness = 7 },\n);\n```\n\n### Test Engine API\nZig wraper for [ImGUI test engine](https://github.com/ocornut/imgui_test_engine).\n\n```zig\nvar check_b = false;\nvar _te: *zgui.te.TestEngine = zgui.te.getTestEngine().?;\nfn registerTests() void {\n    _ = _te.registerTest(\n        \"Awesome\",\n        \"should_do_some_another_magic\",\n        @src(),\n        struct {\n            pub fn gui(ctx: *zgui.te.TestContext) !void {\n                _ = ctx; // autofix\n                _ = zgui.begin(\"Test Window\", .{ .flags = .{ .no_saved_settings = true } });\n                defer zgui.end();\n\n                zgui.text(\"Hello, automation world\", .{});\n                _ = zgui.button(\"Click Me\", .{});\n                if (zgui.treeNode(\"Node\")) {\n                    defer zgui.treePop();\n\n                    _ = zgui.checkbox(\"Checkbox\", .{ .v = \u0026check_b });\n                }\n            }\n\n            pub fn run(ctx: *zgui.te.TestContext) !void {\n                ctx.setRef(\"/Test Window\");\n                ctx.windowFocus(\"\");\n\n                ctx.itemAction(.click, \"Click Me\", .{}, null);\n                ctx.itemAction(.open, \"Node\", .{}, null);\n                ctx.itemAction(.check, \"Node/Checkbox\", .{}, null);\n                ctx.itemAction(.uncheck, \"Node/Checkbox\", .{}, null);\n\n                std.testing.expect(true) catch |err| {\n                    zgui.te.checkTestError(@src(), err);\n                    return;\n                };\n            }\n        },\n    );\n}\n```\n\n### Plot API\n```zig\nif (zgui.plot.beginPlot(\"Line Plot\", .{ .h = -1.0 })) {\n    zgui.plot.setupAxis(.x1, .{ .label = \"xaxis\" });\n    zgui.plot.setupAxisLimits(.x1, .{ .min = 0, .max = 5 });\n    zgui.plot.setupLegend(.{ .south = true, .west = true }, .{});\n    zgui.plot.setupFinish();\n    zgui.plot.plotLineValues(\"y data\", i32, .{ .v = \u0026.{ 0, 1, 0, 1, 0, 1 } });\n    zgui.plot.plotLine(\"xy data\", f32, .{\n        .xv = \u0026.{ 0.1, 0.2, 0.5, 2.5 },\n        .yv = \u0026.{ 0.1, 0.3, 0.5, 0.9 },\n    });\n    zgui.plot.endPlot();\n}\n```\n\n### Gizmo API\n\nZig wraper for [ImGuizmo](https://github.com/CedricGuillemet/ImGuizmo).\n\n\n### Node editor API\n\nZig wraper for [ImGuiNodeEditor](https://github.com/thedmd/imgui-node-editor).\n\n```zig\nvar node_editor = zgui.node_editor.EditorContext.create(.{ .enable_smooth_zoom = true }),\n\nzgui.node_editor.setCurrentEditor(node_editor);\ndefer zgui.node_editor.setCurrentEditor(null);\n{\n    zgui.node_editor.begin(\"NodeEditor\", .{ 0, 0 });\n    defer zgui.node_editor.end();\n\n    zgui.node_editor.beginNode(1);\n    {\n        defer zgui.node_editor.endNode();\n\n        zgui.textUnformatted(\"Node A\");\n\n        zgui.node_editor.beginPin(1, .input);\n        {\n            defer zgui.node_editor.endPin();\n            zgui.textUnformatted(\"-\u003e In\");\n        }\n\n        zgui.sameLine(.{});\n\n        zgui.node_editor.beginPin(2, .output);\n        {\n            defer zgui.node_editor.endPin();\n            zgui.textUnformatted(\"Out -\u003e\");\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzig-gamedev%2Fzgui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzig-gamedev%2Fzgui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzig-gamedev%2Fzgui/lists"}