Daandelange / ofxImGui

Please refer to the develop branch in https://github.com/jvcleave/ofxImGui. I'll keep this fork in sync until it's merged in master.
12 stars 1 forks source link

ofxImGui

ofxAddon that allows you to use ImGui in openFrameworks.

Immediate Mode Gui

Unlike most C++ gui libraries, ImGui uses the immediate mode paradigm rather then being OOP (like ofxGui). In other words, every frame you rebuild the whole GUI, executing only the necessary parts, and ImGui is surprisingly fast at that ! This makes the Gui api closer to the OpenGL api as to the inner oF logic (update(), draw(), begin(), end(), push(), pop(), etc.), which makes it very smooth to integrate.
(Note: Internally, ImGui is not "ramming" on the CPU as most immediate-mode GUIs do).

ImGui Widgets

ImGui provides a lot of gui widgets/components and there's a big community with lots extensions to choose from : you will likely find any widget. In its most basic form, you get a panel with a few control widgets that control your variables, like ofxGui; but ImGui also lets you create a full application GUI layout : a menu, multiple panels, tabs and windows that you can dynamically re-arrange within your ofAppWindow or even popped-out of it. The interactions are very smooth and robust.
A community member made this interactive manual for the web browser, where you can see what ImGui looks like and the code to reproduce it.

ImGui API

ImGui's API is also quite nice : with very few code, you obtain a functional basic GUI component bound to your variable. You can then add arguments or extra api calls to fine-tune it (appearance, layout, interactions, feedback, etc). There's also an internal API (imgui_internal.h) which provides access to even more functionality and lets you build your own gui components!

Screenshot


Supported Platforms

ofxImGui should run on the latest openFrameworks release and it's OS/IDE requirements.
These are typically:


Installation

cd /path/to/of/addons && git clone -b develop https://github.com/jvcleave/ofxImGui.git

Optional - Upgrade GLFW

You can configure oF to use GLFW 3.4 and ImGui will have an even more polished interface. See Developers.md.

Keeping ofxImGui up-to-date

To update ofxImGui within your openframeworks installation:

If you need a particular ImGui version, you can stick at the corresponding ofxImGui version, or downgrade it within that latest ofxImGui by grabbing the imgui folder from an older ofxImGui version.


Optional - Configure ofxImGui

Custom project compilation flags

We try to provide the best default settings for each platform, so you should be good to go.
If your project is using a special setup, you might need to manually set some configuration options, which are explained in Configure.md.

If your project is using ofxAddons that support ofxImGui, add the ofxAddons_ENABLE_IMGUI define to your project. More info in Developers.md.

Debug compilation flags

While interfacing your ofApp with ofxImGui, a good practise is to enable OFXIMGUI_DEBUG together with ofSetLogLevel(OF_LOG_VERBOSE), it provides some general warnings on mistakes and logs some important setup steps.


Usage / Code Samples

Setup

ofxImGui implements DearImGui in such a way that each oF window gets its own imgui context, seamlessly shared between any oF window context. You can also load multiple instances of it in the same ofApp (to use the addon within multiple addons). This feature (shared mode) is automatically enabled when a second ofxImGui::Gui instance is created within the same ofApp application's platform window context. See example-sharedContext for more info.
Note: Only the fist call to gui.setup() has full control over the settings (master); the next ones setup as slaves.
Note: Any call to setup() has to be done from a valid ofWindow, ofGetWindowPtr() is used internally to associate the gui context to that exact ofWindow. Therefore, you cannot setup ofxImGui before OpenFrameworks' setup() calls.

Advanced setup : ImGui config flags & ImGui::GetIO()

ofxImGui provides a simple way to interface ImGui, but it's a huge library providing lots of different options to suit your precise needs.
Most of these advanced options are explained in the imgui_demo.cpp source code. Also checkout example-dockingandviewports and example-advanced.
Some options are: Docking, viewports, custom fonts, and other configuration flags.

Draw your GUI

Once the setup is done, there are basically 2 (combinable) ways to use ofxImGui :

Draw a window (optional)

If you don't call any window, ImGui will automatically create a dummy window named "Debug", so it's handy to create them with a name.
You can create as many windows as you want to keep your GUI organised.

Draw Gui Components

In your ofApp::draw(), call ofAppGui.begin(); and ofAppGui.end();. In-between you can submit widgets.

Important: Each interactive imgui widget needs to have a unique ID within the ImGui ID stack. This can be a char* or a void* that has a static memory address that won't move over time.
For example, using std::list is fine: you can use the item as a pointer, but not for std::vector as items can be reallocated on the fly.

Some simple components:

Checkout the imgui demo window to discover all available widgets !

Customise components

There are many ways to change the default widgets, be it by passing extra optional flags or using more API calls. If you're familiar OpenGL API, you won't have a hard time learning the ImGui API.
Again, have a look at the well documented ImGui Demo code to discover more possibilities. Here are some simple examples.

ofxImGuiHelpers

The helpers are a collection of glue samples for integrating OpenFrameworks objects into ImGui. Amongst others, it makes porting ofxGui apps to ofxImGui easier as it implements a compatibility layer for ofParameter.
To use the helpers, you need this : #include "ImHelpers.h".

For more code samples, check out the examples (below).


Examples

There are several example projects, covering from the simplest use case to more advanced ones : Examples.md.


Developer info

Useful developer info and how to get familiar with DearImGui : Developers.md.
Also: information for using ofxImGui within ofxAddons and for ofxImGui developers and contributors.


Community

ImGui extensions

ofxImGui extensions

ofxAddons providing ofxImGui integration

Credits

ofxImGui was initiated in 2015 by @jvcleave. Today, he's maintainging it together with @prisonerjohn and @daandelange, with the help of many contributors.

License