Adding UI elements to control the application
Having values such as the FPS counter of the timers shown in the ImGui window is nice, but ImGui is also capable of sending input to the application. This sending of input enables us to add control elements to the ImGui window and change the values of our running program, without the need to recompile or remember key mappings.
The example code for this last section is in the 04_opengl_ui_control
and 08_vulkan_ui_control
folders.
To see the generic principle of input controls in ImGui, let’s create a simple example: a checkbox that toggles a Boolean value.
Adding a checkbox
Create the checkbox widget in the UserInterface
class by adding these lines to the createFrame()
method of the UserInterface.cpp
file between the ImGui window position text output widget and the ImGui::End()
call:
static bool checkBoxChecked = false;
ImGui::Checkbox("Check Me", &checkBoxChecked);
...