-
-
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
How to correctly use IDs ? #719
Comments
Have you read the FAQ? |
In the faq in imgui.cpp quite literally says what you should do: for (int i = 0; i < 100; i++)
{
PushID(i);
//...
PopID();
} |
Obviously yes. Like I said, I tried all the possible combinations. For instance : ImGui::SetNextWindowPosCenter();
ImGui::SetNextWindowSize(ImVec2(350, 200));
ImGui::Begin("YAPG - Main menu");
//Level selection
static char levelName[512] = "level.xml";
ImGui::InputText("", levelName, 512);
ImGui::SameLine();
if(ImGui::Button("Play !"))
{
getStateEngine().pauseAndStartState
<level::LevelState, std::string, resources::AllResourcesManagers&, settings::SettingsManager&, sfg::SFGUI&, sfg::Desktop&>(
std::string(levelName), m_resourcesManager, m_settingsManager, m_sfgui, m_desktop
);
}
//Level editor
if(ImGui::Button("Level editor"))
{
getStateEngine().pauseAndStartState
<editor::LevelEditorState, resources::AllResourcesManagers&, settings::SettingsManager&, sfg::SFGUI&, sfg::Desktop&>(
m_resourcesManager, m_settingsManager, m_sfgui, m_desktop
);
}
//Settings
if(ImGui::Button("Settings..."))
{
ImGui::OpenPopup("Settings");
}
//Settings popup
ImGui::SetNextWindowSize(ImVec2(350, 400));
if(ImGui::BeginPopupModal("Settings"))
{
ImGui::PushID("keyboard_settings"); //Just to be sure !
if(ImGui::CollapsingHeader("Keyboard settings"))
{
ImGui::Indent();
for(std::size_t i = 0; i < 4; ++i)
{
std::string label = "Player " + std::to_string(i + 1);
ImGui::PushID(i);
if(ImGui::CollapsingHeader(label.data()))
{
ImGui::Text("Left key: ");
ImGui::SameLine();
if(ImGui::Button(m_playersKeys[i][0]))
{
m_selectedKeyButton = m_playersKeys[i][0];
}
ImGui::Text("Right key: ");
ImGui::SameLine();
if(ImGui::Button(m_playersKeys[i][1]))
{
m_selectedKeyButton = m_playersKeys[i][1];
}
ImGui::Text("Jump key: ");
ImGui::SameLine();
if(ImGui::Button(m_playersKeys[i][2]))
{
m_selectedKeyButton = m_playersKeys[i][2];
}
}
ImGui::PopID();
}
ImGui::Unindent();
}
if(ImGui::Button("Close"))
{
ImGui::CloseCurrentPopup();
}
ImGui::PopID();
ImGui::EndPopup();
}
//About
if(ImGui::Button("About..."))
{
}
//Quit button
if(ImGui::Button("Exit"))
{
getStateEngine().stopStateAndUnpause();
}
ImGui::End(); Still give random bad click actions. :( |
This should work, I can't see why it wouldn't. You are perhaps doing something else wrong in the code. (Never tell yourself "I tried all the possible combinations." it is most often a wrong statement.) |
Ok, at least I use them correctly :). I'll take another look at my code. ;) (Great lib by the way 👍 ) |
Maybe you are handling |
Do you change the contents of
|
Good point (and hence why posting a screenshot of the context is always helpful). Typically your code could you loop over an array of keys to set,
|
Thanks for your help, it works now :) |
Line 637 in 9d6b2b0
|
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!
Hi,
Here is my code :
As you can see, I have a "for" loop, so I probably need to use PushID and PopID. However, I don't know where to put them. I tried all the possible combinations but it always resulted in buttons randomly acting like others (for exemple : the jump key button of the third player launch the level editor as the "Editor" button only should do !).
So, how do the IDs work ?
The text was updated successfully, but these errors were encountered: