From 3edfc042ff4332fe61838bc03a092fc5423356b0 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 15 Jan 2021 10:36:20 +0100 Subject: [PATCH] Tables: Internals: Renaming, tweaks preparing ahead for trickier changes (should be all no-op). --- imgui.cpp | 3 ++- imgui_internal.h | 2 +- imgui_tables.cpp | 24 +++++++++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 6c6747c97..e7078570e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6101,7 +6101,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // This works but 1. doesn't handle multiple Begin/End pairs, 2. recursing into another Begin/End pair - so we need to work that out and add better logging scope. // Maybe we can support CTRL+C on every element? /* - if (g.ActiveId == move_id) + //if (g.NavWindow == window && g.ActiveId == 0) + if (g.ActiveId == window->MoveId) if (g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_C)) LogToClipboard(); */ diff --git a/imgui_internal.h b/imgui_internal.h index 6e6be397c..cfbbc0d9d 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2081,7 +2081,7 @@ struct ImGuiTable bool IsResetAllRequest; bool IsResetDisplayOrderRequest; bool IsUnfrozenRows; // Set when we got past the frozen row. - bool IsOuterRectAutoFitX; // Set when outer_size.x == 0.0f in BeginTable(), scrolling is disabled, and there are stretch columns. + bool IsOuterRectMinFitX; // Set when outer_size.x == 0.0f in BeginTable(), scrolling is disabled, and there are no stretch columns. bool MemoryCompacted; bool HostSkipItems; // Backup of InnerWindow->SkipItem at the end of BeginTable(), because we will overwrite InnerWindow->SkipItem on a per-column basis diff --git a/imgui_tables.cpp b/imgui_tables.cpp index a03177441..e03209344 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -335,7 +335,7 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG table->ColumnsCount = columns_count; table->IsLayoutLocked = false; table->InnerWidth = inner_width; - table->IsOuterRectAutoFitX = (outer_size.x == 0.0f) && (use_child_window == false); + table->IsOuterRectMinFitX = (outer_size.x == 0.0f) && (use_child_window == false); // Will be set to false later if there are any Stretch column. // When not using a child window, WorkRect.Max will grow as we append contents. if (use_child_window) @@ -1032,8 +1032,8 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) // This is done late to handle the case of fixed-columns tables not claiming more widths that they need. // Because of this we are careful with uses of WorkRect and InnerClipRect before this point. if (table->RightMostStretchedColumn != -1) - table->IsOuterRectAutoFitX = false; - if (table->IsOuterRectAutoFitX) + table->IsOuterRectMinFitX = false; + if (table->IsOuterRectMinFitX) { table->OuterRect.Max.x = table->WorkRect.Max.x = unused_x1; table->InnerClipRect.Max.x = ImMin(table->InnerClipRect.Max.x, unused_x1); @@ -1181,7 +1181,6 @@ void ImGui::EndTable() if (inner_window != outer_window) { - // Both OuterRect/InnerRect are valid from BeginTable inner_window->DC.CursorMaxPos.y = table->RowPosY2; } else if (!(flags & ImGuiTableFlags_NoHostExtendY)) @@ -1258,9 +1257,8 @@ void ImGui::EndTable() PopID(); // Restore window data that we modified - const float backup_outer_cursor_pos_x = outer_window->DC.CursorPos.x; - const float backup_outer_max_pos_x = outer_window->DC.CursorMaxPos.x; - const float backup_inner_max_pos_x = inner_window->DC.CursorMaxPos.x; + const ImVec2 backup_outer_max_pos = outer_window->DC.CursorMaxPos; + const ImVec2 backup_inner_max_pos = inner_window->DC.CursorMaxPos; inner_window->WorkRect = table->HostBackupWorkRect; inner_window->ParentWorkRect = table->HostBackupParentWorkRect; inner_window->SkipItems = table->HostSkipItems; @@ -1272,7 +1270,7 @@ void ImGui::EndTable() // Layout in outer window // (FIXME: To allow auto-fit and allow desirable effect of SameLine() we dissociate 'used' vs 'ideal' size by overriding // CursorPosPrevLine and CursorMaxPos manually. That should be a more general layout feature, see same problem e.g. #3414) - const float outer_width = table->IsOuterRectAutoFitX ? table->WorkRect.GetWidth() : table->ColumnsAutoFitWidth; + const float outer_width = table->IsOuterRectMinFitX ? table->WorkRect.GetWidth() : table->ColumnsAutoFitWidth; const float outer_height = table->OuterRect.GetHeight(); if (inner_window != outer_window) { @@ -1284,21 +1282,21 @@ void ImGui::EndTable() outer_window->DC.CursorPosPrevLine.x = table->OuterRect.Max.x; } - // Override EndChild/ItemSize max extent with our own to enable auto-resize on the X axis when possible + // Override declared contents width to enable auto-resize on the X axis when possible. // FIXME-TABLE: This can be improved (e.g. for Fixed columns we don't want to auto AutoFitWidth? or propagate window auto-fit to table?) if (table->Flags & ImGuiTableFlags_ScrollX) { - float max_pos_x = backup_inner_max_pos_x; + float max_pos_x = backup_inner_max_pos.x; if (table->RightMostEnabledColumn != -1) max_pos_x = ImMax(max_pos_x, table->Columns[table->RightMostEnabledColumn].MaxX); if (table->ResizedColumn != -1) max_pos_x = ImMax(max_pos_x, table->ResizeLockMinContentsX2); inner_window->DC.CursorMaxPos.x = max_pos_x; // For inner scrolling - outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos_x, backup_outer_cursor_pos_x + table->ColumnsGivenWidth + inner_window->ScrollbarSizes.x); // For outer scrolling + outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, table->OuterRect.Min.x + table->ColumnsGivenWidth + inner_window->ScrollbarSizes.x); // For outer scrolling } else { - outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos_x, table->WorkRect.Min.x + outer_width); // For auto-fit + outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, table->WorkRect.Min.x + outer_width); // For auto-fit } // Save settings @@ -2373,7 +2371,7 @@ void ImGui::TableDrawBorders(ImGuiTable* table) if (column->MaxX > table->InnerClipRect.Max.x && !is_resized) continue; if (column->NextEnabledColumn == -1 && !is_resizable) - if ((table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame || table->IsOuterRectAutoFitX) + if ((table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame || table->IsOuterRectMinFitX) continue; if (column->MaxX <= column->ClipRect.Min.x) // FIXME-TABLE FIXME-STYLE: Assume BorderSize==1, this is problematic if we want to increase the border size.. continue;