-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for some reason when i try to change the color of my text and try to do pop style color it crashed? #7597
Comments
if (page == 4) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(127, 0, 255, 255)); }
if (ImGui::Button("\n " ICON_FA_COG " \n", ImVec2(50, 50))) { page = 4; }
if (page == 4) { ImGui::PopStyleColor(); } Look carefully at the code and you will understand your mistake: when the You could do: int next_page = page;
if (page == 1) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(127, 0, 255, 255)); }
if (ImGui::Button("\n " ICON_FA_CROSSHAIRS " \n", ImVec2(50, 50))) { next_page = 1; }
if (page == 1) { ImGui::PopStyleColor(); }
ImGui::SetCursorPosX(50);
if (page == 2) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(127, 0, 255, 255)); }
if (ImGui::Button("\n " ICON_FA_EYE " \n", ImVec2(50, 50))) { next_page = 2; }
if (page == 2) { ImGui::PopStyleColor(); }
ImGui::SetCursorPosX(50);
if (page == 3) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(127, 0, 255, 255)); }
if (ImGui::Button("\n " ICON_FA_CLOUD " \n", ImVec2(50, 50))) { next_page = 3; }
if (page == 3) { ImGui::PopStyleColor(); }
ImGui::SetCursorPosX(50);
if (page == 4) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(127, 0, 255, 255)); }
if (ImGui::Button("\n " ICON_FA_COG " \n", ImVec2(50, 50))) { next_page= 4; }
if (page == 4) { ImGui::PopStyleColor(); }
page = next_page; Or: if (page == 1) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(127, 0, 255, 255)); }
if (ImGui::Button("\n " ICON_FA_CROSSHAIRS " \n", ImVec2(50, 50))) { next_page = 1; }
if (page == 1) { ImGui::PopStyleColor(); }
ImGui::SetCursorPosX(50);
if (page == 2) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(127, 0, 255, 255)); }
if (ImGui::Button("\n " ICON_FA_EYE " \n", ImVec2(50, 50))) { next_page = 2; }
if (page == 2) { ImGui::PopStyleColor(); }
ImGui::SetCursorPosX(50);
if (page == 3) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(127, 0, 255, 255)); }
if (ImGui::Button("\n " ICON_FA_CLOUD " \n", ImVec2(50, 50))) { next_page = 3; }
if (page == 3) { ImGui::PopStyleColor(); }
ImGui::SetCursorPosX(50);
if (page == 4) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(127, 0, 255, 255)); }
if (ImGui::Button("\n " ICON_FA_COG " \n", ImVec2(50, 50))) { next_page= 4; }
if (page == 4) { ImGui::PopStyleColor(); } You might also want to create yourself a helper function: // in your own header+source file
bool ImGui::ButtonColored(const ImVec4& col, const char* label)
{
PushStyleColor(ImGuiCol_Text, col);
bool ret = Button(label);
PopStyleColor();
return ret;
} And use it: ImGui::Indent(50.0f);
ImVec4 base_color = style.Colors[ImGuiCol_Text];
ImVec4 selected_color = ImVec4(127, 0, 255, 255);
ImVec2 button_sz(50,50);
if (ImGui::ButtonColored(page == 1 ? selected_color : base_color, "\n " ICON_FA_CROSSHAIRS " \n", button_sz)) { page = 1; }
if (ImGui::ButtonColored(page == 2 ? selected_color : base_color, "\n " ICON_FA_EYE " \n", button_sz)) { page = 2; }
[....]
ImGui::Unindent(50.0f); |
bro thank u so much lol im new to this |
it fixed it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version/Branch of Dear ImGui:
Version 1.XX, Branch: XXX (master/docking/etc.)
Back-ends:
imgui_impl_XXX.cpp + imgui_impl_XXX.cpp
Compiler, OS:
Windows 11, Visual Studio
Full config/build information:
No response
Details:
i tried everything nothings working
Screenshots/Video:
Recording.2024-05-17.113319.mp4
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: