|
1 | | -# cimgui-knobs |
2 | | -Knobs library wrapper in C lang. for Dear ImGui |
| 1 | +# ImGui Knobs |
| 2 | +This is a port/adaptation of [imgui-rs-knobs](https://github.com/DGriffin91/imgui-rs-knobs), for C++. |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +## Usage |
| 7 | +Add `imgui-knobs.cpp` and `imgui-knobs.h` to your project and include `imgui-knobs.h` in some source file. |
| 8 | + |
| 9 | + |
| 10 | +```cpp |
| 11 | +static float value = 0; |
| 12 | + |
| 13 | +if (ImGuiKnobs::Knob("Volume", &value, -6.0f, 6.0f, 0.1f, "%.1fdB", ImGuiKnobVariant_Tick)) { |
| 14 | + // value was changed |
| 15 | +} |
| 16 | +``` |
| 17 | + |
| 18 | +Draw knobs using either `Knob` or `KnobInt`. The API is: |
| 19 | + |
| 20 | +``` |
| 21 | +bool ImGuiKnobs::Knob(label, *value, min, max, [speed, format, variant, size, flags, steps, angle_min, angle_max]) |
| 22 | +bool ImGuiKnobs::KnobInt(label, *value, min, max, [speed, format, variant, size, flags, steps, angle_min, angle_max]) |
| 23 | +``` |
| 24 | + |
| 25 | +You can implement **double click to reset** using standard imgui functionality: |
| 26 | + |
| 27 | +```cpp |
| 28 | +ImGuiKnobs::Knob("Volume", &value, -6.0f, 6.0f, 0.1f, "%.1fdB", ImGuiKnobVariant_Tick); |
| 29 | + |
| 30 | +// Double click to reset, must be directly after drawing the knob so the right imgui "item" is used |
| 31 | +if (ImGui::IsItemActive() && ImGui::IsMouseDoubleClicked(0)) { |
| 32 | + value = 0; |
| 33 | +} |
| 34 | +``` |
| 35 | +
|
| 36 | +See `example/main.cpp` for a demo. |
| 37 | +
|
| 38 | +### Variants |
| 39 | +`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`. |
| 40 | +
|
| 41 | +### Flags |
| 42 | + - `ImGuiKnobFlags_NoTitle`: Hide the top title. |
| 43 | + - `ImGuiKnobFlags_NoInput`: Hide the bottom drag input. |
| 44 | + - `ImGuiKnobFlags_ValueTooltip`: Show a tooltip with the current value on hover. |
| 45 | + - `ImGuiKnobFlags_DragHorizontal`: Use horizontal dragging only (default is bi-directional). |
| 46 | + - `ImGuiKnobFlags_DragVertical`: Use vertical dragging only (default is bi-directional). |
| 47 | +
|
| 48 | +### Size |
| 49 | +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. |
| 50 | +
|
| 51 | +### Colors |
| 52 | +By default the knobs are styled using colors from the imgui theme. You can push/pop style colors to change individual colors. The color ids/flags default to button colors, thus: |
| 53 | +
|
| 54 | +| ImGui Color | Knob meaning | |
| 55 | +|---|---| |
| 56 | +| `ImGuiCol_ButtonActive` | The "filled" part | |
| 57 | +| `ImGuiCol_ButtonHovered` | The "filled" part, when hovered | |
| 58 | +| `ImGuiCol_Button` | The knob track | |
| 59 | +
|
| 60 | +Use `ImGuiCol_FrameBg`/`ImGuiCol_Text` to change the input field colors. |
| 61 | +
|
| 62 | +### Steps |
| 63 | +Steps determines the number of steps draw, it is only used for the `ImGuiKnobVariant_Stepped` variant. |
0 commit comments