Skip to content

Auto-scroll not working when a table has a column with buttons #8984

@iFuSiiOnzZ

Description

@iFuSiiOnzZ

Version/Branch of Dear ImGui:

Version 1.94 WIP, Branch: master

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Window 11 + MSVC 19.43.34809, Windows 11 + MingW-Clang 21.1.0

Full config/build information:

No response

Details:

My Issue/Question:

I have a panel that contains some tab bars, inside each tab bar there is a table. The table is populated with information generated over the time. What is notice is that the auto-scroll is not working, ImGui::GetScrollY() has always a constant value (as long as scroll is not manually done), meanwhile ImGui::GetScrollMaxY() is increasing with each new entry on the table, so the condition is never met. I have tried to set the flag ImGuiTabBarFlags_FittingPolicyScroll but no luck. If I remove the button and replace it with text or SmallButton it works ok. If I let the table be populated, and later I open the tab, the table is scrolled to the bottom, but once is opened, even if I switch tab the auto scroll stops working.

Screenshots/Video:

Image

Minimal, Complete and Verifiable Example code:

// Put this somewhere outside the main loop
std::mutex items_mutex;
int items_count = 0;
int items[100] = {};

auto fnc_puh_items = [&]()
{
    while (items_count < 100)
    {
        {
            std::lock_guard<std::mutex> lock(items_mutex);
            items[items_count++] = items_count + 100;
        }
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
};
std::thread(fnc_puh_items).detach();

// Test code for the bug (inside main loop)
constexpr int TABLE_FLAGS = ImGuiTableFlags_Resizable
    | ImGuiTableFlags_HighlightHoveredColumn
    | ImGuiTableFlags_SizingFixedFit
    | ImGuiTableFlags_Reorderable
    | ImGuiTableFlags_Hideable
    | ImGuiTableFlags_ScrollX
    | ImGuiTableFlags_ScrollY
    | ImGuiTableFlags_Borders
    ;
if (ImGui::Begin("Test panel"))
{
    if (ImGui::BeginTabBar("Test Tab Bar", ImGuiTabBarFlags_Reorderable))
    {
        if (ImGui::BeginTabItem("Test Tab Item"))
        {
            if (ImGui::BeginTable("Test Table", 3, TABLE_FLAGS))
            {
                ImGui::TableSetupColumn("Action");
                ImGui::TableSetupColumn("Count");
                ImGui::TableSetupColumn("Event");

                ImGui::TableSetupScrollFreeze(1, 1);
                ImGui::TableHeadersRow();

                std::lock_guard<std::mutex> lock(items_mutex);
                for (size_t i = 0; i < items_count; ++i)
                {
                    ImGui::TableNextRow();

                    {
                        ImGui::TableNextColumn();
                        ImGui::PushID(i);
                        if (ImGui::Button("View"))
                        {
                        } ImGui::PopID();
                    }
                    {
                        ImGui::TableNextColumn();
                        ImGui::Text("%lld", i + 1);
                    }
                    {
                        ImGui::TableNextColumn();
                        ImGui::Text("%d", items[i]);
                    }
                }

                if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
                {
                    ImGui::SetScrollHereY(1.0f);
                }

                ImGui::EndTable();
            }

            ImGui::EndTabItem();
        }
        ImGui::EndTabBar();
    }
}
ImGui::End();

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions