Skip to content

Commit 607a677

Browse files
committed
added: sources
1 parent 84818e7 commit 607a677

24 files changed

Lines changed: 52472 additions & 3 deletions

.clang-format

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Generated from CLion C/C++ Code Style settings
2+
BasedOnStyle: LLVM
3+
AccessModifierOffset: -4
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveAssignments: false
6+
AlignOperands: true
7+
AllowAllArgumentsOnNextLine: false
8+
AllowAllConstructorInitializersOnNextLine: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: Always
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: All
13+
AllowShortIfStatementsOnASingleLine: Always
14+
AllowShortLambdasOnASingleLine: All
15+
AllowShortLoopsOnASingleLine: true
16+
AlwaysBreakAfterReturnType: None
17+
AlwaysBreakTemplateDeclarations: Yes
18+
BreakBeforeBraces: Custom
19+
BraceWrapping:
20+
AfterCaseLabel: false
21+
AfterClass: false
22+
AfterControlStatement: Never
23+
AfterEnum: false
24+
AfterFunction: false
25+
AfterNamespace: false
26+
AfterUnion: false
27+
BeforeCatch: false
28+
BeforeElse: false
29+
IndentBraces: false
30+
SplitEmptyFunction: false
31+
SplitEmptyRecord: true
32+
BreakBeforeBinaryOperators: None
33+
BreakBeforeTernaryOperators: true
34+
BreakConstructorInitializers: BeforeColon
35+
BreakInheritanceList: BeforeColon
36+
ColumnLimit: 0
37+
CompactNamespaces: false
38+
ContinuationIndentWidth: 8
39+
IndentCaseLabels: true
40+
IndentPPDirectives: None
41+
IndentWidth: 4
42+
KeepEmptyLinesAtTheStartOfBlocks: true
43+
MaxEmptyLinesToKeep: 2
44+
NamespaceIndentation: All
45+
ObjCSpaceAfterProperty: false
46+
ObjCSpaceBeforeProtocolList: true
47+
PointerAlignment: Right
48+
ReflowComments: false
49+
SpaceAfterCStyleCast: true
50+
SpaceAfterLogicalNot: false
51+
SpaceAfterTemplateKeyword: false
52+
SpaceBeforeAssignmentOperators: true
53+
SpaceBeforeCpp11BracedList: false
54+
SpaceBeforeCtorInitializerColon: true
55+
SpaceBeforeInheritanceColon: true
56+
SpaceBeforeParens: ControlStatements
57+
SpaceBeforeRangeBasedForLoopColon: true
58+
SpaceInEmptyParentheses: false
59+
SpacesBeforeTrailingComments: 0
60+
SpacesInAngles: false
61+
SpacesInCStyleCastParentheses: false
62+
SpacesInContainerLiterals: false
63+
SpacesInParentheses: false
64+
SpacesInSquareBrackets: false
65+
TabWidth: 4
66+
UseTab: Never
67+
BinPackArguments: false
68+
BinPackParameters: false

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 dinau
3+
Copyright (c) 2022 Simon Altschuler
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
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+
![image](https://user-images.githubusercontent.com/956928/164050142-96a8dde4-7d2e-43e4-9afe-14ab48eac243.png)
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.

cimgui-knobs.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "imgui-knobs.h"
2+
#include "cimgui-knobs.h"
3+
4+
extern "C" {
5+
6+
bool IgKnobFloat(
7+
const char *label,
8+
float *p_value,
9+
float v_min,
10+
float v_max,
11+
float speed,
12+
const char *format,
13+
IgKnobVariant variant,
14+
float size,
15+
IgKnobFlags flags,
16+
int steps,
17+
float angle_min,
18+
float angle_max) {
19+
return ImGuiKnobs::Knob(label, p_value, v_min, v_max, speed, format,
20+
static_cast<ImGuiKnobVariant>(variant), size,
21+
static_cast<ImGuiKnobFlags>(flags), steps, angle_min,
22+
angle_max);
23+
}
24+
25+
bool IgKnobInt(
26+
const char *label,
27+
int *p_value,
28+
int v_min,
29+
int v_max,
30+
float speed,
31+
const char *format,
32+
IgKnobVariant variant,
33+
float size,
34+
IgKnobFlags flags,
35+
int steps,
36+
float angle_min,
37+
float angle_max) {
38+
return ImGuiKnobs::KnobInt(label, p_value, v_min, v_max, speed, format,
39+
static_cast<ImGuiKnobVariant>(variant), size,
40+
static_cast<ImGuiKnobFlags>(flags), steps,
41+
angle_min, angle_max);
42+
}
43+
44+
} // extern "C"

cimgui-knobs.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#include <stdbool.h>
8+
9+
typedef struct IgKnobColorSet {
10+
unsigned int base;
11+
unsigned int hovered;
12+
unsigned int active;
13+
} IgKnobColorSet;
14+
15+
typedef enum IgKnobFlags {
16+
IgKnobFlags_NoTitle = 1 << 0,
17+
IgKnobFlags_NoInput = 1 << 1,
18+
IgKnobFlags_ValueTooltip = 1 << 2,
19+
IgKnobFlags_DragHorizontal = 1 << 3,
20+
IgKnobFlags_DragVertical = 1 << 4,
21+
} IgKnobFlags;
22+
23+
typedef enum IgKnobVariant {
24+
IgKnobVariant_Tick = 1 << 0,
25+
IgKnobVariant_Dot = 1 << 1,
26+
IgKnobVariant_Wiper = 1 << 2,
27+
IgKnobVariant_WiperOnly = 1 << 3,
28+
IgKnobVariant_WiperDot = 1 << 4,
29+
IgKnobVariant_Stepped = 1 << 5,
30+
IgKnobVariant_Space = 1 << 6,
31+
} IgKnobVariant;
32+
33+
bool IgKnobFloat(
34+
const char *label,
35+
float *p_value,
36+
float v_min,
37+
float v_max,
38+
float speed,
39+
const char *format,
40+
IgKnobVariant variant,
41+
float size,
42+
IgKnobFlags flags,
43+
int steps,
44+
float angle_min,
45+
float angle_max);
46+
47+
bool IgKnobInt(
48+
const char *label,
49+
int *p_value,
50+
int v_min,
51+
int v_max,
52+
float speed,
53+
const char *format,
54+
IgKnobVariant variant,
55+
float size,
56+
IgKnobFlags flags,
57+
int steps,
58+
float angle_min,
59+
float angle_max);
60+
61+
#ifdef __cplusplus
62+
}
63+
#endif

