Skip to content
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

Changing a tab's label while using ImGuiTabBarFlags_Reorderable, auto-reorders the tab as last. #5393

Closed
immortalx74 opened this issue Jun 13, 2022 · 1 comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack tabs tab bars, tabs

Comments

@immortalx74
Copy link

Version: 1.87
Branch: docking

Back-end: imgui_impl_sdl, imgui_impl_sdlrenderer
Compiler: MSVC
Operating System: Windows 11

My Issue/Question:
Using ImGuiTabBarFlags_Reorderable and changing an existing tab's label, causes said tab to be reordered as last.
This is demonstrated in the minimal example bellow. If you remove the flag, the tab's label can be changed without it automatically getting reordered.

The comment in imgui.h does mention this: "+ New tabs are appended at the end of list", so I guess when using the flag, ImGui considers this is a new tab, since it's label has changed?
How could I have manually-reorderable tabs and still be able to change their labels, while keeping the order untouched if there was no user interaction?

static std::string first_tab_label = "first tab";
static std::string second_tab_label = "second tab";

ImGui::Begin( "MyWindow" );
if ( ImGui::Button( "change first tab's label" ) )
{
	first_tab_label = "first tab just changed";
}
if ( ImGui::BeginTabBar( "MyTabBar", ImGuiTabBarFlags_Reorderable ) )
{
	if ( ImGui::BeginTabItem( first_tab_label.c_str() ) )
	{
		ImGui::EndTabItem();
	}
	if ( ImGui::BeginTabItem( second_tab_label.c_str() ) )
	{
		ImGui::EndTabItem();
	}
	ImGui::EndTabBar();
}
ImGui::End();
@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Jun 13, 2022
@ocornut
Copy link
Owner

ocornut commented Jun 13, 2022

This is answered in the FAQ:
https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-about-the-id-stack-system

If you change the tab label by default it change the ID as well, from dear imgui point of view it is a new tab.
Use ### operator to change label while preserving same ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack tabs tab bars, tabs
Projects
None yet
Development

No branches or pull requests

2 participants