Skip to content

Ported Imgui-knobs #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

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.
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.

1 participant