Change the Tabs name from the outside #7233

Closed
opened 2024-01-17 09:16:16 +00:00 by Kolhun · 0 comments
Kolhun commented 2024-01-17 09:16:16 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version 1.90

Back-ends:

imgui_impl_demo.cpp

Compiler, OS:

Windows 10 + DirectX 9

Full config/build information:

No response

Details:

Hi, he wants to make it possible to rename the tab name using ImGui::inputText. Can you tell me how this can be done more correctly?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

static ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_FittingPolicyResizeDown;
char tabNameBuffer[20];
std::string tabName;
std::string tabRename = "";

char buf_tableName[100];

if (ImGui::BeginTabBar("MyTabBarTabWork###tabwork", tab_bar_flags))
{

    if (show_trailing_button)
        if (ImGui::TabItemButton("+", ImGuiTabItemFlags_Trailing | ImGuiTabItemFlags_NoTooltip))
            active_tabs.push_back(next_tab_id++); // Add new tab

    // Submit our regular tabs
    for (int n = 0; n < active_tabs.Size; )
    {
        bool open = true;

        
        snprintf(tabNameBuffer, IM_ARRAYSIZE(tabNameBuffer), "%d", active_tabs[n]);
        sprintf(buf_tableName, "Таблица %s", tabNameBuffer);

        if (ImGui::BeginTabItem(buf_tableName, &open, ImGuiTabItemFlags_None))
        {
            ImGui::Text("This is the %s tab!", tabNameBuffer);
            ImGui::EndTabItem();
        }

        if (!open)
            active_tabs.erase(active_tabs.Data + n);
        else
            n++;
            
    }
    ImGui::EndTabBar();
}

char buf_tableRename[100];
strncpy_s(buf_tableRename, buf_tableName, sizeof(buf_tableName) - 1);
ImGui::InputText("Имя", buf_tableRename, sizeof(buf_tableRename));
### Version/Branch of Dear ImGui: Version 1.90 ### Back-ends: imgui_impl_demo.cpp ### Compiler, OS: Windows 10 + DirectX 9 ### Full config/build information: _No response_ ### Details: Hi, he wants to make it possible to rename the tab name using ImGui::inputText. Can you tell me how this can be done more correctly? ### Screenshots/Video: _No response_ ### Minimal, Complete and Verifiable Example code: ```cpp static ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_FittingPolicyResizeDown; char tabNameBuffer[20]; std::string tabName; std::string tabRename = ""; char buf_tableName[100]; if (ImGui::BeginTabBar("MyTabBarTabWork###tabwork", tab_bar_flags)) { if (show_trailing_button) if (ImGui::TabItemButton("+", ImGuiTabItemFlags_Trailing | ImGuiTabItemFlags_NoTooltip)) active_tabs.push_back(next_tab_id++); // Add new tab // Submit our regular tabs for (int n = 0; n < active_tabs.Size; ) { bool open = true; snprintf(tabNameBuffer, IM_ARRAYSIZE(tabNameBuffer), "%d", active_tabs[n]); sprintf(buf_tableName, "Таблица %s", tabNameBuffer); if (ImGui::BeginTabItem(buf_tableName, &open, ImGuiTabItemFlags_None)) { ImGui::Text("This is the %s tab!", tabNameBuffer); ImGui::EndTabItem(); } if (!open) active_tabs.erase(active_tabs.Data + n); else n++; } ImGui::EndTabBar(); } char buf_tableRename[100]; strncpy_s(buf_tableRename, buf_tableName, sizeof(buf_tableName) - 1); ImGui::InputText("Имя", buf_tableRename, sizeof(buf_tableRename)); ```
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#7233
No description provided.