example/Makefile

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Source: https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_opengl2/Makefile
2+
#
3+
# Cross Platform Makefile
4+
# Compatible with MSYS2/MINGW, Ubuntu 14.04.1 and Mac OS X
5+
#
6+
# You will need SDL2 (http://www.libsdl.org):
7+
# Linux:
8+
# apt-get install libsdl2-dev
9+
# Mac OS X:
10+
# brew install sdl2
11+
# MSYS2:
12+
# pacman -S mingw-w64-i686-SDL2
13+
#
14+
15+
#CXX = g++
16+
#CXX = clang++
17+
18+
EXE = imgui_knobs_example
19+
IMGUI_DIR = .
20+
SOURCES = main.cpp
21+
SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
22+
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl2.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl2.cpp
23+
SOURCES += ../imgui-knobs.cpp
24+
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
25+
UNAME_S := $(shell uname -s)
26+
27+
CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I../ -I$(IMGUI_DIR)/backends
28+
CXXFLAGS += -g -Wall -Wformat
29+
CXXFLAGS += -O1 -Wl,-s -MMD -MP
30+
LIBS =
31+
32+
##---------------------------------------------------------------------
33+
## BUILD FLAGS PER PLATFORM
34+
##---------------------------------------------------------------------
35+
36+
ifeq ($(UNAME_S), Linux) #LINUX
37+
ECHO_MESSAGE = "Linux"
38+
LIBS += -lGL -ldl `sdl2-config --libs`
39+
40+
CXXFLAGS += `sdl2-config --cflags`
41+
CFLAGS = $(CXXFLAGS)
42+
endif
43+
44+
ifeq ($(UNAME_S), Darwin) #APPLE
45+
ECHO_MESSAGE = "Mac OS X"
46+
LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs`
47+
LIBS += -L/usr/local/lib -L/opt/local/lib
48+
49+
CXXFLAGS += `sdl2-config --cflags`
50+
CXXFLAGS += -I/usr/local/include -I/opt/local/include
51+
CFLAGS = $(CXXFLAGS)
52+
endif
53+
54+
ifeq ($(OS), Windows_NT)
55+
ECHO_MESSAGE = "MinGW"
56+
LIBS += -lgdi32 -lopengl32 -limm32 $(shell pkg-config --static --libs sdl2)
57+
58+
CXXFLAGS += $(shell pkg-config --cflags sdl2)
59+
CFLAGS = $(CXXFLAGS)
60+
endif
61+
62+
##---------------------------------------------------------------------
63+
## BUILD RULES
64+
##---------------------------------------------------------------------
65+
66+
%.o:../%.cpp
67+
$(CXX) $(CXXFLAGS) -c -o $@ $<
68+
69+
%.o:%.cpp
70+
$(CXX) $(CXXFLAGS) -c -o $@ $<
71+
72+
%.o:$(IMGUI_DIR)/%.cpp
73+
$(CXX) $(CXXFLAGS) -c -o $@ $<
74+
75+
all: $(EXE)
76+
@echo Build complete for $(ECHO_MESSAGE)
77+
78+
$(EXE): $(OBJS)
79+
$(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)
80+
81+
clean:
82+
@-rm -f $(EXE) $(OBJS)
83+
@-rm *.d
84+
85+
86+
include $(wildcard *.d)

0 commit comments

Comments
 (0)