Skip to content

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

@GordonEldest

Description

@GordonEldest

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;

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions