The imgui_toggle library, adds toggle widgets to dear imgui, like these:
Enabling the module
To enable the toggles module, 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
Then, regenerate the modules cache by running the following command:
user $ https://madladsquad.com/UVKBuildTool --generate <project directory>
After that, refresh your CMake project with
cmake ..
!
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 colours.
::PushStyleColor(ImGuiCol_FrameBg, gray_dim);
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, gray);
ImGui
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
::Toggle("Default Toggle", &values[value_index++]);
ImGui::Toggle("Animated Toggle", &values[value_index++], ImGuiToggleFlags_Animated);
ImGui
// this toggle draws a simple border around it's frame and knob
::Toggle("Bordered Knob", &values[value_index++], ImGuiToggleFlags_Bordered, 1.0f);
ImGui
// this toggle draws a simple shadow around it's frame and knob
::PushStyleColor(ImGuiCol_BorderShadow, green_shadow);
ImGui::Toggle("Shadowed Knob", &values[value_index++], ImGuiToggleFlags_Shadowed, 1.0f);
ImGui
// this toggle draws the shadow & and the surrounding border's frame and knob.
::Toggle("Bordered + Shadowed Knob", &values[value_index++], ImGuiToggleFlags_Bordered | ImGuiToggleFlags_Shadowed, 1.0f);
ImGui::PopStyleColor(1);
ImGui
// this toggle uses stack-pushed style colours to change the way it displays
::PushStyleColor(ImGuiCol_Button, green);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, green_hover);
ImGui::Toggle("Green Toggle", &values[value_index++]);
ImGui::PopStyleColor(2);
ImGui
::Toggle("Toggle with A11y Labels", &values[value_index++], ImGuiToggleFlags_A11y);
ImGui
// this toggle shows no label
::Toggle("##Toggle With Hidden Label", &values[value_index++]);
ImGui
// pop the FrameBg/FrameBgHover colour styles
::PopStyleColor(2); ImGui
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.
C API
We provide a C API for the toggles module as part of the cimgui_extra
project. To use it, simply include
#include <cimgui_extra/cimgui_toggles.h>
.
- Home
- Beginner content
- Install guide
- Creating and using the UI components
- The Instance
- The Init Info struct
- Textures
- Logging
- Unicode support
- Additional features
- Client-side bar
- Custom type definitions
- Memory management
- C API development
- Config files and Folders
- Interfaces
- Internal Event safety
- Customising the build system
- Modules system
- Collaborating with others
- Advanced content
- Developer and contributor resources
- Misc