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

Redundant scrollbar with BeginChild inside a table #6619

Closed
nem0 opened this issue Jul 19, 2023 · 5 comments
Closed

Redundant scrollbar with BeginChild inside a table #6619

nem0 opened this issue Jul 19, 2023 · 5 comments

Comments

@nem0
Copy link
Contributor

nem0 commented Jul 19, 2023

Version/Branch of Dear ImGui:

Version: 07d1709 (the latest)
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx9.cpp + imgui_impl_win32.cpp, but also custom backend
Compiler: VS2022
Operating System: Win10

My Issue/Question:

I'm trying to use table API instead of old columns API to create layout like in the attached screenshot, but there is unnecessary scrollbar, caused by child window inside table. It works fine when using columns API.

Screenshots/Video

image

Standalone, minimal, complete and verifiable example:

    if (ImGui::Begin("test3")) {
        if (ImGui::BeginTable("tab", 2, ImGuiTableFlags_Resizable))    {
            ImGui::TableNextRow();
            ImGui::TableNextColumn();
            ImGui::BeginChild("foo");
            ImGui::EndChild();
            ImGui::TableNextColumn();
            ImGui::EndTable();
        }
    }
    ImGui::End();
@ocornut
Copy link
Owner

ocornut commented Jul 20, 2023

Hello,
Thanks for the report.
I am working on the correct answer for this. The full picture is a little complicated.
In the meanwhile, the temporary workaround would be to reduce child height:

ImGui::BeginChild("foo", ImVec2(0.0f, -ImGui::GetStyle().CellPadding.y));

(It's only temporary as once fixed you would not need it as it would add unnecessary padding)

@ocornut ocornut added the layout label Jul 20, 2023
ocornut added a commit to ocornut/imgui_test_engine that referenced this issue Jul 20, 2023
ocornut added a commit that referenced this issue Jul 20, 2023
…ar width of scrolling tables. (#5920, #6619)

Avoid width variation when resizing down a table hosting a child window.
+ shallow tweak to GetContentRegionMax().
@ocornut
Copy link
Owner

ocornut commented Jul 20, 2023

I pushed a fix for a tangential issue 2bc5d17 (+ test ocornut/imgui_test_engine@03da9cd) I need to fix before yours, but this is not the fix you need yet.

ocornut added a commit to ocornut/imgui_test_engine that referenced this issue Jul 20, 2023
ocornut added a commit that referenced this issue Jul 20, 2023
…lower cell padding or of using ImGuiTableFlags_NoHostExtendY. (#6619)

Made GetContentRegionMax() fully defer to WorkRect when inside a table container.
@ocornut
Copy link
Owner

ocornut commented Jul 20, 2023

I pushed a fix db66e33. If you cherry-pick both 2bc5d17 and db66e33 it'll merge in docking branch.
EDIT Merged into docking too now.

Not done with the tests, but for reference here's my test bed

if (ImGui::Begin("Test #6619"))
{
    static ImGuiTableFlags table_flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders;
    static ImVec2 table_size = ImVec2(0.0f, 0.0f);
    ImVec2 sz1 = ImGui::GetContentRegionAvail();
    ImVec2 sz2;
    ImGui::ColorButton("##blah1", { 1,1,0,0.5f }, 0, { 50,300 });
    ImGui::SameLine();
    if (ImGui::BeginTable("Table", 2, table_flags, table_size))
    {
        ImGui::TableNextRow();
        ImGui::TableNextColumn();
        sz2 = ImGui::GetContentRegionAvail();
        if (0)
        {
            ImGui::Button("Fill", ImVec2(-FLT_MIN, -FLT_MIN));
        }
        else
        {
            ImGui::PushStyleColor(ImGuiCol_ChildBg, { 0,1,0,0.5f });
            ImGui::BeginChild("foo");// , ImVec2(0.0f, -ImGui::GetStyle().CellPadding.y * 2.0f));
            ImVec2 child_size = ImGui::GetWindowSize();
            ImGui::Text("\n\n\nChild %.2f, %.2f", child_size.x, child_size.y);
            ImGui::EndChild();
            ImGui::PopStyleColor();
        }
        ImGui::TableNextColumn();
        ImGui::ColorButton("##blah1", { 1,0,1,0.5f }, 0, { 50,250 });
        ImGui::EndTable();
    }
    ImGui::Begin("test4");
    ImGui::Text("Avail %f %f", sz1.x, sz1.y);
    ImGui::Text("Avail %f %f", sz2.x, sz2.y);
    ImGui::CheckboxFlags("NoHostExtendY", &table_flags, ImGuiTableFlags_NoHostExtendY);
    ImGui::CheckboxFlags("ScrollY", &table_flags, ImGuiTableFlags_ScrollY);
    ImGui::InputFloat2("TableSize", &table_size.x);
    ImGui::End();
}
ImGui::End();

@ocornut
Copy link
Owner

ocornut commented Jul 20, 2023

Closing this as solved.

@ocornut ocornut closed this as completed Jul 20, 2023
@nem0
Copy link
Contributor Author

nem0 commented Jul 20, 2023

Thank you, it does fix my issue.

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