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

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

Closed
Alan-FGR opened this issue Oct 19, 2018 · 4 comments
Closed

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

Alan-FGR opened this issue Oct 19, 2018 · 4 comments

Comments

@Alan-FGR
Copy link

Alan-FGR commented Oct 19, 2018

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

@ocornut
Copy link
Owner

ocornut commented Oct 22, 2018

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
Copy link
Author

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 😆

@Alan-FGR
Copy link
Author

IT HAPPENED!! 🤣
image
@ocornut congrats man!

@ocornut ocornut added the layout label Apr 8, 2019
ocornut added a commit that referenced this issue Nov 18, 2020
…ColumnFlags_*. (#125, #513, #913, #1204, #1444, #2142, #2707)

Affected: ImGuiColumnsFlags_None, ImGuiColumnsFlags_NoBorder, ImGuiColumnsFlags_NoResize, ImGuiColumnsFlags_NoPreserveWidths, ImGuiColumnsFlags_NoForceWithinWindow, ImGuiColumnsFlags_GrowParentContentsSize. Added redirection enums. Did not add redirection type.
@ocornut
Copy link
Owner

ocornut commented Dec 8, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants