Tables: decent support for auto-resize of stretch columns (trickier than it sounds)

Four cases:
1. visible columns are all stretch, resize all : "size all to default" reset to default weight
2. visible columns are all stretch, resize one: "size one to fit" set weight, reapply weight (todo: improve weight redistribution in case of >1 siblings)
3. visible columns are mixed, resize all: "size all to fit/default" reset stretchs to default weight, set fixed to auto width
4. visible columns are mixed, resize one: "size one to fit", redistribute weight the same way as a manual resize
+ TableSetupColumn() more consistently clear AutoFitQueue.
+ zero-clear RowCellData buffer.
This commit is contained in:
ocornut
2020-11-16 20:25:35 +01:00
parent c5dcf2fde1
commit 3b3503e60f
3 changed files with 85 additions and 50 deletions

View File

@ -3514,7 +3514,7 @@ static void ShowDemoWindowTables()
{
// By default, if we don't enable ScrollX the sizing policy for each columns is "Stretch"
// Each columns maintain a sizing weight, and they will occupy all available width.
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV;
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody;
PushStyleCompact();
ImGui::CheckboxFlags("ImGuiTableFlags_Resizable", &flags, ImGuiTableFlags_Resizable);
ImGui::CheckboxFlags("ImGuiTableFlags_BordersV", &flags, ImGuiTableFlags_BordersV);
@ -3549,7 +3549,7 @@ static void ShowDemoWindowTables()
"Using _Resizable + _SizingPolicyFixedX flags.\n"
"Fixed-width columns generally makes more sense if you want to use horizontal scrolling.\n\n"
"Double-click a column border to auto-fit the column to its contents.");
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingPolicyFixedX | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV;
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingPolicyFixedX | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody;
//ImGui::CheckboxFlags("ImGuiTableFlags_ScrollX", &flags, ImGuiTableFlags_ScrollX); // FIXME-TABLE: Explain or fix the effect of enable Scroll on outer_size
if (ImGui::BeginTable("##table1", 3, flags))
{