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

Not all expected cells are selected when drag-selecting in an x-scrolling table #7994

Open
tombuskens opened this issue Sep 18, 2024 · 0 comments
Labels
clipper selection tables/columns test wanted Should add corresponding test to ImGuiTestSuite

Comments

@tombuskens
Copy link

Version/Branch of Dear ImGui:

Veversion 1.91.1 (19110), docking branch

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx12.cpp

Compiler, OS:

Windows 10 + MSVC 14.39.33218

Full config/build information:

Dear ImGui 1.91.1 (19110)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=202002
define: _WIN32
define: _WIN64
define: _MSC_VER=1939
define: _MSVC_LANG=202002
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx12
io.ConfigFlags: 0x00000481
 NavEnableKeyboard
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoAutoMerge
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMoveFromTitleBarOnly
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 2 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 784.00,561.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

When drag-selecting in a table with ImGuiTableFlags_ScrollX enabled, and selection set to ImGuiMultiSelectFlags_BoxSelect2d, it seems that not all expected cells are selected.

See the video below; the expected result would be that all cells in the rectangular selection area would be selected, but some of the cells that scroll out of view are not selected.

Screenshots/Video:

multiselect.mp4

Minimal, Complete and Verifiable Example code:

The issue is reproducible with some modified demo code.
The modifications are basically - change to ImGuiMultiSelectFlags_BoxSelect2d / ImGuiTableFlags_ScrollX, add some columns, and track cell selection instead of rows.

The behavior seems to be triggered most easily by scrolling to the right, then drag-selecting from top-right to bottom-left, though generally scrolling while selecting can result in some cells not being selected correctly.

        IMGUI_DEMO_MARKER("Widgets/Selection State/Multi-Select (in a table)");
        if (ImGui::TreeNode("Multi-Select (in a table)"))
        {
            static ImGuiSelectionBasicStorage selection;

            const int ITEMS_COUNT = 10000;
            const int COLUMN_COUNT = 5;
            ImGui::Text("Selection: %d/%d", selection.Size, ITEMS_COUNT);
            if (ImGui::BeginTable("##Basket", COLUMN_COUNT, ImGuiTableFlags_ScrollY | ImGuiTableFlags_ScrollX | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter, ImVec2(300, 300)))
            {
                ImGui::TableSetupColumn("Object", ImGuiTableColumnFlags_WidthFixed, 100);
                ImGui::TableSetupColumn("One", ImGuiTableColumnFlags_WidthFixed, 100);
                ImGui::TableSetupColumn("Two", ImGuiTableColumnFlags_WidthFixed, 100);
                ImGui::TableSetupColumn("Three", ImGuiTableColumnFlags_WidthFixed, 100);
                ImGui::TableSetupColumn("Four", ImGuiTableColumnFlags_WidthFixed, 100);

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

                ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect2d;
                ImGuiMultiSelectIO* ms_io = ImGui::BeginMultiSelect(flags, selection.Size, ITEMS_COUNT * COLUMN_COUNT);
                selection.ApplyRequests(ms_io);

                ImGuiListClipper clipper;
                clipper.Begin(ITEMS_COUNT);
                if (ms_io->RangeSrcItem != -1)
                    clipper.IncludeItemByIndex((int)ms_io->RangeSrcItem / COLUMN_COUNT); // Ensure RangeSrc item is not clipped.
                while (clipper.Step())
                {
                    for (int n = clipper.DisplayStart; n < clipper.DisplayEnd; n++)
                    {
                        ImGui::TableNextRow();
                        ImGui::TableNextColumn();
                        char label[64];
                        sprintf(label, "Object %05d: %s", n, ExampleNames[n % IM_ARRAYSIZE(ExampleNames)]);
                        bool item_is_selected;
                        int idx = n * COLUMN_COUNT;
                        item_is_selected = selection.Contains((ImGuiID)idx);
                        ImGui::SetNextItemSelectionUserData(idx);
                        ImGui::Selectable(label, item_is_selected, ImGuiSelectableFlags_AllowOverlap);

                        ++idx;
                        for (idx; idx < n * COLUMN_COUNT + 5; idx++)
                        {
                            ImGui::TableNextColumn();
                            item_is_selected = selection.Contains((ImGuiID)idx);
                            ImGui::SetNextItemSelectionUserData(idx);
                            ImGui::Selectable(label, item_is_selected, ImGuiSelectableFlags_AllowOverlap);
                        }
                    }
                }

                ms_io = ImGui::EndMultiSelect();
                selection.ApplyRequests(ms_io);
                ImGui::EndTable();
            }
            ImGui::TreePop();
        }
@tombuskens tombuskens changed the title Selection issue with ImGuiMultiSelectFlags_BoxSelect2d in a table with ImGuiTableFlags_ScrollX enabled Not all expected cells are selected when drag-selecting in an x-scrolling table Sep 18, 2024
@ocornut ocornut added tables/columns clipper selection test wanted Should add corresponding test to ImGuiTestSuite labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clipper selection tables/columns test wanted Should add corresponding test to ImGuiTestSuite
Projects
None yet
Development

No branches or pull requests

2 participants