I am trying to keep track of which ImGui tab is selected. Whenever the screens tab is selected, it retrieves the data from SQLite. The problem is, there's like 6 tabs, and keeping track of all those bools would be cumbersome. Is there a different method that's better?
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame();
ImGui::Begin("Debug");
static bool screens_tab_was_selected = false;
static vector<screen> vs;
if (ImGui::BeginTabBar("##tabbar"), ImGuiTabBarFlags_::ImGuiTabBarFlags_NoTooltip)
{
ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_None;
if (ImGui::BeginTabBar("MyTabBar", tab_bar_flags))
{
if (ImGui::BeginTabItem("Screens"))
{
if (screens_tab_was_selected == false)
{
vs = retrieve_screens("test.db");
screens_tab_was_selected = true;
cout << "retrieving screens" << endl;
}
vector<char*> vcharp(vs.size(), NULL);
for (size_t i = 0; i < vs.size(); i++)
vcharp[i] = const_cast<char*>(vs[i].nickname.c_str());
static int selected = 0;
if (ImGui::Combo("My Combo", &selected, &vcharp[0], vcharp.size()))
{
//MessageBoxA(NULL, vcharp[selected], "", MB_OK);
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Characters"))
{
screens_tab_was_selected = false;
ImGui::Text("Characters tab");
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Portal Pairs"))
{
screens_tab_was_selected = false;
ImGui::Text("Portal pairs tab");
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Cinematics"))
{
screens_tab_was_selected = false;
ImGui::Text("Cinematics");
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Global booleans"))
{
screens_tab_was_selected = false;
ImGui::Text("Global booleans");
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}
ImGui::End();
// ImGui::ShowDemoWindow();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());