-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Creating checkboxes from a list of values #7472
Comments
@duhnyel This seems to be due to the // Static way, prefered for quick hacking
static bool foo[2] = {false, false};
ImGui::Begin("Hello, world!");
for(int i = 0; i < sizeof(foo); i++){
ImGui::Checkbox("test", &foo[i]);
}
ImGui::End(); // Store-out-the-loop way
bool foo[2] = {false, false};
while(run_main_loop)
{
// ... Inputs handling ...
ImGui::Begin("Hello, world!");
for(int i = 0; i < sizeof(foo); i++){
ImGui::Checkbox("test", &foo[i]);
}
ImGui::End();
// ... Rendering ...
} |
That has seemed solve the problem but only partially. After moving the declaration outside the loop the top checkbox works but any others underneath, don't. I also can't make the list static for the actual implementation in my project. bool foo[4] = {false, false, false, false};
while (run_main_loop){
ImGui::Begin("Hello, world!");
for(int i = 0; i < sizeof(foo); i++){
ImGui::Checkbox("test", &foo[i]);
}
ImGui::End();
} |
@duhnyel Its an issue with same bool foo[4] = {false, false, false, false};
while (run_main_loop)
{
if( ImGui::Begin("Hello, world!") )
{
for(size_t i = 0; i < IM_ARRAYSIZE(foo); i++)
{
ImGui::PushID(&foo[i]);
ImGui::Checkbox("test", &foo[i]);
ImGui::PopID();
}
}
ImGui::End();
} |
Thank you Yurii for your answers. They are both correct answers. Closing this. |
Also #74, #96, #480, #501, #647, #654, #719, #843, #894, #1057, #1173, #1390, #1414, #1556, #1768, #2041, #2116, #2330, #2475, #2562, #2667, #2807, #2885, #3102, #3375, #3526, #3964, #4008, #4070, #4158, #4172, #4199, #4375, #4395, #4471, #4548, #4612, #4631, #4657, #4796, #5210, #5303, #5360, #5393, #5533, #5692, #5707, #5729, #5773, #5787, #5884, #6046, #6093, #6186, #6223, #6364, #6387, #6567, #6692, #6724, #6939, #6984, #7246, #7270, #7375, #7421, #7434, #7472, #7581, #7724, #7926, #7937 and probably more.. Tagging to increase visibility!
Version/Branch of Dear ImGui:
Version 1.90.4 WIP, Branch: master
Back-ends:
imgui_impl_sdl3.cpp + imgui_impl_sdlrenderer3.cpp
Compiler, OS:
Linux + cmake(ninja + gcc)
Full config/build information:
Details:
I'm trying to create checkboxes from an array of values but for some reason it doesn't set the value of the boolean inside the array. The checkbox just stays blank or quickly flashes checked and the value of the boolean doesn't change. What to do?
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: