You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My Issue/Question: If multiple InputText's are created via loop, whenever I select one when running my app, it deselects it.
I've been creating a game engine in Vulkan, and the UI with imgui, but as I started to make my entity inspector, it seems when I create input text via looping, whenever I select an input, it deselects it, and if I select the input that was the last one created, it selects all of them and i can edit the text in all of the inputs.
Here's the code of what I have:
for (int i = 0; i < storage.sel_gameEntities.size(); i++) {
std::string s = std::to_string(storage.sel_gameEntities[i][0]->getId());
if (ImGui::CollapsingHeader(std::string(std::string(storage.sel_gameEntities[i][0]->name) + "###" + s).c_str(), ImGuiTreeNodeFlags_None))
{
ImGui::InputText("Name", storage.sel_gameEntities[i][0]->buf_name, 64);
storage.sel_gameEntities[i][0]->name = storage.sel_gameEntities[i][0]->buf_name;
}
}
The text was updated successfully, but these errors were encountered:
You can skip the string building ID thing by using PushID(i) and PopID() in your loop and also for your CollapsingHeader.
(As a side note you can get rid of ImGuiTreeNodeFlags_None as this is the default for CollapsingHeader.
And you should put storage.sel_gameEntities[i][0] in a variable in your loop, that'll remove a lot of repetition.)
// NOTE: This code is untested but you should get my main idea here.for (int i = 0; i < storage.sel_gameEntities.size(); i++) {
auto* current = storage.sel_gameEntities[i][0];
ImGui::PushID(current->getId()); // This works if getId() returns int/string/char*if (ImGui::CollapsingHeader(current->name)) {
ImGui::PushID(i);
ImGui::InputText("Name", current->buf_name, 64);
ImGui::PopID();
current->name = current->buf_name;
}
ImGui::PopID();
}
Version: 1.83
Branch: docking
My Issue/Question: If multiple InputText's are created via loop, whenever I select one when running my app, it deselects it.
I've been creating a game engine in Vulkan, and the UI with imgui, but as I started to make my entity inspector, it seems when I create input text via looping, whenever I select an input, it deselects it, and if I select the input that was the last one created, it selects all of them and i can edit the text in all of the inputs.
Here's the code of what I have:
The text was updated successfully, but these errors were encountered: