How to make theme changer in your menu using ImGui.

xLamantine

Newbie
Newbie
Newbie
Newbie
Status
Offline
Joined
Mar 16, 2021
Messages
8
Reaction score
2
Hello everyone. Today I will tell you how to create a selection of themes for your menu based on ImGui. To create this, you need to create a combo element and variables with an array to it:
const char* themes[]{ "Dark Purple", "Dark Blue" }; static int curTheme; ImGui::Combo(xorstr("Menu Theme"), &curTheme, themes, ARRAYSIZE(themes));
Next, you need to create a code that detects what is selected in the combo element and installs the desired theme.
if (curTheme == 0) { colors[ImGuiCol_WindowBg] = ImVec4(0.39f, 0.00f, 0.63f, 0.11f); } else if (curTheme == 1) { colors[ImGuiCol_WindowBg] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f); }
Why do we use else if? Because this code will not work with a simple if or simple else. The value of the curTheme variable will be equal to the selected item in the combo. If we specified "Dark Purple" as the first in the array, and right after it "Dark Blue", then the first value of curTheme will be 0, that is, Dark Purple, and 1 will be equal to Dark Blue, because this is how the C ++ basics work, because in this programming language, the counting in the array starts from 0.

You can add an infinite number of your own themes and styles. Why don't we use PushStyleColor, you ask? Because the first value that your code will accept will have to have PopStyleColor, otherwise the code will not work, but at the same time, because of this, settings of other styles are released and not accepted. If I helped you, I will be glad. Good luck!
SS:
1615910435100.png
1615910445988.png
 
Top