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

Tables: cannot calc content width properly #3568

Closed
antmanler opened this issue Oct 31, 2020 · 6 comments
Closed

Tables: cannot calc content width properly #3568

antmanler opened this issue Oct 31, 2020 · 6 comments

Comments

@antmanler
Copy link

antmanler commented Oct 31, 2020

Version/Branch of Dear ImGui:

Version: 1.80 WIP (17905)
Branch: tables

Dear ImGui 1.80 WIP (17905)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201103
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: __APPLE__
define: __GNUC__=4
define: __clang_version__=12.0.0 (clang-1200.0.31.1)
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000440
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigMacOSXBehaviors
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMemoryCompactTimer = 60.0f
io.BackendFlags: 0x0000140E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 4 fonts, Flags: 0x00000000, TexSize: 512,1024
io.DisplaySize: 1600.00,900.00
io.DisplayFramebufferScale: 2.00,2.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 6.00,3.00
style.FrameRounding: 2.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp +imgui_impl_opengl3.cpp
Operating System: MacOS

My Issue/Question:

In recent update tables cannot figure out the right width of columns when using slider of dragfloat as cell's content.
But it works as expected in 1.79 WIP (17803)

Screenshots/Video

1.80 WIP (17905)

image

1.79 WIP (17803)
image

@ocornut
Copy link
Owner

ocornut commented Oct 31, 2020 via email

@antmanler antmanler changed the title Table cannot calc content with properly Table cannot calc content width properly Nov 1, 2020
@antmanler
Copy link
Author

It seems git history has been rewritten on branch/Tables,
on current Tables branch brefore the following commit it works as expected.
Tables: Frozen rows/columns in nav menu layer, fixed conflict between…

cf8175b...426dc5f

@antmanler
Copy link
Author

I'm trying to reproduce this issue with the following code, BUT it seems like that this issue is not introduced by branch/tables:

1.79 WIP (17803) was manually merged from master@4fd43a8 + branch/tables, AND it works as expected: each columns' width is fitting its content.

image

BUT on current branch of tables, columns' width is only determinate by it's column's name if the content is DragFloat

image

static ImGuiTableFlags flags = ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable;
static float shared_value = 0.6180339887;
static char *columns[] = {"col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8", "col9", "col10", "col11"};
ImGui::SetNextWindowSize(ImVec2(400, 200), ImGuiCond_FirstUseEver);
if (ImGui::Begin("IssuseTable"))
{
    if (ImGui::BeginTable("##issue3568", 11, flags))
    {
        for (int i = 0; i < 11; ++i)
        {
            ImGui::TableSetupColumn(columns[i], ImGuiTableColumnFlags_WidthFixed);
        }
        ImGui::TableHeadersRow();
        for (int i = 0; i < 3; ++i)
        {
            ImGui::TableNextRow();
            for (int j = 0; j < 11; ++j)
            {
                if (ImGui::TableNextColumn())
                {
                    if (j % 2 == 0)
                    {
                        ImGui::AlignTextToFramePadding();
                        ImGui::Text("text value %d", j);
                    }
                    else
                    {
                        ImGui::SetNextItemWidth(-FLT_MIN);
                        ImGui::DragFloat("##dagfloat", &shared_value, 1, 0, 0, "%.4f");
                    }
                }
            }
        }
        ImGui::EndTable();
    }
}
ImGui::End();

@ocornut
Copy link
Owner

ocornut commented Nov 2, 2020

Thank you for the repro.

I think you misunderstood the fact that:

ImGui::SetNextItemWidth(-FLT_MIN);
ImGui::DragFloat("##dagfloat", &shared_value, 1, 0, 0, "%.4f");

This will make the widget use available space. And therefore always request exactly the width the of column.
If it fit better before it was either accidental, either side-effect of existing .ini data, either an artifact of default minimum width being too wide. If I checkout cf8175b and test your repro there's a similar issue, just a little more spacing (because some of padding-sizing side-effects in recent changes) but still clipped.

@ocornut ocornut changed the title Table cannot calc content width properly Tables: cannot calc content width properly Nov 2, 2020
@antmanler
Copy link
Author

Thank you, I think it's the result of the change on minimum width of columns, I'm submitting the width explicitly using TableSetupColumn.
But I realize that "size column to fit" always uses the width I set in TableSetupColumn not the content in DragFloat nor SliderFloat.

@ocornut
Copy link
Owner

ocornut commented Nov 4, 2020

But I realize that "size column to fit" always uses the width I set in TableSetupColumn not the content in DragFloat nor SliderFloat.

For this to happens we'd need to rework some fundamental of our layout system and ItemAdd etc func. I think eventually we will do that but in the short-term. I'll post again here if it ends up being implemented someday. (we need to have multiple variations of "CursorMaxPos" essentially, the issue in #3414 also requires a similar thing to be done to distinguish "requested width" from "scrollable width").

@ocornut ocornut closed this as completed Nov 4, 2020
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