Tables: Calculating ideal total width, some renaming, comments. Clarify that inner_width is unused with ScrollX=0. Clip many comments to 120 columns.

This commit is contained in:
omar
2020-05-12 17:23:10 +02:00
committed by ocornut
parent b7ff85d9ad
commit 9f43aae226
4 changed files with 168 additions and 133 deletions
+2 -2
View File
@@ -10515,7 +10515,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
else if (rect_type == TRT_ColumnsRect) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->MinX, table->InnerClipRect.Min.y, c->MaxX, table->InnerClipRect.Min.y + table->LastOuterHeight); }
else if (rect_type == TRT_ColumnsClipRect) { ImGuiTableColumn* c = &table->Columns[n]; return c->ClipRect; }
else if (rect_type == TRT_ColumnsContentHeadersUsed) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->MinX, table->InnerClipRect.Min.y, c->MinX + c->ContentWidthHeadersUsed, table->InnerClipRect.Min.y + table->LastFirstRowHeight); } // Note: y1/y2 not always accurate
else if (rect_type == TRT_ColumnsContentHeadersIdeal) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->MinX, table->InnerClipRect.Min.y, c->MinX + c->ContentWidthHeadersDesired, table->InnerClipRect.Min.y + table->LastFirstRowHeight); } // "
else if (rect_type == TRT_ColumnsContentHeadersIdeal) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->MinX, table->InnerClipRect.Min.y, c->MinX + c->ContentWidthHeadersIdeal, table->InnerClipRect.Min.y + table->LastFirstRowHeight); } // "
else if (rect_type == TRT_ColumnsContentRowsFrozen) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->MinX, table->InnerClipRect.Min.y, c->MinX + c->ContentWidthRowsFrozen, table->InnerClipRect.Min.y + table->LastFirstRowHeight); } // "
else if (rect_type == TRT_ColumnsContentRowsUnfrozen) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->MinX, table->InnerClipRect.Min.y + table->LastFirstRowHeight, c->MinX + c->ContentWidthRowsUnfrozen, table->InnerClipRect.Max.y); } // "
IM_ASSERT(0);
@@ -10573,7 +10573,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
for (int table_n = 0; table_n < g.Tables.GetSize(); table_n++)
{
ImGuiTable* table = g.Tables.GetByIndex(table_n);
if (table->LastFrameActive < g.FrameCount - 1 || table->OuterWindow != g.NavWindow)
if (table->LastFrameActive < g.FrameCount - 1 || (table->OuterWindow != g.NavWindow && table->InnerWindow != g.NavWindow))
continue;
BulletText("Table 0x%08X (%d columns, in '%s')", table->ID, table->ColumnsCount, table->OuterWindow->Name);
+4 -8
View File
@@ -3680,8 +3680,8 @@ static void ShowDemoWindowTables()
ImGui::CheckboxFlags("_NoSortDescending", (unsigned int*)&column_flags[column], ImGuiTableColumnFlags_NoSortDescending);
ImGui::CheckboxFlags("_PreferSortAscending", (unsigned int*)&column_flags[column], ImGuiTableColumnFlags_PreferSortAscending);
ImGui::CheckboxFlags("_PreferSortDescending", (unsigned int*)&column_flags[column], ImGuiTableColumnFlags_PreferSortDescending);
ImGui::CheckboxFlags("_IndentEnable", (unsigned int*)&column_flags[column], ImGuiTableColumnFlags_IndentEnable);
ImGui::CheckboxFlags("_IndentDisable", (unsigned int*)&column_flags[column], ImGuiTableColumnFlags_IndentDisable);
ImGui::CheckboxFlags("_IndentEnable", (unsigned int*)&column_flags[column], ImGuiTableColumnFlags_IndentEnable); ImGui::SameLine(); HelpMarker("Default for column 0");
ImGui::CheckboxFlags("_IndentDisable", (unsigned int*)&column_flags[column], ImGuiTableColumnFlags_IndentDisable); ImGui::SameLine(); HelpMarker("Default for column >0");
ImGui::PopID();
ImGui::PopStyleVar(2);
}
@@ -4089,7 +4089,6 @@ static void ShowDemoWindowTables()
static int items_count = IM_ARRAYSIZE(template_items_names);
static ImVec2 outer_size_value = ImVec2(0, 250);
static float row_min_height = 0.0f; // Auto
static float inner_width_without_scroll = 0.0f; // Fill
static float inner_width_with_scroll = 0.0f; // Auto-extend
static bool outer_size_enabled = true;
static bool lock_first_column_visibility = false;
@@ -4171,10 +4170,7 @@ static void ShowDemoWindowTables()
// From a user point of view we will tend to use 'inner_width' differently depending on whether our table is embedding scrolling.
// To facilitate experimentation we expose two values and will select the right one depending on active flags.
if (flags & ImGuiTableFlags_ScrollX)
ImGui::DragFloat("inner_width (when ScrollX active)", &inner_width_with_scroll, 1.0f, 0.0f, FLT_MAX);
else
ImGui::DragFloat("inner_width (when ScrollX inactive)", &inner_width_without_scroll, 1.0f, 0.0f, FLT_MAX);
ImGui::DragFloat("inner_width (when ScrollX active)", &inner_width_with_scroll, 1.0f, 0.0f, FLT_MAX);
ImGui::DragFloat("row_min_height", &row_min_height, 1.0f, 0.0f, FLT_MAX);
ImGui::SameLine(); HelpMarker("Specify height of the Selectable item.");
ImGui::DragInt("items_count", &items_count, 0.1f, 0, 5000);
@@ -4213,7 +4209,7 @@ static void ShowDemoWindowTables()
ImVec2 table_scroll_cur, table_scroll_max; // For debug display
const ImDrawList* table_draw_list = NULL; // "
const float inner_width_to_use = (flags & ImGuiTableFlags_ScrollX) ? inner_width_with_scroll : inner_width_without_scroll;
const float inner_width_to_use = (flags & ImGuiTableFlags_ScrollX) ? inner_width_with_scroll : 0.0f;
if (ImGui::BeginTable("##table", 6, flags, outer_size_enabled ? outer_size_value : ImVec2(0, 0), inner_width_to_use))
{
// Declare columns
+7 -6
View File
@@ -1905,11 +1905,11 @@ struct ImGuiTableColumn
float ContentMaxPosRowsFrozen; // Submitted contents absolute maximum position, from which we can infer width.
float ContentMaxPosRowsUnfrozen; // (kept as float because we need to manipulate those between each cell change)
float ContentMaxPosHeadersUsed;
float ContentMaxPosHeadersDesired;
float ContentMaxPosHeadersIdeal;
ImS16 ContentWidthRowsFrozen; // Contents width. Because row freezing is not correlated with headers/not-headers we need all 4 variants (ImDrawCmd merging uses different data than alignment code).
ImS16 ContentWidthRowsUnfrozen; // (encoded as ImS16 because we actually rarely use those width)
ImS16 ContentWidthHeadersUsed; // TableHeader() automatically softclip itself + report ideal desired size, to avoid creating extraneous draw calls
ImS16 ContentWidthHeadersDesired;
ImS16 ContentWidthHeadersIdeal;
ImS16 NameOffset; // Offset into parent ColumnsNames[]
bool IsActive; // Is the column not marked Hidden by the user (regardless of clipping). We're not calling this "Visible" here because visibility also depends on clipping.
bool IsActiveNextFrame;
@@ -1982,7 +1982,8 @@ struct ImGuiTable
float LastOuterHeight; // Outer height from last frame
float LastFirstRowHeight; // Height of first row from last frame
float ColumnsTotalWidth;
float InnerWidth;
float InnerWidth; // User value passed to BeginTable(), see comments at the top of BeginTable() for details.
float IdealTotalWidth; // Sum of ideal column width for nothing to be clipped
float ResizedColumnNextWidth;
ImRect OuterRect; // Note: OuterRect.Max.y is often FLT_MAX until EndTable(), unless a height has been specified in BeginTable().
ImRect WorkRect;
@@ -2264,14 +2265,14 @@ namespace ImGui
IMGUI_API void TableBeginCell(ImGuiTable* table, int column_n);
IMGUI_API void TableEndCell(ImGuiTable* table);
IMGUI_API ImRect TableGetCellRect();
IMGUI_API const char* TableGetColumnName(ImGuiTable* table, int column_n);
IMGUI_API ImGuiID TableGetColumnResizeID(ImGuiTable* table, int column_n, int instance_no = 0);
IMGUI_API const char* TableGetColumnName(const ImGuiTable* table, int column_n);
IMGUI_API ImGuiID TableGetColumnResizeID(const ImGuiTable* table, int column_n, int instance_no = 0);
IMGUI_API void TableSetColumnAutofit(ImGuiTable* table, int column_n);
IMGUI_API void PushTableBackground();
IMGUI_API void PopTableBackground();
IMGUI_API void TableLoadSettings(ImGuiTable* table);
IMGUI_API void TableSaveSettings(ImGuiTable* table);
IMGUI_API ImGuiTableSettings* TableFindSettings(ImGuiTable* table);
IMGUI_API ImGuiTableSettings* TableFindSettings(const ImGuiTable* table);
IMGUI_API void* TableSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name);
IMGUI_API void TableSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line);
IMGUI_API void TableSettingsHandler_WriteAll(ImGuiContext*, ImGuiSettingsHandler*, ImGuiTextBuffer* buf);
+155 -117
View File
File diff suppressed because it is too large Load Diff