Giter VIP home page Giter VIP logo

imgui-knobs's Introduction

ImGui Knobs

This is a port/adaptation of imgui-rs-knobs, for C++.

image

Usage

Add imgui-knobs.cpp and imgui-knobs.h to your project and include imgui-knobs.h in some source file.

static float value = 0;

if (ImGuiKnobs::Knob("Volume", &value, -6.0f, 6.0f, 0.1f, "%.1fdB", ImGuiKnobVariant_Tick)) {
    // value was changed
}

Draw knobs using either Knob or KnobInt. The API is:

bool ImGuiKnobs::Knob(label, *value, min, max, [speed, format, variant, size, flags, steps])
bool ImGuiKnobs::KnobInt(label, *value, min, max, [speed, format, variant, size, flags, steps])

Variants

variant determines the visual look of the knob. Available variants are: ImGuiKnobVariant_Tick, ImGuiKnobVariant_Dot, ImGuiKnobVariant_Wiper, ImGuiKnobVariant_WiperOnly, ImGuiKnobVariant_WiperDot, ImGuiKnobVariant_Stepped, ImGuiKnobVariant_Space.

Flags

  • ImGuiKnobFlags_NoTitle: Hide the top title.
  • ImGuiKnobFlags_NoInput: Hide the bottom drag input.
  • ImGuiKnobFlags_ValueTooltip: Show a tooltip with the current value on hover.
  • ImGuiKnobFlags_DragHorizontal: Use horizontal dragging (default is vertical).

Size

