-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Getting index of the TabItem #5997
Comments
Also see #5853 |
It's for my small VFX editor, where each tab is VFX object (and its properties), so for my usage, it's more convenient to move the order of objects (which matters) using the ImGuiTabBarFlags_Reorderable. I understand it's probably not made for those use cases, but for me, it's good enough atm. Anyway if you have any tips, they're more than welcome. |
I don’t understand your explanation but I am interested to understand this better. Could you clarify? |
Well, I'll give a different example of a use-case. When you have in Chrome opened multiple tabs, you can right-click one of the tabs and click Here is how it could be handled using the GetTabItemIndex function. static std::vector<tab> tabs;
static std::vector<int> index_mapping;
ImGui::BeginTabBar("Tabs", ImGuiTabBarFlags_Reorderable)
for (int tab_index = 0; tab_index < tabs.size(); tab_index++)
{
if (ImGui::BeginTabItem(tabs[tab_index].id))
{
if (ImGui::Button("Remove tabs on right"))
{
for (usize index = 0; index < tabs.size(); index++)
{
if (index_mapping[index] > index_mapping[tab_index])
{
/* schedule to be removed */
}
}
}
ImGui::EndTabItem();
}
index_mapping[tab_index] = ImGui::GetTabItemIndex();
}
ImGui::EndTabBar(); |
Sorry for my late answer, I have now pushed 3d8885c with a handful of internal/low-level helpers to facilitate this. It may little more mouthful as I didn't want to add extraneous/unnecessary helpers, but something like this should work: ImGuiTabBar* tab_bar = GetCurrentTabBar();
int tab_order = TabBarGetTabOrder(tab_bar, TabBarGetCurrentTab(tab_bar));
for (int n = tab_order + 1; n < tab_bar.Tabs.Size; n++)
if (ImGuiTabItem* tab = TabBarFindTabByOrder(tab_bar, n))
TabBarCloseTab(tab_bar, tab); |
Hey, is there any way how could I get the current index of element in BeginTabBar/EndTabBar while having enabled ImGuiTabBarFlags_Reorderable? Was browsing the demo, but sadly didn't find anything related to that. Thanks for any answers.
Edit:
After some checking of the implementation of the TabItems, I found out I can write something like this and so far looks like it does what I was looking for. Gonna leave it here in case someone else will need it.
The text was updated successfully, but these errors were encountered: