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 output borders and background beyond right-most column #3605

Closed
sonoro1234 opened this issue Nov 19, 2020 · 7 comments
Closed

Tables output borders and background beyond right-most column #3605

sonoro1234 opened this issue Nov 19, 2020 · 7 comments

Comments

@sonoro1234
Copy link

I would like to know why tables with fixed sizing policy are printing background and borders outside of item rect size
I would expect the area contained inside red rectangle to be as the background.

tables_fixed

@ocornut ocornut changed the title fixed Tables output borders and background outside item rect Tables output borders and background beyong right-most column Nov 19, 2020
@sonoro1234
Copy link
Author

Wrapping the table with BeginGroup-EndGroup and then
ig.GetWindowDrawList():AddRect(ig.GetItemRectMin(), ig.GetItemRectMax(), ig.U32(1,1,1,1));
outputs this:

table_group

@rokups
Copy link
Contributor

rokups commented Nov 19, 2020

I personally would not expect space beyond last one to be same as the background, because conceptually that space is part of the table. It would be confusing to have two sets of backgrounds in a single table i would think.

However, a quick search shows that UI toolkits do both variants. In that case, i suppose both are valid styles to have.

@sonoro1234
Copy link
Author

sonoro1234 commented Nov 19, 2020

that space is part of the table.

But BeginGroup/EndGroup (surrounded by white border rectangle) is telling that this space is not part of the table. It is just surrounding the three rows and four columns of the table.

@ocornut ocornut changed the title Tables output borders and background beyong right-most column Tables output borders and background beyond right-most column Nov 20, 2020
@ocornut
Copy link
Owner

ocornut commented Dec 4, 2020

But BeginGroup/EndGroup (surrounded by white border rectangle) is telling that this space is not part of the table.

It's an artifact of the fact that tables declare a certain contents size for windows auto-resize to function, and that's the size visible in EndGroup(). Same thing if you were to enclose a simple TreeNode or Selectable in a group (the visible highlight is larger than the minimum size which is the one declared for layout purpose).

As per your question, it's a valid concern but presently tables weren't designed for that.
However:

(1) You can set a specific outer-width for the Table:
Added this to demo now:

if (ImGui::BeginTable("##table1", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, ImVec2(TEXT_BASE_WIDTH * 30, 0.0f)))
{
    for (int row = 0; row < 5; row++)
    {
        ImGui::TableNextRow();
        for (int column = 0; column < 3; column++)
        {
            ImGui::TableNextColumn();
            ImGui::Text("Cell %d,%d", column, row);
        }
    }
    ImGui::EndTable();
}
ImGui::SameLine();
if (ImGui::BeginTable("##table2", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, ImVec2(TEXT_BASE_WIDTH * 30, 0.0f)))
{
    for (int row = 0; row < 3; row++)
    {
        ImGui::TableNextRow(0, TEXT_BASE_HEIGHT * 1.5f);
        for (int column = 0; column < 3; column++)
        {
            ImGui::TableNextColumn();
            ImGui::Text("Cell %d,%d", column, row);
        }
    }
    ImGui::EndTable();
}

image

I just fixed a bug to make this work btw, so you'll need to update to latest.

(2) To do exactly what you suggest we'd need to add an additional feature.
I can see various ways to approach the problem, will try to investigate it during Beta.
As I am hoping to rewrite the bg/borders rendered in a different way, if it runs a post-process pass in EndTable() as I expected to do it'll be easier to shrink the table at that point.

@ocornut
Copy link
Owner

ocornut commented Dec 17, 2020

FYI I have a working version of this:

20201217_tables_no_host_extend_x

It's not committed yet as

  • I am still working on related features now.
  • This make a off-by-one right-most-border issue a little more visible (and it's a surprisingly tricky issue but I'll fix it).
  • I am not totally sure what is the right way to enable/disable this.
  • There's currently a slight asymmetry between the seemingly-but-no-so-equivalent X/Y flags which needs some rethinking.

PS: The "hello" string visible on the right is a SameLine() + Text() call.

ocornut added a commit that referenced this issue Dec 18, 2020
…ll probably rename.

Moved some code from BeginTable() to TableUpdateLayout() to late latch some of the required data.
ocornut added a commit that referenced this issue Dec 18, 2020
…e outer_size.x == 0.0f act as ImGuiTableFlags_NoHostExtendX (#3605, ad83976) when no scrolling and no stretch column. Which is more consistent.

Demo: moved "Compact table" to "Padding" section, makes more sense. Tweaked demo.
@ocornut
Copy link
Owner

ocornut commented Dec 18, 2020

This is now supported but not via the flag suggested in the previous post.
See #2957 (comment)

"

BREAKING CHANGES (DEC 2020)

To support #3605 I made a little change to the default value and handling of the ImVec2 outer_size parameter.

ImVec2 outer_size previous default value is ImVec2(0.0f, 0.0f)
ImVec2 outer_size new default value is ImVec2(-FLT-MIN, 0.0f) (right-align)

The new meaning of outer_size.x == 0.0f is "automatic width".
If Scrolling is enabled or if any columns is set to Stretch, outer_size.x == 0.0f is the same as outer_size == -FLT_MIN (will right-align). If Scrolling is disabled and all columns are set to Non-Stretch, then outer_size.x == 0.0f allows to create tables which don't use the full window width while not having to specify a width ahead:

Effectively this is unlikely to break much code as outer_size is only required for scrolling tables.
(As a data point: The only things affected in the demo were demo tables which had a toggle to switch between scrolling and not-scrolling, and therefore had specific height provided and yet could have their scrolling disabled, which is not likely to appear in real code.)
"

@ocornut ocornut closed this as completed Dec 18, 2020
ocornut added a commit that referenced this issue Jan 21, 2021
…ze.x == 0.0f. Changed default outer_size to (0.0f, 0.0f). (#3605)
@ocornut
Copy link
Owner

ocornut commented Jan 21, 2021

I made a change to the feature discussed here.

I disliked the -FLT_MIN/0.0f distinction because it made the required default value for outer_size = ImVec2(-FLT_MIN, 0.0f) which is odd and perhaps a bit cumbersome for languages with explicit values such as C.

Instead I have made it a flag ImGuiTableFlags_NoHostExtendX now.

Will release 1.80 shortly.

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

3 participants