imgui
imgui copied to clipboard
How do I select Reordable Tab?
I have 4 tabs using ImGui::BeginTabItem. I am using ImGuiTabBarFlags_Reorderable flag for ImGui::BeginTabBar.
I want to select the tab next to the currently selected tab, how do I do that?
I know I can select tab by using ImGuiTabItemFlags_SetSelected, but I don't know which tab is NEXT for because I can't get the order of Reorderable tabs.
if (ImGui::Begin("Window"))
{
if (ImGui::BeginTabBar("Tabs", ImGuiTabBarFlags_::ImGuiTabBarFlags_Reorderable))
{
if (ImGui::BeginTabItem("Tab1")){ ImGui::EndTabItem(); }
if (ImGui::BeginTabItem("Tab2")){ ImGui::EndTabItem(); }
if (ImGui::BeginTabItem("Tab3")){ ImGui::EndTabItem(); }
if (ImGui::BeginTabItem("Tab4")){ ImGui::EndTabItem(); }
ImGui::EndTabBar();
}
ImGui::End();
}
This is not supported by the API and seems like an odd request to want to select the tab right of current tab while allowing user re-ordering. Can you explain more of the context?
The ImGUI Window I create is used by many users.
The four tabs (In fact, many more tabs) have different priorities for each user and I want to make Reordable so that it is easy for them to use. I assume they will change the order of the tabs by using the mouse.
Apart from that, I have a request to control ImGUI Window with something other than a mouse (keyboard or gamepad) from them. I try to fulfill this request with my program, but I am stuck with the problem that when change the selection of tabs with the keyboard, I don't know in which order the tabs are arranged, so I don't even know which tab is to the right of the current tab.
You did not answer my question, why would you want to care about the tab on the right if the tabs are reorderable?
I am not grasping the intent of your question.
There are some users who can't write (and read) programs. When they run the above code, the tabs line up in the following order.
Tab1 | Tab2 | Tab3 | Tab4
User1 only uses Tab2 and Tab3, so they are reordered as follows
Tab2 | Tab3 | Tab1 | Tab4
User2 uses only Tab1 and Tab4, so they are reordered as follows
Tab1 | Tab4 | Tab3 | Tab2
The work up to this point is done using the mouse.
As I mentioned earlier, We want to use the keyboard or gamepad to control the GUI for any further operations. When we type the command "move to next tab" on the keyboard, We want to select tabs in the order we see them visually. No one knows the order of the tabs for User1 and User2 except ImGui. Even if I know that the current tab is Tab1 , I can't know whether Tab2, Tab3, or Tab4 is next to Tab1.
Is it possible to control ImGui with keyboard if I just don't know about it?
My question was asking why one would want “go to next tab” in the place. We can’t answer questions without understanding intent. If you dig in internals you’ll easily find tab order data (its also exposed in Debugger/Metrics where you can see how to access it).
Keyboard/Gamepad Navigation config flags allows controls of dear imgui.
@isringo See this FAQ entry for details on keyboard/gamepad navigation.
Thank you. I'll look it.
Sorry for my late answer. And I forgot to acknowledge that last "long message" gave me the information I wanted to understand your use case. I have pushed a bunch of low-level/internal helpers in 3d8885c which should now make it possible to do that work with a sensibly more stable and documented API.
"Move to next tab" therefore should be something along the line of:
ImGuiTabBar* tab_bar = GetCurrentTabBar();
int current_order = TabBarFindTabByOrder(tab_bar, TabBarGetCurrentTab(tab_bar));
if (ImGuiTabItem* next_tab = TabBarFindTabByOrder(tab_bar, current_order + 1))
TabBarQueueFocus(tab_bar, next_tab);