Column with variable width content not updating scroll area width #2142

Closed
opened 2018-10-19 22:44:57 +00:00 by Alan-FGR · 4 comments
Alan-FGR commented 2018-10-19 22:44:57 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

1.65

Back-end file/Renderer/OS:

Back-ends: imgui_impl_sdl.cpp + imgui_impl_dx11.cpp
OS: Windows 7

My Issue/Question:

I want to make a table consisting of two columns, one with variable width, but the scroll area isn't updated according to the width of the columns.

Standalone, minimal, complete and verifiable example:

ImGui::Begin("Key Mapping", nullptr, ImGuiWindowFlags_HorizontalScrollbar);

ImGui::Columns(2);
ImGui::SetColumnWidth(0, 90);

ImGui::Text("Action");
ImGui::NextColumn();
ImGui::Text("Keys");
ImGui::NextColumn();

ImGui::Separator();

for (int i = 0; i < 16; ++i)
{
    ImGui::Text("label");
    ImGui::NextColumn();
    for (int i1 = 65; i1 < 70; ++i1)
    {
        ImGui::Button((char*)&i1, ImVec2(60, 0));
        ImGui::SameLine();
    }
    ImGui::Button("+");
    ImGui::NextColumn();
}

ImGui::End();

Screenshots/Video
Use case:

Example code:
image

**Version/Branch of Dear ImGui:** 1.65 **Back-end file/Renderer/OS:** Back-ends: imgui_impl_sdl.cpp + imgui_impl_dx11.cpp OS: Windows 7 **My Issue/Question:** I want to make a table consisting of two columns, one with variable width, but the scroll area isn't updated according to the width of the columns. **Standalone, minimal, complete and verifiable example:** ``` C++ ImGui::Begin("Key Mapping", nullptr, ImGuiWindowFlags_HorizontalScrollbar); ImGui::Columns(2); ImGui::SetColumnWidth(0, 90); ImGui::Text("Action"); ImGui::NextColumn(); ImGui::Text("Keys"); ImGui::NextColumn(); ImGui::Separator(); for (int i = 0; i < 16; ++i) { ImGui::Text("label"); ImGui::NextColumn(); for (int i1 = 65; i1 < 70; ++i1) { ImGui::Button((char*)&i1, ImVec2(60, 0)); ImGui::SameLine(); } ImGui::Button("+"); ImGui::NextColumn(); } ImGui::End(); ``` **Screenshots/Video** Use case: ![](https://files.gitter.im/nem0/LumixEngine/mlHP/image.png) Example code: ![image](https://user-images.githubusercontent.com/8399299/47246966-13e4ef00-d3d7-11e8-9ecd-0a97cd22972c.png)
ocornut commented 2018-10-22 14:56:13 +00:00 (Migrated from github.com)

Hello @Alan-FGR,

I want to make a table consisting of two columns, one with variable width, but the scroll area isn't updated according to the width of the columns.

At the moment columns are a container which do not report the size of their contents outside.
That's a legitimate issue but the situation is a little tricky today (TL;DR; Columns are currently terrible and haven't been really improved since 1.00 - need some love).

There's a temporary workaround you can use which restore pre-1.51 bug/behavior of reporting the farther X position of the last column, which happens to be specifically useful in a couple of case including yours. You can use this internal API instead of Columns().

#include "imgui_internal.h"

ImGui::BeginColumns(...., ImGuiColumnsFlags_GrowParentContentsSize);
[...]
ImGui::EndColumns();

Please note that for simple use and in particular your use here, you are probably better off not using Columns at all, and just using SameLine() to position the cursor after the first call to Text().

Hello @Alan-FGR, > I want to make a table consisting of two columns, one with variable width, but the scroll area isn't updated according to the width of the columns. At the moment columns are a container which do not report the size of their contents outside. That's a legitimate issue but the situation is a little tricky today (TL;DR; Columns are currently terrible and haven't been really improved since 1.00 - need some love). There's a temporary workaround you can use which restore pre-1.51 bug/behavior of reporting the farther X position of the _last_ column, which happens to be specifically useful in a couple of case including yours. You can use this internal API instead of `Columns()`. ``` #include "imgui_internal.h" ImGui::BeginColumns(...., ImGuiColumnsFlags_GrowParentContentsSize); [...] ImGui::EndColumns(); ``` Please note that for simple use and in particular your use here, you are probably better off _not_ using Columns at all, and just using SameLine() to position the cursor after the first call to `Text()`.
Alan-FGR commented 2018-10-23 01:07:50 +00:00 (Migrated from github.com)

Hello @ocornut! Thank you for your reply.

Yes, I've ended up going with just labels and buttons and using SameLine(), it works just as well but there's no vertical separator 😛 what's no big deal... in any case that trick/workaround could come handy I guess, it's always good to have them up my sleeves, but yeah I won't be using columns when I need that kind of behavior. Columns have their uses though, I think especially when you want to allow the user to resize them.

I think this is a legit bug/improvement so I won't close the issue.

PS: 12345 stars is happening 😆

Hello @ocornut! Thank you for your reply. Yes, I've ended up going with just labels and buttons and using SameLine(), it works just as well but there's no vertical separator :stuck_out_tongue: what's no big deal... in any case that trick/workaround could come handy I guess, it's always good to have them up my sleeves, but yeah I won't be using columns when I need that kind of behavior. Columns have their uses though, I think especially when you want to allow the user to resize them. I think this is a legit bug/improvement so I won't close the issue. PS: 12345 stars is happening :laughing:
Alan-FGR commented 2018-10-23 20:18:35 +00:00 (Migrated from github.com)

IT HAPPENED!! 🤣
image
@ocornut congrats man!

**IT HAPPENED!!** :rofl: ![image](https://user-images.githubusercontent.com/8399299/47383856-ff0ca200-d6db-11e8-8be0-417c1dfd9e8e.png) @ocornut congrats man!
ocornut commented 2020-12-08 16:07:27 +00:00 (Migrated from github.com)

Closing this as new tables api has more configurability + support for horizontal scrolling and horizontal freezing.

Closing this as new tables api has more configurability + support for horizontal scrolling and horizontal freezing.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#2142
No description provided.