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

Table angled headers, sorting only works on first column #7937

Closed
dcnieho opened this issue Aug 31, 2024 · 11 comments
Closed

Table angled headers, sorting only works on first column #7937

dcnieho opened this issue Aug 31, 2024 · 11 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack tables/columns

Comments

@dcnieho
Copy link

dcnieho commented Aug 31, 2024

Version/Branch of Dear ImGui:

Version 1.90.9, Branch: docking

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Windows 11, msvc 1940

Full config/build information:

NB: this is imgui_bundle 1.5.2
Dear ImGui 1.90.9 (19090)
--------------------------------

sizeof(size_t): 8, sizeof(ImDrawIdx): 4, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1940
define: _MSVC_LANG=201703
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------

io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000480
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMoveFromTitleBarOnly
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------

io.Fonts: 16 fonts, Flags: 0x00000000, TexSize: 2048,4096
io.DisplaySize: 3500.00,1750.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------

style.WindowPadding: 20.00,20.00
style.WindowBorderSize: 1.00
style.FramePadding: 10.00,7.00
style.FrameRounding: 7.00
style.FrameBorderSize: 1.00
style.ItemSpacing: 20.00,10.00
style.ItemInnerSpacing: 10.00,10.00

Details:

My Issue/Question:
See the below screenshot. I have a table with mixed normal and angled headers. First two normal headers, then a series of angled headers. I can sort the table on the normal header and the first angled header, but not the rest. Any click on those is just ignored. (sort specs does not become dirty). This is both when clicking on the angled header or the line below it (only the normal header row works for the first angled header column, but i understand that is expected).

Screenshots/Video:

image

Minimal, Complete and Verifiable Example code:

This is not an complete minimal example, nor in C++ (its Python using imgui_bundle), but shows the main relevant code

table_flags: int = (
    imgui.TableFlags_.scroll_x |
    imgui.TableFlags_.scroll_y |
    imgui.TableFlags_.hideable |
    imgui.TableFlags_.sortable |
    imgui.TableFlags_.resizable |
    imgui.TableFlags_.sort_multi |
    imgui.TableFlags_.reorderable |
    imgui.TableFlags_.sizing_fixed_fit |
    imgui.TableFlags_.no_host_extend_y |
    imgui.TableFlags_.no_borders_in_body_until_resize |
    imgui.TableFlags_.highlight_hovered_column
)

if imgui.begin_table(
    f"##session_list",
    columns=self._view_column_count,
    flags=self.table_flags,
):
    # Setup
    checkbox_width = frame_height-2*imgui.get_style().frame_padding.y
    imgui.table_setup_column("Selector", imgui.TableColumnFlags_.no_hide | imgui.TableColumnFlags_.no_sort | imgui.TableColumnFlags_.no_resize | imgui.TableColumnFlags_.no_reorder, init_width_or_weight=checkbox_width)  # 0
    imgui.table_setup_column("Name", imgui.TableColumnFlags_.default_sort | imgui.TableColumnFlags_.no_hide | imgui.TableColumnFlags_.no_resize)  # 1
    imgui.table_setup_column("Recordings", imgui.TableColumnFlags_.no_resize | imgui.TableColumnFlags_.angled_header)  # 2
    for k in ['Import', 'Code Episodes']:   # 3+, just put the first two here...
        imgui.table_setup_column(k, imgui.TableColumnFlags_.no_resize | imgui.TableColumnFlags_.angled_header)

imgui.table_setup_scroll_freeze(1, 2)  # Sticky column headers and selector row

imgui.table_angled_headers_row()
imgui.table_next_row(imgui.TableRowFlags_.headers)
for i in range(imgui.table_get_column_count()):
    if not imgui.table_set_column_index(i):
        continue
    column_name = '' if imgui.table_get_column_flags(i) & imgui.TableColumnFlags_.no_header_label else imgui.table_get_column_name(i)
    if i==0:  # checkbox column, skip all logic here as not relevant for this problem
        pass
    else:
        imgui.table_header(column_name)

# draw rows... logic skipped, not relevant
@dcnieho
Copy link
Author

dcnieho commented Aug 31, 2024

Recording.2024-09-01.000723.mp4

Here a screen recording. Not also that the whole angled header bar is highlighted when clicked, don't know if that is of relevance

@ocornut
Copy link
Owner

ocornut commented Sep 3, 2024

I added ImGuiTableFlags_Sortable to the Table->Angled Headers demo and it worked.

The reason seems to be that you have an ID conflict with your TableHeader("") calls:

column_name = '' if imgui.table_get_column_flags(i) & imgui.TableColumnFlags_.no_header_label else imgui.table_get_column_name(i)

TableHeadersRow() is doing:

for (int column_n = 0; column_n < columns_count; column_n++)
{
    if (!TableSetColumnIndex(column_n))
        continue;

    // Push an id to allow unnamed labels (generally accidental, but let's behave nicely with them)
    // In your own code you may omit the PushID/PopID all-together, provided you know they won't collide.
    const char* name = (TableGetColumnFlags(column_n) & ImGuiTableColumnFlags_NoHeaderLabel) ? "" : TableGetColumnName(column_n);
    PushID(column_n);
    TableHeader(name);
    PopID();
}

You are missing a PushID() call.

I don't recall the details but I spent some time evaluating whether TableHeader() should push an extra column ID and deemed this inconsistent.

@ocornut ocornut closed this as completed Sep 3, 2024
@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Sep 3, 2024
@dcnieho
Copy link
Author

dcnieho commented Sep 4, 2024

Ah, i even looked at that code and didn't see the point of PushID due to the comment. Maybe an additional comment like "NB: This is important for proper interaction with the row under an angled headers row, since none of these header columns have a label for this row".

Thanks!

@ocornut
Copy link
Owner

ocornut commented Sep 4, 2024

Why aren’t you using TableHeadersRow() ?

@dcnieho
Copy link
Author

dcnieho commented Sep 4, 2024

Because i have a checkbox in the first column of the header for selection logic (select all/deselect all), so I have to handle drawing the header row manually.

@ocornut
Copy link
Owner

ocornut commented Sep 4, 2024

I am not in front of the code now but if there isn’t a column flag for that we can add one.

@dcnieho
Copy link
Author

dcnieho commented Sep 4, 2024

If i understand you correctly, you suggest adding a column flag to put a checkbox in the header? I think a flag would not be sufficient for that, a way would be needed to set the state of the checkbox (tristate actually, also only part of the table's rows could be selected) and would need a way to report any user interaction with it. What i have now works well

@ocornut
Copy link
Owner

ocornut commented Sep 4, 2024

The flag would disable submitting a header. You can set call e.g. TableSetColumnIndex(0) and submit your checkbox.

@ocornut
Copy link
Owner

ocornut commented Sep 4, 2024

Actually, it already works with ImGuiTableColumnFlags_NoHeaderLabel... Set this on the column, then call TableHeadersRow() then TableSetColumnIndex(0) and you can submit your checkbox..

ocornut added a commit that referenced this issue Sep 4, 2024
@ocornut
Copy link
Owner

ocornut commented Sep 4, 2024

I have pushed a few comments in 722a2a1

@dcnieho
Copy link
Author

dcnieho commented Sep 4, 2024

Ah sorry, then i misunderstood your comment. Yes, this works beautifully, and i am of course very happy that i do not have to reimplement TableHeadersRow() like this. Thanks for going beyond in the support! The comments are helpful too.

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

No branches or pull requests

2 participants