The imgui_toggle library, adds toggle widgets to dear imgui, like these:
Enabling the module
To enable the toggles module, you hardcode the USE_TOGGLES_MODULE
option in your CMakeLists.txt
file by finding the following line:
option(USE_TOGGLES_MODULE "Use the toggles module" OFF)
and modifying the line to look like this:
option(USE_TOGGLES_MODULE "Use the toggles module" ON)
Alternatively, you can also generate through the CMake CLI:
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DUSE_TOGGLES_MODULE=ON
Finally, update your uvproj.yaml
so that the toggles
key under enabled-modules
is set to true like this:
name: "MyProject"
version: "1.0.0.0"
engine-version: "1.0.0.0"
enabled-modules:
toggles: true
Next, in your source file, include the Modules.hpp
header:
#include <Modules/Modules.hpp>
Event safety
The entire module is flagged as event safe at All ready
.
Testing out the module
In one of your widgets, add the following code to your tick function:
const ImVec4 green(0.16f, 0.66f, 0.45f, 1.0f);
const ImVec4 green_hover(0.0f, 1.0f, 0.57f, 1.0f);
const ImVec4 gray_dim(0.45f, 0.45f, 0.45f, 1.0f);
const ImVec4 gray(0.65f, 0.65f, 0.65f, 1.0f);
// use some lovely gray backgrounds for "off" toggles
// the default will use your theme's frame background colors.
ImGui::PushStyleColor(ImGuiCol_FrameBg, gray_dim);
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, gray);
static bool values[] = { true, true, true, true, true, true, true, true };
size_t value_index = 0;
const ImVec4 salmon(1.0f, 0.43f, 0.35f, 1.0f);
const ImVec4 green_shadow(0.0f, 1.0f, 0.0f, 0.4f);
// a default and default animated toggle
"Default Toggle", &values[value_index++]);
ImGui::Toggle("Animated Toggle", &values[value_index++], ImGuiToggleFlags_Animated);
ImGui::Toggle(
// this toggle draws a simple border around it's frame and knob
"Bordered Knob", &values[value_index++], ImGuiToggleFlags_Bordered, 1.0f);
ImGui::Toggle(
// this toggle draws a simple shadow around it's frame and knob
ImGui::PushStyleColor(ImGuiCol_BorderShadow, green_shadow);"Shadowed Knob", &values[value_index++], ImGuiToggleFlags_Shadowed, 1.0f);
ImGui::Toggle(
// this toggle draws the shadow & and the surrounding border's frame and knob.
"Bordered + Shadowed Knob", &values[value_index++], ImGuiToggleFlags_Bordered | ImGuiToggleFlags_Shadowed, 1.0f);
ImGui::Toggle(1);
ImGui::PopStyleColor(
// this toggle uses stack-pushed style colors to change the way it displays
ImGui::PushStyleColor(ImGuiCol_Button, green);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, green_hover);"Green Toggle", &values[value_index++]);
ImGui::Toggle(2);
ImGui::PopStyleColor(
"Toggle with A11y Labels", &values[value_index++], ImGuiToggleFlags_A11y);
ImGui::Toggle(
// this toggle shows no label
"##Toggle With Hidden Label", &values[value_index++]);
ImGui::Toggle(
// pop the FrameBg/FrameBgHover color styles
2); ImGui::PopStyleColor(
after compiling and running, the result should look like this:
Learning the module
To learn more about this third party library, check out the imgui_toggle GitHub repository
Checking for the module
To check for the module at compile time, use the UIMGUI_TOGGLES_MODULE_ENABLED
macro.
Runtime checking can be done using the toggles
member of the ModuleSettings
struct. More info can be found here.
- Home
- Beginner content
- Install guide
- Creating and using the UI components
- The Instance
- The Init Info struct
- Additional features
- Custom type definitions
- C API development
- Config files and Folders
- Interfaces
- Internal Event safety
- Modules system
- I18N
- Plotting
- Knobs
- Spinners
- Toggles
- Text Utils
- Undo/Redo
- CLI Parser
- Theming
- OS
- Opening URLs and using file pickers
- Exec integration
- Fonts
- Unix
- DBus utilities
- XDG integration
- Collaborating with others
- Advanced content
- Loading dynamic libraries at runtime
- Understanding the library layout
- Compilation mode modifiers
- Adding plugin support to your application
- Production export and deployment
- Developer and contributor resources
- Misc