You can specify a size given as the width of the knob (will be scaled according to ImGui's FontGlobalScale). Default (0) will use 4x line height.

Steps

Steps determines the number of steps draw, it is only used for the ImGuiKnobVariant_Stepped variant.

imgui-knobs's People

Contributors

altschuler avatar leonsal avatar madman10k avatar nitz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imgui-knobs's Issues

API discovery made harder by KNOB_WIDGET and KNOB_WIDGET_DEF ?

This is merely a suggestion, but I suspect that KNOB_WIDGET/KNOB_WIDGET_DEF are making it harder to:

  • discover APIs
  • use IDE facilities to follow through a function call
  • search for code

Etc. this may throw off both tooling and humans alike. They seem to have rather minimal added value considering there are 7 entry points and being the same and declared in the same location, there have little reason to become out of sync.
I would therefore suggest to remove those macro indirection there.

It's also unclear what the detail:: stuff has to do in the public header file, since it seems unused (but also unsure what the VA_ARGS are for, so maybe part of that detail:: is required for public API).

Issue with using SameLine()

Hi there,

This is awesome, though is there a way to get them to work nicely with SameLine()?

image

 static float value = 0;

        if (ImGuiKnobs::WiperKnob("Wiper", &value, -6.0f, 6.0f, "%.1fdB")) {
        // value was changed
        }
        ImGui::SameLine();

        if (ImGuiKnobs::TickKnob("Tick", &value, -6.0f, 6.0f, "%.1fdB")) {
        // value was changed
        }
        ImGui::SameLine();

        if (ImGuiKnobs::DotKnob("Dot", &value, -6.0f, 6.0f, "%.1fdB")) {
        // value was changed
        }
        ImGui::SameLine();
        if (ImGuiKnobs::SpaceKnob("Space", &value, -6.0f, 6.0f, "%.1fdB")) {
        // value was changed
        }
        ImGui::SameLine();
        if (ImGuiKnobs::SteppedKnob("Stepped", &value, -6.0f, 6.0f, "%.1fdB")) {
        // value was changed
        }
    

Speed should be range-dependant

If default speed is used, we should use a value that makes for a "natural" speed, so a value of (max - min) * some_constant.

how to use int type?

hey @altschuler ,
thanks a lot for sharing this!

do you know if we can use int types too?
I am trying but I am getting some rare behaviors....

Small line in some wiper variants...

hey @altschuler ,
I made some customization of some parts to fit my style colors theme,

and I have noticed that in some types, a weird line is drawn.
Is that a "feature"?
It's a line in the center of the arc track:

bandicam.2023-01-05.04-36-09-602.mp4

Do you know how can I fix this and where to look into?

Thanks!

Is it possible to allow for Vertical and Horizontal drag to be treated as the same thing?

Is it possible to allow for Vertical and Horizontal drag to be treated as the same thing? This is standard practice and makes knobs and sliders easier and more intuitive to use. In other words, dragging up/diagonally/right all produce the same outcome. The math is straightforward, just requiring a check to see if vertical or horizontal mouse positions are greater and just use the greater value.

Annoucing Dear ImGui Bundle including imgui-knobs and many others; with support for C++, Python and emscripten

I'm happy to announce the first public release of Dear ImGui Bundle. Dear ImGui Bundle is a bundle for Dear ImGui, including many powerful libraries from its ecosystem. It enables to easily create ImGui applications in C++ and Python, under Windows, macOS, Linux, emscripten. It is aimed at application developers, researchers, and beginner developers who want to quickly get started.

imgui-knobs is a included in the widgets provided with it.

@altschuler : sorry to hijack the issues list for this, and feel to close this issue; as this is just for your information. I informed @ocornut yesterday, and I plan to communicate about it in the ImGui gallery in the next hours.

New dear imgui release breaks compilation

Hello. First, thanks for creating and maintaining this really useful library!

The newest dear imgui release v1.89.4 includes a breaking API change that renames the AddBezierCurve member of ImDrawList to AddBezierCubic

There is currently 1 instance of this in imgui-knobs.cpp at line 36 as part of the draw_arc1 function. All that needs to be done is to replace AddBezierCurve with AddBezierCubic.

This change was introduced in release v1.80. I briefly looked through the changelog for any references to it, and it seems no changes to the API, other than the rename, were made since then, so it's safe to just rename.

I tested the change locally and everything works as expected with the example code from the readme.

[feature] allow multiple flags

it seems that only one flag can be enabled, right?
multiple at same time would be super cool maybe.

static float value = 0;

ImGuiKnobFlags flags;
flags += ImGuiKnobFlags_ValueTooltip;
flags += ImGuiKnobFlags_NoTitle;
flags += ImGuiKnobFlags_NoInput;
flags += ImGuiKnobFlags_DragHorizontal;

if (ImGuiKnobs::Knob("Value", &value, -6.0f, 6.0f, 12 / 250.f, "%.1fdB", ImGuiKnobVariant_WiperDot, size, flags))
{
}

Custom colors for primary, secondary and track colors

Having the feature to select custom colors for each parts of the knobs could bring a lot of styling capabilities to this excellent library!

There are functions defined for this here: https://github.com/altschuler/imgui-knobs/blob/main/imgui-knobs.cpp#L203-L224

One workaround is to wrap the Knob() call in Push/PopStyleColor() for each colors used (namely ImGuiCol_ButtonActive and ImGuiCol_ButtonHovered for primary and ImGuiCol_Framebg for Track) except ImGuiCol_Framebg will likely also affect the input box background and all 6 colors can not be overriden as they are not unique so it doesn't give full customisation.

@altschuler Do you have an idea/suggestion for that?
I know you're not the author of the original code from which this is ported but have you an idea of why these colors were picked up as base for the knobs initially?

I'd have to look at the style editor again but if there are enough unique colors sharing the same default (in dark and light theme) then they could be used instead as base/hovered/active triple and allow each to be overriden as explained above. Hope that makes sense.

Another solution is adding yet another 2/3 optional arguments to Knob()

PS: https://github.com/Simon-L/minisilver/blob/dev/src/imgui-knobs-svg.h for my usecase I wanted fancier knobs so I went ahead and added SVG background and front element!

Detect double-click?

First off, this is a great library. Thanks a ton for making it available.

This might be possible already, but I'd love to be able to detect a double-click on the knob. For example, in Ableton Live, double-clicking on a knob returns it to its default value.

While I'm talking about Ableton Live, there's another optional feature I'd love to see in ImGui. I can make this a separate issue if you want, but it's just an idea: Freezing the mouse cursor and making it invisible for the duration of the adjustment. This is good for sweeping knobs without losing your place. I can hack this behavior in to an extent but it would be nice to have as a real feature.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.