Skip to content

Keyboard Nav in Scrollable tables doesn't account for frozen rows #5143

@chreden

Description

@chreden

Version/Branch of Dear ImGui:

Dear ImGui 1.88 WIP (18713)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1930
define: _MSVC_LANG=201402
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
io.ConfigFlags: 0x00000001
 NavEnableKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1264.00,761.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

Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx11.cpp + imgui_impl_win32.cpp
Compiler: VS2022
Operating System: Windows 10

My Issue/Question:

For a table with ImGuiTableFlags_ScrollY using keyboard navigation and the up arrow to scroll up any frozen rows aren't taken into account so the table doesn't fully scroll to selected item. Scrolling up with the mouse or the home key does work (home key only helps for the 0th element).

When navigating around it crops up quite often, with the element you have selected mostly out of view. It affects whichever item is at the top of the view, not just the first item in the overall table.

Screenshots/Video

Steps in the video:

  • Scroll down with down arrow and back up to the headers to confirm normal behaviour when no scrolling has taken place
  • I scroll down using the down key past the scroll point
  • Scroll back up using the up key - selected item is out of view
  • Scroll back down
  • Scroll up holding page up - it wiggles between the first two elements
bandicam.2022-03-29.17-32-26-255.mp4

Standalone, minimal, complete and verifiable example: (see #2261)
for to_string

#include <string>

Enable keyboard nav

io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
{
    static int selected = 0;
    ImGui::Begin("Scroll and Selectable", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
    if (ImGui::BeginTable("Items", 2, ImGuiTableFlags_ScrollY, ImVec2(300, 300)))
    {
        ImGui::TableSetupScrollFreeze(0, 1);
        ImGui::TableSetupColumn("#");
        ImGui::TableSetupColumn("Text");
        ImGui::TableHeadersRow();

        for (int i = 0; i < 100; ++i)
        {
            ImGui::TableNextRow();
            ImGui::TableNextColumn();

            bool is_selected = i == selected;
            if (ImGui::Selectable(std::to_string(i).c_str(), &is_selected, ImGuiSelectableFlags_SpanAllColumns))
            {
                selected = i;
            }
            ImGui::TableNextColumn();
            ImGui::Text("Example text");
        }

        ImGui::EndTable();
    }
    ImGui::End();
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions