Skip to content

Conversation

Logickin-Lambda
Copy link
Contributor

@Logickin-Lambda Logickin-Lambda commented Aug 12, 2025

Thanks for waiting the setup of my new laptop before going back on working my proposal of porting the knob library.

As proposed in the issues, the library can be conditionally compiled by stating .with_knobs with true:

// zgui
const zgui = b.dependency("zgui", .{
    .shared = false,
    .with_knobs = true,
    .backend = .glfw_wgpu,
   });
exe.root_module.addImport("zgui", zgui.module("root"));
exe.linkLibrary(zgui.artifact("imgui"));

Once the knob part is included, simply call zgui.knobs.knob to create a knob:

// Minimal knob function call
_ = zgui.knobs.knob("Minimal", .{
    .v = &v_knob,
    .v_min = 0,
    .v_max = 1.0,
});

For different knob style, resolution per step, arc shape, and color, we can apply with the additional parameter like shown:

// Styled f32 knob
_ = zgui.knobs.knob("f32 Knob", .{
    .v = &v_knob,
    .v_min = 0,
    .v_max = 1.0,
    .size = 200,
    .speed = 0.0005,
    .angle_min = std.math.pi,
    .angle_max = 2 * std.math.pi,
    .variant = .{ .stepped = true },
    .steps = 5,
});

// Styled i32 knob (applied color)
zgui.pushStyleColor4f(.{ .idx = zgui.StyleCol.button_active, .c = .{ 0.6, 0.2, 0.2, 1 } });
zgui.pushStyleColor4f(.{ .idx = zgui.StyleCol.button_hovered, .c = .{ 0.6, 0.4, 0.4, 1 } });
zgui.pushStyleColor4f(.{ .idx = zgui.StyleCol.button, .c = .{ 0.4, 0, 0, 1 } });
_ = zgui.knobs.knobInt("i32 Knob", .{
    .v = &v_knob_int,
    .v_min = -10,
    .v_max = 10,
    .size = 250,
    .variant = zgui.knobs.KnobVariant{ .wiper_dot = true },
    .flags = zgui.knobs.KnobFlags{
        .drag_horizontal = true,
        .no_input = true,
    },
});
zgui.popStyleColor(.{ .count = 3 });

The result based on the function call above (applied with zgui,sameLine() for the alignments):

Knobs.in.demo.mp4

Time for some code review, and let see if there are further requests to follow.

Logickin-Lambda and others added 15 commits July 28, 2025 15:06
I am about to test these functions, so I am going
to commit those for a backup.
The PlotLines() and PlotHistogram() are now tested
and they can produce the exact same result from the
web imgui demo.
The code is done, and testing is in sight.
As suggested by the code review, I have replaced
my direct array access with a null pointer check.
Now we finally have the knobs for zgui which is
based on the altschuler's imgui-knobs.

Although it seemsingly works fully, I will do more
tests before doing a pull request, along with put
some images for the README section to demonstrate
how to use the elements.
A simple example is added for knobs such
that to demostrate how to create knobs for
your imgui programs.
Seems like my function name was a bit different
where I used snake case while the other code use
camcel case, so I have unified my code to align
the coding style of others.
@hazeycode hazeycode requested a review from Copilot August 31, 2025 14:20
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ports the imgui-knobs library to zgui, enabling the creation of knob UI controls. The integration is optional and can be enabled with the with_knobs build flag.

  • Adds a Zig wrapper for the imgui-knobs C++ library with type-safe API
  • Integrates the imgui-knobs source code and provides conditional compilation
  • Provides both float and integer knob variants with extensive customization options

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/zknobs.cpp C++ wrapper functions to bridge imgui-knobs with Zig
src/knobs.zig Zig API providing type-safe knob functions and configuration structs
src/gui.zig Exports the knobs module when available
libs/imgui_knobs/imgui-knobs.h Header file for the imgui-knobs library
libs/imgui_knobs/imgui-knobs.cpp Implementation of the imgui-knobs library
libs/imgui_knobs/LICENSE MIT license for the imgui-knobs library
build.zig Build configuration to conditionally include knobs support
README.md Documentation and usage examples for the knobs API

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@hazeycode hazeycode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please list the knobs lib version under the Versons section in the README.

@Logickin-Lambda
Copy link
Contributor Author

Logickin-Lambda commented Sep 1, 2025

After I have taken a look into the library, I just found it doesn't have a specific release version, so I am think of stating the last commit date of the library before I have ported it (which is 23 June 2025) or the commit id (8a43bf7) instead because giving it an arbitrary version will not reflect the actual version of the library and it might cause confusion.

There is a chance that the library is small and the update is infrequent, so they don't really care to put them as a release.

If you have concern about my approach, please let me know such that I will notify the author behind the knob library and hopefully they could do a proper release.

@hazeycode
Copy link
Member

The branch name + commit hash is sufficient.

Due to the lack of official release, we have concluded
to use branch name + commit hash, and I have also
set the link used in the version redirecting to
that particular commit history for reference.
@Logickin-Lambda
Copy link
Contributor Author

Done! Besides added the version, clicking the link of the version to the knobs will redirect to that particular commit history as well.

@hazeycode hazeycode merged commit 7bc9461 into zig-gamedev:main Sep 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants