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

Method to dynamically change Hide/Show Column in Tables (request and fix suggested) #3935

Closed
GordonEldest opened this issue Mar 17, 2021 · 7 comments

Comments

@GordonEldest
Copy link

GordonEldest commented Mar 17, 2021

The flag ImGuiTableColumnFlags_DefaultHide does hide a column but once and for all
because it is only used on first call to TableSetupColumn(...) where a few line are executed but only under control of table->IsInitializing so this happens only on first call.

This behavior prevent the capabilities to hide the column at will. (after first Frame on the table).
Maybe a flag allow it but not only didn't I find it but vanillia demo show this strange behavior on code related to “ImGui::TreeNode("Columns flags")” where in the list of flags manage trough check box , the “hide” in fact do nothing.
But the example in table ImGui::TreeNode("Resizable, mixed") does properly hide column "CCC" of "table2"

The reason underneath the lack of "dynamic" (that it cannot change on each frame) is due to the State of a Table flag
table->IsInitializing which is kept at true until first call to EndTable () where it is set forever at “false”.
However it seems making sense to keep this feature more dynamic in ImGui::TableSetupColumn() where this flag does manage display.

Workaround:
Add management code for column->IsEnabled = column->IsEnabledNextFrame = true in ImGui::TableSetupColumn
See below

Drawback:
Unknown why the implementation work that way. Maybe the code does what it is intended to do.
Effect of the 2 flags involved are not fully understood, but so far no side effect seen.
The check is done on flags but after it is filtered and == to column->Flags . (see full source to clarify)
This is my choice to respect the sequence used in if (table->IsInitializing) but it would be good to dig in BeginTable and see how much code is executed to seeif a transient Method should be designed (use of only one flag ? column->IsEnabledNextFrame? )

(WIP v1.82) Docking branch
imgui_table.cpp ~ line 1387

Standard code

   if (table->IsInitializing)
    {
        // Init width or weight
        if (column->WidthRequest < 0.0f && column->StretchWeight < 0.0f)
.........
    }

Extended Code

if (table->IsInitializing)
    {
        // Init width or weight
        if (column->WidthRequest < 0.0f && column->StretchWeight < 0.0f)
.........
    }
  if (flags & ImGuiTableColumnFlags_DefaultHide)		//glh++in EndTable set table->IsInitializing=false , this flag reverse this effect during Colum Setup to allow reasserting column Hide dynamically
       column->IsEnabled = column->IsEnabledNextFrame =  false;
  else 
       column->IsEnabled = column->IsEnabledNextFrame = true;
@ocornut
Copy link
Owner

ocornut commented Mar 18, 2021

Hello,

DefaultHide works as expected, it is the default state.
The suggested change would always override current state with default state.

Question 1: are you aware that user can right-click to alter visibility of individual columns, or reset visibility state?

Question 2: if you answered Yes to question 1, why do you need to alter it programmatically? Please be explicit.

There is a function TableSetColumnEnabled() in imgui_internal.h but for variety of reasons I think it is misleading to expose it to the public API. People who ask about it are generally trying to badly replicate what should be provided by the settings systems or by higher-level systems, therefore I am not convinced this needs to be made public until I hear of good reasons.

@mekhontsev
Copy link

I upvote to make TableSetColumnEnabled public.
There is a table in my application with more than 50 columns, most of them are hidden usually.
I have to use a special dialog to set a hidden status of every column because the only way to show the standard column chooser is to use rigth mouse button, but it is not possible on touch devices. Also, standard column chooser is not optimized for small screens.
Currently I always move TableSetColumnEnabled to the imgui.h on every ImGui update.

@ocornut
Copy link
Owner

ocornut commented Mar 22, 2021

Good points.

Currently I always move TableSetColumnEnabled to the imgui.h on every ImGui update.

Why not just including imgui_internal.h in the one file that needs it?

@mekhontsev
Copy link

Why not just including imgui_internal.h in the one file that needs it?

I'm trying to use the standard API as much as possible :)
Actually, TableSetColumnEnabled is the only function that I need at the moment ...

@GordonEldest
Copy link
Author

GordonEldest commented Mar 23, 2021

Hello
sorry for my late answer, kudo for your quick answer!

Short:
TableSetColumnEnabled(...) does exactly what I look for. Thanks. Yes I upvote to externalize it.
No I didn't notice that right click does something, Nice. I will investigate UI paradigm impact

Long:

DefaultHide works as expected, it is the default state.
The suggested change would always override current state with default state.

I get your point now.
Yes it does override it and create side effect, as you predicted. But on a feature I didn't know.

Question 1: are you aware that user can right-click to alter visibility of individual columns, or reset visibility state?

No, I was not, and yes in order for right click to work I need to remove my code. :-)

Question 2: if you answered Yes to question 1, why do you need to alter it programmatically? Please be explicit.

Q1 answer is No. But nevertheless I need(ed) a way to programmatically hide/show column with a Boolean preset
before the TableBegin()
Think about it as a way to change collumn hide/show but trough an automat, not by asking user.
Yes we can influence first call but TabgeBegin optmisation does hamper way to do it programatically (until I hear of ableSetColumnEnabled ()

In fact the demo show exactly what I need, in Table&Columns->Column flags->check box "_DefaultHide" of column Two
Expected experience would be that this check mark Hide/Show column two.
At present time it doesn't seem to do something.

Of course I can have various Table layouts, but it lack elegance and increase dramatically the amount of code for us,
in a pretty crowded window, with hoovers, dynamic reposition of Modal, animated text,etc ...
My suggestion does the job for us, but I will migrate to TableSetColumnEnabled
I hate patch and branch, so I will check that 'rigthclicking' may also match the UI intended experience.

Note:
TableSetColumnEnabled seems to work in column index,
while the concept of TableSetupColumn use "Id" which is great (and probably low CPU overhead)

Thanks
issue closed for me

@GordonEldest
Copy link
Author

Why not just including imgui_internal.h in the one file that needs it?

I'm trying to use the standard API as much as possible :)
Actually, TableSetColumnEnabled is the only function that I need at the moment ...

I agree with you, but the feature worth breaking the law but not the rule ;-)
you can limit that to one function (the beauty of ImGui is to Not overuse class and attribute like private)
just putting this after headers does the job

namespace ImGui
{
	extern void TableSetColumnEnabled(int column_n, bool enabled);
}

@ocornut
Copy link
Owner

ocornut commented Mar 24, 2021

Added TableSetColumnEnabled() to public api with aa5431f

ocornut added a commit that referenced this issue Jun 7, 2021
ocornut added a commit that referenced this issue Jun 7, 2021
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