A small demo exploring automatically building editor widgets for structs. Objects are introspected using pupene, while imgui provides the underlying UI.
A struct:
struct complex_thing {
vec22fi v22fi;
vec2f xy;
float decimal;
int32_t integer;
uint8_t byte;
Color color;
std::string hallo = "hi there";
};
Called every frame:
ui::widget::object_editor(object, config);
pupene requires that a pup()
function is provided for
each serializable type. These functions work with all puppers. As
such, for any type for which a UI can be constructed, binary and json
serialization is available too.
Simplified usage:
// object to edit
auto ct = complex_thing{};
// the config object holds state for the current editor
auto config = EditorConfig{"object"};
config.filter.pattern.reserve(50); // rough edges
while (!poll_events(key_callback)) {
render_frame(window, [&ct, &config]() {
// called each frame
ui::widget::object_editor(ct, config);
});
}
pup-fns.h contains all necessary pup()
functions and types.
This has only been tested on Kubuntu 17.10, using clang-5.0 and gcc 7.2. It should/might work elsewhere too.
Requirements:
- Recent compiler with C++17 support
- CMake 3.8+
- Python and conan (
pip install conan
)
Add this conan remote for imgui and pupene dependencies:
conan remote add junkdog https://api.bintray.com/conan/junkdog/conan
This step also builds the dependencies and installs them into the local conan cache.
cmake -H. -B_builds \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=_install
cmake --build _builds --target install -- -j 8
Unless running the executable from a folder containingSourceCodePro-Semibold.ttf
,
the default imgui font will be used.
cd _install/bin
./example