ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.77k stars 10.17k forks source link

Incorrect keyboard tabbing for reordered columns #8016

Open tombuskens opened 5 days ago

tombuskens commented 5 days ago

Version/Branch of Dear ImGui:

Version 1.91.2 (19120), docking branch

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx12.cpp

Compiler, OS:

Windows 10, MSVC 1939

Full config/build information:

Dear ImGui 1.91.2 (19120)
--------------------------------
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:

After reordering columns in a table, tabbing through columns via keyboard navigation tracks the original column order, instead of the reordered one.

Screenshots/Video:

https://github.com/user-attachments/assets/0a08c968-3520-4f9a-9679-30eb0c6fedc2

Minimal, Complete and Verifiable Example code:

Reproducible by using the unmodified Angled Headers demo. Drag a column to re-order it, click the first column header, then press TAB repeatedly. The column focus will follow the original column order instead of the re-ordered one.

ocornut commented 5 days ago

Unlike left<>right arrow keys, Tabbing follows submission order. It kinda mimics what e.g. Win32 api exposed as tabbing order. One property of that is that it guarantees every item are reachable. But I generally agree that in this sorts of situation it's really not what anyone would expect to happen.

Unfortunately it means that Tabbing would need to be reworked to perform fuller scoring, similar to directional requests. The logic in NavProcessItemForTabbingRequest() would need to be reworked and folded into NavScoreItem(). It's likely to be a bit hairy to do right, but sounds possible.

tombuskens commented 4 days ago

In this case it does seem a bit unexpected indeed :) Would you know of a way to achieve this currently? I've got a UI where users can pick a subset of columns from a list to display, and these columns are used in a table with ImGuiTableFlags_Reorderable set. I had a go at some workarounds, but these all had issues: