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

The buttons inside the table do not work #7421

Closed
Kolhun opened this issue Mar 19, 2024 · 2 comments
Closed

The buttons inside the table do not work #7421

Kolhun opened this issue Mar 19, 2024 · 2 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@Kolhun
Copy link

Kolhun commented Mar 19, 2024

Version/Branch of Dear ImGui:

Version 1.90.4

Back-ends:

imgui_impl_demo.cpp

Compiler, OS:

Windows 10 + DirectX11

Full config/build information:

No response

Details:

Hello dear ImGui! An incomprehensible question arose regarding the fact that ImageButton in the cells of my table do not work except for the very first ImageButton button. Even a simple printf debug does not output anything, what is my mistake?

Screenshots/Video:

image

Minimal, Complete and Verifiable Example code:

if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
            {
            
                if (ImGui::BeginTabItem("1C###1Csssss"))
                {
                    if (ImGui::BeginTable("sd###table1fsd2", 3, flags))
                    {
                        ImGui::TableSetupColumn("Ключ", ImGuiTableColumnFlags_WidthFixed, 0);
                        ImGui::TableSetupColumn("Значение", ImGuiTableColumnFlags_WidthFixed, 1);
                        ImGui::TableSetupColumn("Описание", ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthStretch, 2);
                        ImGui::TableSetupScrollFreeze(0, 1);
                        ImGui::TableHeadersRow();

                        static int selected = -1;


                    
                        for (int row = 0; row < 12; row++)//for(auto& row = data.begin(); row != data.end(); ++row)//for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++)//for (auto row = data.begin(); row != data.end(); ++row)
                            {
                                ImGui::TableNextColumn();
                                const char* returnItems;
                                switch (row)
                                {
                                case 0:
                                    ImGui::Text("avito_status");
                                    ImGui::TableNextColumn();
                                    ImGui::Text("Статус");
                                    ImGui::TableNextColumn();

                                    if (strcmp(dataBegin->AvitoStatus, "0") == 0)
                                    {
                                        ImGui::TextWrapped("Новый");
                                    }
                                    else {
                                        ImGui::TextWrapped("Учтён");
                                    }

                                    ImGui::SameLine();
                                    if (ImGui::SmallButton("Новый"))
                                    {
                                        dataBegin->AvitoStatus = "0";
                                        DataUploadInTable(dataBegin, dataTableWorkBuffer, items_TableWorkBuffer);
                                    }
                                    ImGui::SameLine();
                                    if (ImGui::SmallButton("Учтён"))
                                    {
                                        dataBegin->AvitoStatus = "1";
                                        DataUploadInTable(dataBegin, dataTableWorkBuffer, items_TableWorkBuffer);
                                    }
                                    ImGui::SameLine();
                                    if (ImGui::SmallButton("Без фото"))
                                    {
                                        dataBegin->AvitoStatus = "2";
                                        DataUploadInTable(dataBegin, dataTableWorkBuffer, items_TableWorkBuffer);
                                    }
                                    ImGui::SameLine();
                                    if (ImGui::SmallButton("Прочее"))
                                    {
                                        dataBegin->AvitoStatus = "3";
                                        DataUploadInTable(dataBegin, dataTableWorkBuffer, items_TableWorkBuffer);
                                    }

                                    ;break;
                                case 1:
                                    ImGui::Text("id");
                                    ImGui::TableNextColumn();
                                    ImGui::Text("ID");
                                    ImGui::TableNextColumn();
                                    ImGui::AlignTextToFramePadding();

                                    if (ImGui::ImageButton((void*)texImageCopy, ImVec2(16, 16)))
                                    {
                                        ImGui::SetClipboardText(dataBegin->ID);
                                    }
                                    ImGui::SameLine();

                                    ImGui::TextWrapped(dataBegin->ID);
                                    ;break;
                                case 2:
                                    ImGui::Text("uid");
                                    ImGui::TableNextColumn();
                                    ImGui::Text("UID");
                                    ImGui::TableNextColumn();
                                    ImGui::AlignTextToFramePadding();

                                    if (ImGui::ImageButton((void*)texImageCopy, ImVec2(16, 16)))
                                    {
                                        ImGui::SetClipboardText(dataBegin->UID);
                                    }
                                    ImGui::SameLine();

                                    ImGui::TextWrapped(dataBegin->UID);
                                    ;break;
                                case 3:
                                    ImGui::Text("category");
                                    ImGui::TableNextColumn();
                                    ImGui::Text("Категория");
                                    ImGui::TableNextColumn();
                                    ImGui::AlignTextToFramePadding();
                                    if (ImGui::ImageButton((void*)texImageCopy, ImVec2(16, 16)))
                                    {
                                        printf("\n ;)");
                                        ImGui::SetClipboardText(dataBegin->Category);
                                    }
                                    ImGui::SameLine();
                                    ImGui::TextWrapped(dataBegin->Category);
                                    ImGui::SameLine();

                                    ImGui::AlignTextToFramePadding();
                                    if (ImGui::ImageButton((void*)texImageCopy, ImVec2(16, 16)))
                                    {
                                        ImGui::SetClipboardText(dataBeginCategory->Name);
                                    }
                                    ImGui::SameLine();
                                    ImGui::TextWrapped(dataBeginCategory->Name);

                                    ;break;
//////////
@PathogenDavid
Copy link
Contributor

The IDs between your buttons are conflicting, see this FAQ entry for details.

Additionally you're using an overload of ImGui::ImageButton which is deprecated (partially to help avoid this mistake.) You should use the version which takes an ID instead, and consider defining IMGUI_DISABLE_OBSOLETE_FUNCTIONS to disable deprecated overloads entirely.

@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Mar 19, 2024
@ocornut
Copy link
Owner

ocornut commented Mar 19, 2024

Most typically you would surround each row with PushID(row)/PopID(), as outlined in the linked FAQ entry.
Closing this as answered.

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
Projects
None yet
Development

No branches or pull requests

3 participants