Browse Source

Tables: Better preserve column data (mainly widths) when columns count changes. (#4046) + .ini skips columns with no data.

pull/4060/head
ocornut 4 years ago
parent
commit
770f9daab3
  1. 1
      docs/CHANGELOG.txt
  2. 2
      imgui.h
  3. 27
      imgui_tables.cpp

1
docs/CHANGELOG.txt

@ -44,6 +44,7 @@ Other Changes:
- Scrolling: Fix mouse wheel axis swap when using SHIFT on macOS (system already does it). (#4010) - Scrolling: Fix mouse wheel axis swap when using SHIFT on macOS (system already does it). (#4010)
- Window: Fix IsWindowAppearing() from returning true twice in most cases. (#3982, #1497, #1061) - Window: Fix IsWindowAppearing() from returning true twice in most cases. (#3982, #1497, #1061)
- Tables: Expose TableSetColumnEnabled() in public api. (#3935) - Tables: Expose TableSetColumnEnabled() in public api. (#3935)
- Tables: Better preserve widths when columns count changes. (#4046)
- TabBar: Fixed mouse reordering with very fast movements (e.g. crossing multiple tabs in a single - TabBar: Fixed mouse reordering with very fast movements (e.g. crossing multiple tabs in a single
frame and then immediately standling still (would only affect automation/bots). [@rokups] frame and then immediately standling still (would only affect automation/bots). [@rokups]
- Drags, Sliders, Inputs: Specifying a NULL format to Float functions default them to "%.3f" to be - Drags, Sliders, Inputs: Specifying a NULL format to Float functions default them to "%.3f" to be

2
imgui.h

@ -61,7 +61,7 @@ Index of this file:
// Version // Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
#define IMGUI_VERSION "1.83 WIP" #define IMGUI_VERSION "1.83 WIP"
#define IMGUI_VERSION_NUM 18203 #define IMGUI_VERSION_NUM 18204
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
#define IMGUI_HAS_TABLE #define IMGUI_HAS_TABLE

27
imgui_tables.cpp

@ -470,10 +470,14 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
table->MemoryCompacted = false; table->MemoryCompacted = false;
// Setup memory buffer (clear data if columns count changed) // Setup memory buffer (clear data if columns count changed)
const int stored_size = table->Columns.size(); ImGuiTableColumn* old_columns_to_preserve = NULL;
if (stored_size != 0 && stored_size != columns_count) void* old_columns_raw_data = NULL;
{ const int old_columns_count = table->Columns.size();
IM_FREE(table->RawData); if (old_columns_count != 0 && old_columns_count != columns_count)
{
// Attempt to preserve width on column count change (#4046)
old_columns_to_preserve = table->Columns.Data;
old_columns_raw_data = table->RawData;
table->RawData = NULL; table->RawData = NULL;
} }
if (table->RawData == NULL) if (table->RawData == NULL)
@ -496,14 +500,24 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
for (int n = 0; n < columns_count; n++) for (int n = 0; n < columns_count; n++)
{ {
ImGuiTableColumn* column = &table->Columns[n]; ImGuiTableColumn* column = &table->Columns[n];
if (old_columns_to_preserve && n < old_columns_count)
{
// FIXME: We don't attempt to preserve column order in this path.
*column = old_columns_to_preserve[n];
}
else
{
float width_auto = column->WidthAuto; float width_auto = column->WidthAuto;
*column = ImGuiTableColumn(); *column = ImGuiTableColumn();
column->WidthAuto = width_auto; column->WidthAuto = width_auto;
column->IsPreserveWidthAuto = true; // Preserve WidthAuto when reinitializing a live table: not technically necessary but remove a visible flicker column->IsPreserveWidthAuto = true; // Preserve WidthAuto when reinitializing a live table: not technically necessary but remove a visible flicker
column->DisplayOrder = table->DisplayOrderToIndex[n] = (ImGuiTableColumnIdx)n;
column->IsEnabled = column->IsEnabledNextFrame = true; column->IsEnabled = column->IsEnabledNextFrame = true;
} }
column->DisplayOrder = table->DisplayOrderToIndex[n] = (ImGuiTableColumnIdx)n;
}
} }
if (old_columns_raw_data)
IM_FREE(old_columns_raw_data);
// Load settings // Load settings
if (table->IsSettingsRequestLoad) if (table->IsSettingsRequestLoad)
@ -3350,6 +3364,9 @@ static void TableSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandle
for (int column_n = 0; column_n < settings->ColumnsCount; column_n++, column++) for (int column_n = 0; column_n < settings->ColumnsCount; column_n++, column++)
{ {
// "Column 0 UserID=0x42AD2D21 Width=100 Visible=1 Order=0 Sort=0v" // "Column 0 UserID=0x42AD2D21 Width=100 Visible=1 Order=0 Sort=0v"
bool save_column = column->UserID != 0 || save_size || save_visible || save_order || (save_sort && column->SortOrder != -1);
if (!save_column)
continue;
buf->appendf("Column %-2d", column_n); buf->appendf("Column %-2d", column_n);
if (column->UserID != 0) buf->appendf(" UserID=%08X", column->UserID); if (column->UserID != 0) buf->appendf(" UserID=%08X", column->UserID);
if (save_size && column->IsStretch) buf->appendf(" Weight=%.4f", column->WidthOrWeight); if (save_size && column->IsStretch) buf->appendf(" Weight=%.4f", column->WidthOrWeight);

Loading…
Cancel
Save