ImGui Auto Generator for openFrameworks
README
ofxImGuiAuto

ImGui::Begin("Test");
IMGUI_AUTOS2(
size, 1.0f, 10.0f, 1000.0f, "%.0f",
angle, 0.1f,
color,
color_on,
ENUM_(choise)
);
IMGUI_AUTO_SAVE_LOAD(save(), load());
ImGui::End();(see example for detail above.)
This addon provides macros named
IMGUI_AUTO, IMGUI_AUTOS, IMGUI_AUTOS2, IMGUI_AUTO_SAVE_LOAD that automatically generate ImGui DragXXX controls and Save/Load buttons.C++17 or higher is required.
Tested on oF v0.12.0 (win/mac)
Dependencies
Features
- Automatically generates ImGui (Drag) controls for:
floatintofVec2fofVec3fofRectangleofColor(ColorEdit4)bool(Checkbox)enum(Combo)
Example
using IMGUI_AUTOS / IMGUI_AUTO
class MyApp : public ofBaseApp {
public:
ofVec2f position;
ofVec2f size;
float scale;
ofVec2f offset;
ofVec2f baseSize;
float speed;
float fadeIn;
float duration;
float fadeOut;
bool enabled;
void setup() {
position = ofVec2f(0, 0);
size = ofVec2f(100, 70);
scale = 1.0f;
offset = ofVec2f(10, 10);
baseSize = ofVec2f(50, 50);
speed = 1.0f;
fadeIn = 0.5f;
duration = 1.0f;
fadeOut = 0.5f;
enabled = true;
load();
}
void save(){
// something to save
}
void load(){
// something to load
}
void drawGui() {
ImGui::Begin("My Controls");
IMGUI_AUTOS(
position,
size,
scale,
offset,
baseSize,
enabled
);
IMGUI_AUTO(speed, 0.1f);
IMGUI_AUTO(fadeIn, 0.1f);
IMGUI_AUTO(duration, 0.1f);
IMGUI_AUTO(fadeOut, 0.1f);
IMGUI_AUTO_SAVE_LOAD(save(), load(), "save", "load");
// or short-hand:
// IMGUI_AUTO_SAVE_LOAD(save(), load());
ImGui::End();
}
};using IMGUI_AUTOS2 (smarter)
void drawGui() {
ImGui::Begin("My Controls");
IMGUI_AUTOS2(
position,
size,
scale,
offset,
baseSize,
enabled,
speed, 0.1f,
fadeIn, 0.1f,
duration, 0.1f,
fadeOut, 0.1f
);
IMGUI_AUTO_SAVE_LOAD(save(), load(), "save", "load");
// or short-hand:
// IMGUI_AUTO_SAVE_LOAD(save(), load());
ImGui::End();
}IMGUI_AUTOS2 Limitations
- In order to use enum in
IMGUI_AUTOS2,ENUM_(enum)is needed. - There is runtime overhead.
| IMGUI_AUTOS | IMGUI_AUTOS2 | |
|---|---|---|
| enum | :white_check_mark: | :white_check_mark: (use ENUM_()) |
| parameters | :x: (use IMGUI_AUTO) | :white_check_mark: [^1] |
| args limit | 14 | - (infinite) |
| runtime overhead | none | low |
IMGUI_AUTO or IMGUI_AUTOS instead.[!WARNING]
If you have GUI flickering when usingIMGUI_AUTO2()on your app, please read below.
[!NOTE]
IMGUI_AUTO2()macro string is parsed on first call in run-time, and cached statically. This may make GUI flickering in some special case.
If you won't cache it,
- useIMGUI_AUTOS2_NO_CACHE()(short-hand:IMGUI_AUTOS2_NC()) macro instaed
- or#define IMGUI_AUTO_NO_CACHEbefore#include "ofxImGuiAuto.h".
for save/load
You can use any serializations as you like.
I recommend ofxJsonUtils and ofxJsonUtilsUtils.
ofxJsonUtilsUtils's
JSON_FUNCS syntax will fit well IMGUI_AUTOS or IMGUI_AUTOS2.JSON_FUNCS(name, age, life, score);[!NOTE]
If you need deep integration with JSON, consider ofxImGuiJson as an alternative.
License
0BSD
(Please note that magic_enum is MIT License.)
ofxAddons