Imgui: SetColumnWidth(-1, ...) makes other columns non-resizeable

Created on 2 Mar 2018  路  5Comments  路  Source: ocornut/imgui

version 1.60

using SetColumnWidth(-1, ...) makes other columns non-resizeable

you can test this by modifying imgui_demo.cpp line 1626 and add ImGui::SetColumnWidth(-1,10); and you can't resize any of the columns, not just the one you're setting the width to

            ImGui::Text("With border:");
            ImGui::Columns(4, "mycolumns"); // 4-ways, with border
            ImGui::Separator();
// inserted code here ->
            ImGui::SetColumnWidth(-1,10); ImGui::Text("ID"); ImGui::NextColumn();
            ImGui::Text("Name"); ImGui::NextColumn();
            ImGui::Text("Path"); ImGui::NextColumn();
            ImGui::Text("Hovered"); ImGui::NextColumn();
            ImGui::Separator();
            const char* names[3] = { "One", "Two", "Three" };
            const char* paths[3] = { "/path/one", "/path/two", "/path/three" };
            static int selected = -1;
            for (int i = 0; i < 3; i++)
            {
                char label[32];
                sprintf(label, "%04d", i);
                if (ImGui::Selectable(label, selected == i, ImGuiSelectableFlags_SpanAllColumns))
                    selected = i;
                bool hovered = ImGui::IsItemHovered();
                ImGui::NextColumn();
                ImGui::Text(names[i]); ImGui::NextColumn();
                ImGui::Text(paths[i]); ImGui::NextColumn();
                ImGui::Text("%d", hovered); ImGui::NextColumn();
            }

bug tablecolumns

Most helpful comment

Just found this post because I'm having the same problem. Any chance this will get fixed anytime soon, or is there a smart way to make this work? I want to make my first column a fixed size, and the rest resizable.

All 5 comments

I confirmed the bug. Columns are currently a bit of an issue and I don't know when I'll be able to fix them.

The work-around I suggest for now would be to not call SetColumnWidth() every frame but only once.

Thanks for the quick reply!

Just found this post because I'm having the same problem. Any chance this will get fixed anytime soon, or is there a smart way to make this work? I want to make my first column a fixed size, and the rest resizable.

I also wanted to keep an initial size for the first column (but still resizeable), then second column would fit 100% of remaining space.

Got it to work in my use case for now with following snippet.
Is there any better way?

ImGui::Columns(2);

    static float initial_spacing = 100.f; if( initial_spacing ) ImGui::SetColumnWidth(0, initial_spacing), initial_spacing = 0;
    ImGui::Text("description");

ImGui::NextColumn();

    ImGui::PushItemWidth(-1);
    ImGui::Text("your widget here");
    ImGui::PopItemWidth();

ImGui::Columns(1);

image

Hi everyone!

@r-lyeh I had the same issue but your solution didn't worked for me. I found another "trick" based on your initial one, to force it on the initial frame, or more precisely on the second frame (I don't know why..).

static unsigned short initial_column_spacing = 0;

if (initial_column_spacing < 2) 
{
    ImGui::SetColumnWidth(0, 70.0f);
    initial_column_spacing++;
}

As you can see, i had to set the column width two frames in a row to be taken into account by ImGui.

Hope this can help,

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Folling picture Folling  路  3Comments

DarkLinux picture DarkLinux  路  3Comments

the-lay picture the-lay  路  3Comments

BlackWatersInc picture BlackWatersInc  路  3Comments

namuda picture namuda  路  3Comments