189#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
190#define _CRT_SECURE_NO_WARNINGS
193#ifndef IMGUI_DEFINE_MATH_OPERATORS
194#define IMGUI_DEFINE_MATH_OPERATORS
199#include "imgui_internal.h"
206#pragma warning (disable: 4127)
207#pragma warning (disable: 4996)
208#if defined(_MSC_VER) && _MSC_VER >= 1922
209#pragma warning (disable: 5054)
211#pragma warning (disable: 26451)
212#pragma warning (disable: 26812)
216#if defined(__clang__)
217#if __has_warning("-Wunknown-warning-option")
218#pragma clang diagnostic ignored "-Wunknown-warning-option"
220#pragma clang diagnostic ignored "-Wunknown-pragmas"
221#pragma clang diagnostic ignored "-Wold-style-cast"
222#pragma clang diagnostic ignored "-Wfloat-equal"
223#pragma clang diagnostic ignored "-Wformat-nonliteral"
224#pragma clang diagnostic ignored "-Wsign-conversion"
225#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
226#pragma clang diagnostic ignored "-Wdouble-promotion"
227#pragma clang diagnostic ignored "-Wenum-enum-conversion"
228#pragma clang diagnostic ignored "-Wdeprecated-enum-enum-conversion"
229#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
230#elif defined(__GNUC__)
231#pragma GCC diagnostic ignored "-Wpragmas"
232#pragma GCC diagnostic ignored "-Wformat-nonliteral"
233#pragma GCC diagnostic ignored "-Wclass-memaccess"
254static const int TABLE_DRAW_CHANNEL_BG0 = 0;
255static const int TABLE_DRAW_CHANNEL_BG2_FROZEN = 1;
256static const int TABLE_DRAW_CHANNEL_NOCLIP = 2;
257static const float TABLE_BORDER_SIZE = 1.0f;
258static const float TABLE_RESIZE_SEPARATOR_HALF_THICKNESS = 4.0f;
259static const float TABLE_RESIZE_SEPARATOR_FEEDBACK_TIMER = 0.06f;
262inline ImGuiTableFlags
TableFixFlags(ImGuiTableFlags flags, ImGuiWindow* outer_window)
265 if ((flags & ImGuiTableFlags_SizingMask_) == 0)
266 flags |= ((flags & ImGuiTableFlags_ScrollX) || (outer_window->Flags & ImGuiWindowFlags_AlwaysAutoResize)) ? ImGuiTableFlags_SizingFixedFit : ImGuiTableFlags_SizingStretchSame;
269 if ((flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedSame)
270 flags |= ImGuiTableFlags_NoKeepColumnsVisible;
273 if (flags & ImGuiTableFlags_Resizable)
274 flags |= ImGuiTableFlags_BordersInnerV;
277 if (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY))
278 flags &= ~(ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_NoHostExtendY);
281 if (flags & ImGuiTableFlags_NoBordersInBodyUntilResize)
282 flags &= ~ImGuiTableFlags_NoBordersInBody;
285 if ((flags & (ImGuiTableFlags_Resizable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Sortable)) == 0)
286 flags |= ImGuiTableFlags_NoSavedSettings;
289 if (outer_window->RootWindow->Flags & ImGuiWindowFlags_NoSavedSettings)
290 flags |= ImGuiTableFlags_NoSavedSettings;
295ImGuiTable* ImGui::TableFindByID(ImGuiID
id)
298 return g.Tables.GetByKey(
id);
302bool ImGui::BeginTable(
const char* str_id,
int columns_count, ImGuiTableFlags flags,
const ImVec2& outer_size,
float inner_width)
304 ImGuiID
id = GetID(str_id);
305 return BeginTableEx(str_id,
id, columns_count, flags, outer_size, inner_width);
308bool ImGui::BeginTableEx(
const char* name, ImGuiID
id,
int columns_count, ImGuiTableFlags flags,
const ImVec2& outer_size,
float inner_width)
311 ImGuiWindow* outer_window = GetCurrentWindow();
312 if (outer_window->SkipItems)
316 IM_ASSERT(columns_count > 0 && columns_count < IMGUI_TABLE_MAX_COLUMNS);
317 if (flags & ImGuiTableFlags_ScrollX)
318 IM_ASSERT(inner_width >= 0.0f);
321 const bool use_child_window = (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) != 0;
322 const ImVec2 avail_size = GetContentRegionAvail();
323 const ImVec2 actual_outer_size = CalcItemSize(outer_size, ImMax(avail_size.x, 1.0f), use_child_window ? ImMax(avail_size.y, 1.0f) : 0.0f);
324 const ImRect outer_rect(outer_window->DC.CursorPos, outer_window->DC.CursorPos + actual_outer_size);
325 const bool outer_window_is_measuring_size = (outer_window->AutoFitFramesX > 0) || (outer_window->AutoFitFramesY > 0);
326 if (use_child_window && IsClippedEx(outer_rect, 0) && !outer_window_is_measuring_size)
328 ItemSize(outer_rect);
333 if (
g.DebugBreakInTable ==
id)
337 ImGuiTable* table =
g.Tables.GetOrAddByKey(
id);
338 const ImGuiTableFlags table_last_flags = table->Flags;
341 const int table_idx =
g.Tables.GetIndex(table);
342 if (++
g.TablesTempDataStacked >
g.TablesTempData.Size)
343 g.TablesTempData.resize(
g.TablesTempDataStacked, ImGuiTableTempData());
344 ImGuiTableTempData* temp_data = table->TempData = &
g.TablesTempData[
g.TablesTempDataStacked - 1];
345 temp_data->TableIndex = table_idx;
346 table->DrawSplitter = &table->TempData->DrawSplitter;
347 table->DrawSplitter->Clear();
350 table->IsDefaultSizingPolicy = (flags & ImGuiTableFlags_SizingMask_) == 0;
354 const int previous_frame_active = table->LastFrameActive;
355 const int instance_no = (previous_frame_active !=
g.FrameCount) ? 0 : table->InstanceCurrent + 1;
357 table->Flags = flags;
358 table->LastFrameActive =
g.FrameCount;
359 table->OuterWindow = table->InnerWindow = outer_window;
360 table->ColumnsCount = columns_count;
361 table->IsLayoutLocked =
false;
362 table->InnerWidth = inner_width;
363 temp_data->UserOuterSize = outer_size;
367 table->InstanceCurrent = (ImS16)instance_no;
370 IM_ASSERT(table->ColumnsCount == columns_count &&
"BeginTable(): Cannot change columns count mid-frame while preserving same ID");
371 if (table->InstanceDataExtra.Size < instance_no)
372 table->InstanceDataExtra.push_back(ImGuiTableInstanceData());
373 instance_id = GetIDWithSeed(instance_no, GetIDWithSeed(
"##Instances", NULL,
id));
379 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
380 table_instance->TableInstanceID = instance_id;
383 if (use_child_window)
387 ImVec2 override_content_size(FLT_MAX, FLT_MAX);
388 if ((flags & ImGuiTableFlags_ScrollX) && !(flags & ImGuiTableFlags_ScrollY))
389 override_content_size.y = FLT_MIN;
395 if ((flags & ImGuiTableFlags_ScrollX) && inner_width > 0.0f)
396 override_content_size.x = inner_width;
398 if (override_content_size.x != FLT_MAX || override_content_size.y != FLT_MAX)
399 SetNextWindowContentSize(ImVec2(override_content_size.x != FLT_MAX ? override_content_size.x : 0.0f, override_content_size.y != FLT_MAX ? override_content_size.y : 0.0f));
402 if ((table_last_flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) == 0)
403 SetNextWindowScroll(ImVec2(0.0f, 0.0f));
406 ImGuiWindowFlags child_flags = (flags & ImGuiTableFlags_ScrollX) ? ImGuiWindowFlags_HorizontalScrollbar : ImGuiWindowFlags_None;
407 BeginChildEx(name, instance_id, outer_rect.GetSize(),
false, child_flags);
408 table->InnerWindow =
g.CurrentWindow;
409 table->WorkRect = table->InnerWindow->WorkRect;
410 table->OuterRect = table->InnerWindow->Rect();
411 table->InnerRect = table->InnerWindow->InnerRect;
412 IM_ASSERT(table->InnerWindow->WindowPadding.x == 0.0f && table->InnerWindow->WindowPadding.y == 0.0f && table->InnerWindow->WindowBorderSize == 0.0f);
415 if (table->InnerWindow->SkipItems && outer_window_is_measuring_size)
416 table->InnerWindow->SkipItems =
false;
419 if (instance_no == 0)
421 table->HasScrollbarYPrev = table->HasScrollbarYCurr;
422 table->HasScrollbarYCurr =
false;
424 table->HasScrollbarYCurr |= table->InnerWindow->ScrollbarY;
430 table->WorkRect = table->OuterRect = table->InnerRect = outer_rect;
436 PushOverrideID(instance_id);
439 ImGuiWindow* inner_window = table->InnerWindow;
440 table->HostIndentX = inner_window->DC.Indent.x;
441 table->HostClipRect = inner_window->ClipRect;
442 table->HostSkipItems = inner_window->SkipItems;
443 temp_data->HostBackupWorkRect = inner_window->WorkRect;
444 temp_data->HostBackupParentWorkRect = inner_window->ParentWorkRect;
445 temp_data->HostBackupColumnsOffset = outer_window->DC.ColumnsOffset;
446 temp_data->HostBackupPrevLineSize = inner_window->DC.PrevLineSize;
447 temp_data->HostBackupCurrLineSize = inner_window->DC.CurrLineSize;
448 temp_data->HostBackupCursorMaxPos = inner_window->DC.CursorMaxPos;
449 temp_data->HostBackupItemWidth = outer_window->DC.ItemWidth;
450 temp_data->HostBackupItemWidthStackSize = outer_window->DC.ItemWidthStack.Size;
451 inner_window->DC.PrevLineSize = inner_window->DC.CurrLineSize = ImVec2(0.0f, 0.0f);
457 if (inner_window != outer_window)
459 if (flags & ImGuiTableFlags_BordersOuterV)
460 table->HostClipRect.Min.x = ImMin(table->HostClipRect.Min.x + TABLE_BORDER_SIZE, table->HostClipRect.Max.x);
461 if (flags & ImGuiTableFlags_BordersOuterH)
462 table->HostClipRect.Min.y = ImMin(table->HostClipRect.Min.y + TABLE_BORDER_SIZE, table->HostClipRect.Max.y);
470 const bool pad_outer_x = (flags & ImGuiTableFlags_NoPadOuterX) ?
false : (flags & ImGuiTableFlags_PadOuterX) ? true : (flags & ImGuiTableFlags_BordersOuterV) != 0;
471 const bool pad_inner_x = (flags & ImGuiTableFlags_NoPadInnerX) ?
false : true;
472 const float inner_spacing_for_border = (flags & ImGuiTableFlags_BordersInnerV) ? TABLE_BORDER_SIZE : 0.0f;
473 const float inner_spacing_explicit = (pad_inner_x && (flags & ImGuiTableFlags_BordersInnerV) == 0) ?
g.Style.CellPadding.x : 0.0f;
474 const float inner_padding_explicit = (pad_inner_x && (flags & ImGuiTableFlags_BordersInnerV) != 0) ?
g.Style.CellPadding.x : 0.0f;
475 table->CellSpacingX1 = inner_spacing_explicit + inner_spacing_for_border;
476 table->CellSpacingX2 = inner_spacing_explicit;
477 table->CellPaddingX = inner_padding_explicit;
479 const float outer_padding_for_border = (flags & ImGuiTableFlags_BordersOuterV) ? TABLE_BORDER_SIZE : 0.0f;
480 const float outer_padding_explicit = pad_outer_x ?
g.Style.CellPadding.x : 0.0f;
481 table->OuterPaddingX = (outer_padding_for_border + outer_padding_explicit) - table->CellPaddingX;
483 table->CurrentColumn = -1;
484 table->CurrentRow = -1;
485 table->RowBgColorCounter = 0;
486 table->LastRowFlags = ImGuiTableRowFlags_None;
487 table->InnerClipRect = (inner_window == outer_window) ? table->WorkRect : inner_window->ClipRect;
488 table->InnerClipRect.ClipWith(table->WorkRect);
489 table->InnerClipRect.ClipWithFull(table->HostClipRect);
490 table->InnerClipRect.Max.y = (flags & ImGuiTableFlags_NoHostExtendY) ? ImMin(table->InnerClipRect.Max.y, inner_window->WorkRect.Max.y) : inner_window->ClipRect.Max.y;
492 table->RowPosY1 = table->RowPosY2 = table->WorkRect.Min.y;
493 table->RowTextBaseline = 0.0f;
494 table->RowCellPaddingY = 0.0f;
495 table->FreezeRowsRequest = table->FreezeRowsCount = 0;
496 table->FreezeColumnsRequest = table->FreezeColumnsCount = 0;
497 table->IsUnfrozenRows =
true;
498 table->DeclColumnsCount = table->AngledHeadersCount = 0;
499 if (previous_frame_active + 1 <
g.FrameCount)
500 table->IsActiveIdInTable =
false;
501 temp_data->AngledHeadersExtraWidth = 0.0f;
504 table->BorderColorStrong = GetColorU32(ImGuiCol_TableBorderStrong);
505 table->BorderColorLight = GetColorU32(ImGuiCol_TableBorderLight);
508 g.CurrentTable = table;
509 outer_window->DC.NavIsScrollPushableX =
false;
510 outer_window->DC.CurrentTableIdx = table_idx;
511 if (inner_window != outer_window)
512 inner_window->DC.CurrentTableIdx = table_idx;
514 if ((table_last_flags & ImGuiTableFlags_Reorderable) && (flags & ImGuiTableFlags_Reorderable) == 0)
515 table->IsResetDisplayOrderRequest =
true;
518 if (table_idx >=
g.TablesLastTimeActive.Size)
519 g.TablesLastTimeActive.resize(table_idx + 1, -1.0f);
520 g.TablesLastTimeActive[table_idx] = (float)
g.Time;
521 temp_data->LastTimeActive = (float)
g.Time;
522 table->MemoryCompacted =
false;
525 ImGuiTableColumn* old_columns_to_preserve = NULL;
526 void* old_columns_raw_data = NULL;
527 const int old_columns_count = table->Columns.size();
528 if (old_columns_count != 0 && old_columns_count != columns_count)
531 old_columns_to_preserve = table->Columns.Data;
532 old_columns_raw_data = table->RawData;
533 table->RawData = NULL;
535 if (table->RawData == NULL)
537 TableBeginInitMemory(table, columns_count);
538 table->IsInitializing = table->IsSettingsRequestLoad =
true;
540 if (table->IsResetAllRequest)
541 TableResetSettings(table);
542 if (table->IsInitializing)
545 table->SettingsOffset = -1;
546 table->IsSortSpecsDirty =
true;
547 table->InstanceInteracted = -1;
548 table->ContextPopupColumn = -1;
549 table->ReorderColumn = table->ResizedColumn = table->LastResizedColumn = -1;
550 table->AutoFitSingleColumn = -1;
551 table->HoveredColumnBody = table->HoveredColumnBorder = -1;
552 for (
int n = 0; n < columns_count; n++)
554 ImGuiTableColumn* column = &table->Columns[n];
555 if (old_columns_to_preserve && n < old_columns_count)
558 *column = old_columns_to_preserve[n];
562 float width_auto = column->WidthAuto;
563 *column = ImGuiTableColumn();
564 column->WidthAuto = width_auto;
565 column->IsPreserveWidthAuto =
true;
566 column->IsEnabled = column->IsUserEnabled = column->IsUserEnabledNextFrame =
true;
568 column->DisplayOrder = table->DisplayOrderToIndex[n] = (ImGuiTableColumnIdx)n;
571 if (old_columns_raw_data)
572 IM_FREE(old_columns_raw_data);
575 if (table->IsSettingsRequestLoad)
576 TableLoadSettings(table);
583 const float new_ref_scale_unit =
g.FontSize;
584 if (table->RefScale != 0.0f && table->RefScale != new_ref_scale_unit)
586 const float scale_factor = new_ref_scale_unit / table->RefScale;
588 for (
int n = 0; n < columns_count; n++)
589 table->Columns[n].WidthRequest = table->Columns[n].WidthRequest * scale_factor;
591 table->RefScale = new_ref_scale_unit;
596 inner_window->SkipItems =
true;
600 if (table->ColumnsNames.Buf.Size > 0)
601 table->ColumnsNames.Buf.resize(0);
604 TableBeginApplyRequests(table);
618void ImGui::TableBeginInitMemory(ImGuiTable* table,
int columns_count)
621 const int columns_bit_array_size = (int)ImBitArrayGetStorageSizeInBytes(columns_count);
622 ImSpanAllocator<6> span_allocator;
623 span_allocator.Reserve(0, columns_count *
sizeof(ImGuiTableColumn));
624 span_allocator.Reserve(1, columns_count *
sizeof(ImGuiTableColumnIdx));
625 span_allocator.Reserve(2, columns_count *
sizeof(ImGuiTableCellData), 4);
626 for (
int n = 3; n < 6; n++)
627 span_allocator.Reserve(n, columns_bit_array_size);
628 table->RawData = IM_ALLOC(span_allocator.GetArenaSizeInBytes());
629 memset(table->RawData, 0, span_allocator.GetArenaSizeInBytes());
630 span_allocator.SetArenaBasePtr(table->RawData);
631 span_allocator.GetSpan(0, &table->Columns);
632 span_allocator.GetSpan(1, &table->DisplayOrderToIndex);
633 span_allocator.GetSpan(2, &table->RowCellData);
634 table->EnabledMaskByDisplayOrder = (ImU32*)span_allocator.GetSpanPtrBegin(3);
635 table->EnabledMaskByIndex = (ImU32*)span_allocator.GetSpanPtrBegin(4);
636 table->VisibleMaskByIndex = (ImU32*)span_allocator.GetSpanPtrBegin(5);
640void ImGui::TableBeginApplyRequests(ImGuiTable* table)
645 if (table->InstanceCurrent == 0)
647 if (table->ResizedColumn != -1 && table->ResizedColumnNextWidth != FLT_MAX)
648 TableSetColumnWidth(table->ResizedColumn, table->ResizedColumnNextWidth);
649 table->LastResizedColumn = table->ResizedColumn;
650 table->ResizedColumnNextWidth = FLT_MAX;
651 table->ResizedColumn = -1;
655 if (table->AutoFitSingleColumn != -1)
657 TableSetColumnWidth(table->AutoFitSingleColumn, table->Columns[table->AutoFitSingleColumn].WidthAuto);
658 table->AutoFitSingleColumn = -1;
664 if (table->InstanceCurrent == 0)
666 if (table->HeldHeaderColumn == -1 && table->ReorderColumn != -1)
667 table->ReorderColumn = -1;
668 table->HeldHeaderColumn = -1;
669 if (table->ReorderColumn != -1 && table->ReorderColumnDir != 0)
675 const int reorder_dir = table->ReorderColumnDir;
676 IM_ASSERT(reorder_dir == -1 || reorder_dir == +1);
677 IM_ASSERT(table->Flags & ImGuiTableFlags_Reorderable);
678 ImGuiTableColumn* src_column = &table->Columns[table->ReorderColumn];
679 ImGuiTableColumn* dst_column = &table->Columns[(reorder_dir == -1) ? src_column->PrevEnabledColumn : src_column->NextEnabledColumn];
680 IM_UNUSED(dst_column);
681 const int src_order = src_column->DisplayOrder;
682 const int dst_order = dst_column->DisplayOrder;
683 src_column->DisplayOrder = (ImGuiTableColumnIdx)dst_order;
684 for (
int order_n = src_order + reorder_dir; order_n != dst_order + reorder_dir; order_n += reorder_dir)
685 table->Columns[table->DisplayOrderToIndex[order_n]].DisplayOrder -= (ImGuiTableColumnIdx)reorder_dir;
686 IM_ASSERT(dst_column->DisplayOrder == dst_order - reorder_dir);
689 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
690 table->DisplayOrderToIndex[table->Columns[column_n].DisplayOrder] = (ImGuiTableColumnIdx)column_n;
691 table->ReorderColumnDir = 0;
692 table->IsSettingsDirty =
true;
697 if (table->IsResetDisplayOrderRequest)
699 for (
int n = 0; n < table->ColumnsCount; n++)
700 table->DisplayOrderToIndex[n] = table->Columns[n].DisplayOrder = (ImGuiTableColumnIdx)n;
701 table->IsResetDisplayOrderRequest =
false;
702 table->IsSettingsDirty =
true;
707static void TableSetupColumnFlags(ImGuiTable* table, ImGuiTableColumn* column, ImGuiTableColumnFlags flags_in)
709 ImGuiTableColumnFlags flags = flags_in;
712 if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0)
714 const ImGuiTableFlags table_sizing_policy = (table->Flags & ImGuiTableFlags_SizingMask_);
715 if (table_sizing_policy == ImGuiTableFlags_SizingFixedFit || table_sizing_policy == ImGuiTableFlags_SizingFixedSame)
716 flags |= ImGuiTableColumnFlags_WidthFixed;
718 flags |= ImGuiTableColumnFlags_WidthStretch;
722 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiTableColumnFlags_WidthMask_));
726 if ((table->Flags & ImGuiTableFlags_Resizable) == 0)
727 flags |= ImGuiTableColumnFlags_NoResize;
730 if ((flags & ImGuiTableColumnFlags_NoSortAscending) && (flags & ImGuiTableColumnFlags_NoSortDescending))
731 flags |= ImGuiTableColumnFlags_NoSort;
734 if ((flags & ImGuiTableColumnFlags_IndentMask_) == 0)
735 flags |= (table->Columns.index_from_ptr(column) == 0) ? ImGuiTableColumnFlags_IndentEnable : ImGuiTableColumnFlags_IndentDisable;
743 column->Flags = flags | (column->Flags & ImGuiTableColumnFlags_StatusMask_);
746 column->SortDirectionsAvailCount = column->SortDirectionsAvailMask = column->SortDirectionsAvailList = 0;
747 if (table->Flags & ImGuiTableFlags_Sortable)
749 int count = 0, mask = 0, list = 0;
750 if ((flags & ImGuiTableColumnFlags_PreferSortAscending) != 0 && (flags & ImGuiTableColumnFlags_NoSortAscending) == 0) { mask |= 1 << ImGuiSortDirection_Ascending; list |= ImGuiSortDirection_Ascending << (
count << 1);
count++; }
751 if ((flags & ImGuiTableColumnFlags_PreferSortDescending) != 0 && (flags & ImGuiTableColumnFlags_NoSortDescending) == 0) { mask |= 1 << ImGuiSortDirection_Descending; list |= ImGuiSortDirection_Descending << (
count << 1);
count++; }
752 if ((flags & ImGuiTableColumnFlags_PreferSortAscending) == 0 && (flags & ImGuiTableColumnFlags_NoSortAscending) == 0) { mask |= 1 << ImGuiSortDirection_Ascending; list |= ImGuiSortDirection_Ascending << (
count << 1);
count++; }
753 if ((flags & ImGuiTableColumnFlags_PreferSortDescending) == 0 && (flags & ImGuiTableColumnFlags_NoSortDescending) == 0) { mask |= 1 << ImGuiSortDirection_Descending; list |= ImGuiSortDirection_Descending << (
count << 1);
count++; }
754 if ((table->Flags & ImGuiTableFlags_SortTristate) ||
count == 0) { mask |= 1 << ImGuiSortDirection_None;
count++; }
755 column->SortDirectionsAvailList = (ImU8)list;
756 column->SortDirectionsAvailMask = (ImU8)mask;
757 column->SortDirectionsAvailCount = (ImU8)count;
758 ImGui::TableFixColumnSortDirection(table, column);
766void ImGui::TableUpdateLayout(ImGuiTable* table)
769 IM_ASSERT(table->IsLayoutLocked ==
false);
771 const ImGuiTableFlags table_sizing_policy = (table->Flags & ImGuiTableFlags_SizingMask_);
772 table->IsDefaultDisplayOrder =
true;
773 table->ColumnsEnabledCount = 0;
774 ImBitArrayClearAllBits(table->EnabledMaskByIndex, table->ColumnsCount);
775 ImBitArrayClearAllBits(table->EnabledMaskByDisplayOrder, table->ColumnsCount);
776 table->LeftMostEnabledColumn = -1;
777 table->MinColumnWidth = ImMax(1.0f,
g.Style.FramePadding.x * 1.0f);
782 int count_stretch = 0;
783 int prev_visible_column_idx = -1;
784 bool has_auto_fit_request =
false;
785 bool has_resizable =
false;
786 float stretch_sum_width_auto = 0.0f;
787 float fixed_max_width_auto = 0.0f;
788 for (
int order_n = 0; order_n < table->ColumnsCount; order_n++)
790 const int column_n = table->DisplayOrderToIndex[order_n];
791 if (column_n != order_n)
792 table->IsDefaultDisplayOrder =
false;
793 ImGuiTableColumn* column = &table->Columns[column_n];
798 if (table->DeclColumnsCount <= column_n)
800 TableSetupColumnFlags(table, column, ImGuiTableColumnFlags_None);
801 column->NameOffset = -1;
803 column->InitStretchWeightOrWidth = -1.0f;
807 if (!(table->Flags & ImGuiTableFlags_Hideable) || (column->Flags & ImGuiTableColumnFlags_NoHide))
808 column->IsUserEnabledNextFrame =
true;
809 if (column->IsUserEnabled != column->IsUserEnabledNextFrame)
811 column->IsUserEnabled = column->IsUserEnabledNextFrame;
812 table->IsSettingsDirty =
true;
814 column->IsEnabled = column->IsUserEnabled && (column->Flags & ImGuiTableColumnFlags_Disabled) == 0;
816 if (column->SortOrder != -1 && !column->IsEnabled)
817 table->IsSortSpecsDirty =
true;
818 if (column->SortOrder > 0 && !(table->Flags & ImGuiTableFlags_SortMulti))
819 table->IsSortSpecsDirty =
true;
822 const bool start_auto_fit = (column->Flags & ImGuiTableColumnFlags_WidthFixed) ? (column->WidthRequest < 0.0f) : (column->StretchWeight < 0.0f);
824 column->AutoFitQueue = column->CannotSkipItemsQueue = (1 << 3) - 1;
826 if (!column->IsEnabled)
828 column->IndexWithinEnabledSet = -1;
833 column->PrevEnabledColumn = (ImGuiTableColumnIdx)prev_visible_column_idx;
834 column->NextEnabledColumn = -1;
835 if (prev_visible_column_idx != -1)
836 table->Columns[prev_visible_column_idx].NextEnabledColumn = (ImGuiTableColumnIdx)column_n;
838 table->LeftMostEnabledColumn = (ImGuiTableColumnIdx)column_n;
839 column->IndexWithinEnabledSet = table->ColumnsEnabledCount++;
840 ImBitArraySetBit(table->EnabledMaskByIndex, column_n);
841 ImBitArraySetBit(table->EnabledMaskByDisplayOrder, column->DisplayOrder);
842 prev_visible_column_idx = column_n;
843 IM_ASSERT(column->IndexWithinEnabledSet <= column->DisplayOrder);
847 if (!column->IsPreserveWidthAuto)
848 column->WidthAuto = TableGetColumnWidthAuto(table, column);
851 const bool column_is_resizable = (column->Flags & ImGuiTableColumnFlags_NoResize) == 0;
852 if (column_is_resizable)
853 has_resizable =
true;
854 if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && column->InitStretchWeightOrWidth > 0.0f && !column_is_resizable)
855 column->WidthAuto = column->InitStretchWeightOrWidth;
857 if (column->AutoFitQueue != 0x00)
858 has_auto_fit_request =
true;
859 if (column->Flags & ImGuiTableColumnFlags_WidthStretch)
861 stretch_sum_width_auto += column->WidthAuto;
866 fixed_max_width_auto = ImMax(fixed_max_width_auto, column->WidthAuto);
870 if ((table->Flags & ImGuiTableFlags_Sortable) && table->SortSpecsCount == 0 && !(table->Flags & ImGuiTableFlags_SortTristate))
871 table->IsSortSpecsDirty =
true;
872 table->RightMostEnabledColumn = (ImGuiTableColumnIdx)prev_visible_column_idx;
873 IM_ASSERT(table->LeftMostEnabledColumn >= 0 && table->RightMostEnabledColumn >= 0);
878 if (has_auto_fit_request && table->OuterWindow != table->InnerWindow)
879 table->InnerWindow->SkipItems =
false;
880 if (has_auto_fit_request)
881 table->IsSettingsDirty =
true;
884 float sum_width_requests = 0.0f;
885 float stretch_sum_weights = 0.0f;
886 table->LeftMostStretchedColumn = table->RightMostStretchedColumn = -1;
887 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
889 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
891 ImGuiTableColumn* column = &table->Columns[column_n];
893 const bool column_is_resizable = (column->Flags & ImGuiTableColumnFlags_NoResize) == 0;
894 if (column->Flags & ImGuiTableColumnFlags_WidthFixed)
897 float width_auto = column->WidthAuto;
898 if (table_sizing_policy == ImGuiTableFlags_SizingFixedSame && (column->AutoFitQueue != 0x00 || !column_is_resizable))
899 width_auto = fixed_max_width_auto;
903 if (column->AutoFitQueue != 0x00)
904 column->WidthRequest = width_auto;
905 else if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !column_is_resizable && column->IsRequestOutput)
906 column->WidthRequest = width_auto;
914 if (column->AutoFitQueue > 0x01 && table->IsInitializing && !column->IsPreserveWidthAuto)
915 column->WidthRequest = ImMax(column->WidthRequest, table->MinColumnWidth * 4.0f);
916 sum_width_requests += column->WidthRequest;
921 if (column->AutoFitQueue != 0x00 || column->StretchWeight < 0.0f || !column_is_resizable)
923 if (column->InitStretchWeightOrWidth > 0.0f)
924 column->StretchWeight = column->InitStretchWeightOrWidth;
925 else if (table_sizing_policy == ImGuiTableFlags_SizingStretchProp)
926 column->StretchWeight = (column->WidthAuto / stretch_sum_width_auto) * count_stretch;
928 column->StretchWeight = 1.0f;
931 stretch_sum_weights += column->StretchWeight;
932 if (table->LeftMostStretchedColumn == -1 || table->Columns[table->LeftMostStretchedColumn].DisplayOrder > column->DisplayOrder)
933 table->LeftMostStretchedColumn = (ImGuiTableColumnIdx)column_n;
934 if (table->RightMostStretchedColumn == -1 || table->Columns[table->RightMostStretchedColumn].DisplayOrder < column->DisplayOrder)
935 table->RightMostStretchedColumn = (ImGuiTableColumnIdx)column_n;
937 column->IsPreserveWidthAuto =
false;
938 sum_width_requests += table->CellPaddingX * 2.0f;
940 table->ColumnsEnabledFixedCount = (ImGuiTableColumnIdx)count_fixed;
941 table->ColumnsStretchSumWeights = stretch_sum_weights;
944 const ImRect work_rect = table->WorkRect;
945 const float width_spacings = (table->OuterPaddingX * 2.0f) + (table->CellSpacingX1 + table->CellSpacingX2) * (table->ColumnsEnabledCount - 1);
946 const float width_removed = (table->HasScrollbarYPrev && !table->InnerWindow->ScrollbarY) ?
g.Style.ScrollbarSize : 0.0f;
947 const float width_avail = ImMax(1.0f, (((table->Flags & ImGuiTableFlags_ScrollX) && table->InnerWidth == 0.0f) ? table->InnerClipRect.GetWidth() : work_rect.GetWidth()) - width_removed);
948 const float width_avail_for_stretched_columns = width_avail - width_spacings - sum_width_requests;
949 float width_remaining_for_stretched_columns = width_avail_for_stretched_columns;
950 table->ColumnsGivenWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount;
951 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
953 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
955 ImGuiTableColumn* column = &table->Columns[column_n];
958 if (column->Flags & ImGuiTableColumnFlags_WidthStretch)
960 float weight_ratio = column->StretchWeight / stretch_sum_weights;
961 column->WidthRequest = IM_TRUNC(ImMax(width_avail_for_stretched_columns * weight_ratio, table->MinColumnWidth) + 0.01f);
962 width_remaining_for_stretched_columns -= column->WidthRequest;
967 if (column->NextEnabledColumn == -1 && table->LeftMostStretchedColumn != -1)
968 column->Flags |= ImGuiTableColumnFlags_NoDirectResize_;
971 column->WidthGiven = ImTrunc(ImMax(column->WidthRequest, table->MinColumnWidth));
972 table->ColumnsGivenWidth += column->WidthGiven;
977 if (width_remaining_for_stretched_columns >= 1.0f && !(table->Flags & ImGuiTableFlags_PreciseWidths))
978 for (
int order_n = table->ColumnsCount - 1; stretch_sum_weights > 0.0f && width_remaining_for_stretched_columns >= 1.0f && order_n >= 0; order_n--)
980 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n))
982 ImGuiTableColumn* column = &table->Columns[table->DisplayOrderToIndex[order_n]];
983 if (!(column->Flags & ImGuiTableColumnFlags_WidthStretch))
985 column->WidthRequest += 1.0f;
986 column->WidthGiven += 1.0f;
987 width_remaining_for_stretched_columns -= 1.0f;
995 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
996 table_instance->HoveredRowLast = table_instance->HoveredRowNext;
997 table_instance->HoveredRowNext = -1;
998 table->HoveredColumnBody = table->HoveredColumnBorder = -1;
999 const ImRect mouse_hit_rect(table->OuterRect.Min.x, table->OuterRect.Min.y, table->OuterRect.Max.x, ImMax(table->OuterRect.Max.y, table->OuterRect.Min.y + table_instance->LastOuterHeight));
1000 const ImGuiID backup_active_id =
g.ActiveId;
1002 const bool is_hovering_table = ItemHoverable(mouse_hit_rect, 0, ImGuiItemFlags_None);
1003 g.ActiveId = backup_active_id;
1006 float mouse_skewed_x =
g.IO.MousePos.x;
1007 if (table->AngledHeadersHeight > 0.0f)
1008 if (
g.IO.MousePos.y >= table->OuterRect.Min.y &&
g.IO.MousePos.y <= table->OuterRect.Min.y + table->AngledHeadersHeight)
1009 mouse_skewed_x += ImTrunc((table->OuterRect.Min.y + table->AngledHeadersHeight -
g.IO.MousePos.y) * table->AngledHeadersSlope);
1014 bool has_at_least_one_column_requesting_output =
false;
1015 bool offset_x_frozen = (table->FreezeColumnsCount > 0);
1016 float offset_x = ((table->FreezeColumnsCount > 0) ? table->OuterRect.Min.x : work_rect.Min.x) + table->OuterPaddingX - table->CellSpacingX1;
1017 ImRect host_clip_rect = table->InnerClipRect;
1019 ImBitArrayClearAllBits(table->VisibleMaskByIndex, table->ColumnsCount);
1020 for (
int order_n = 0; order_n < table->ColumnsCount; order_n++)
1022 const int column_n = table->DisplayOrderToIndex[order_n];
1023 ImGuiTableColumn* column = &table->Columns[column_n];
1025 column->NavLayerCurrent = (ImS8)(table->FreezeRowsCount > 0 ? ImGuiNavLayer_Menu : ImGuiNavLayer_Main);
1027 if (offset_x_frozen && table->FreezeColumnsCount == visible_n)
1029 offset_x += work_rect.Min.x - table->OuterRect.Min.x;
1030 offset_x_frozen =
false;
1034 column->Flags &= ~ImGuiTableColumnFlags_StatusMask_;
1036 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n))
1040 column->MinX = column->MaxX = column->WorkMinX = column->ClipRect.Min.x = column->ClipRect.Max.x = offset_x;
1041 column->WidthGiven = 0.0f;
1042 column->ClipRect.Min.y = work_rect.Min.y;
1043 column->ClipRect.Max.y = FLT_MAX;
1044 column->ClipRect.ClipWithFull(host_clip_rect);
1045 column->IsVisibleX = column->IsVisibleY = column->IsRequestOutput =
false;
1046 column->IsSkipItems =
true;
1047 column->ItemWidth = 1.0f;
1052 if (is_hovering_table && mouse_skewed_x >= column->ClipRect.Min.x && mouse_skewed_x < column->ClipRect.Max.x)
1053 table->HoveredColumnBody = (ImGuiTableColumnIdx)column_n;
1056 column->MinX = offset_x;
1059 float max_width = TableGetMaxColumnWidth(table, column_n);
1060 column->WidthGiven = ImMin(column->WidthGiven, max_width);
1061 column->WidthGiven = ImMax(column->WidthGiven, ImMin(column->WidthRequest, table->MinColumnWidth));
1062 column->MaxX = offset_x + column->WidthGiven + table->CellSpacingX1 + table->CellSpacingX2 + table->CellPaddingX * 2.0f;
1069 column->WorkMinX = column->MinX + table->CellPaddingX + table->CellSpacingX1;
1070 column->WorkMaxX = column->MaxX - table->CellPaddingX - table->CellSpacingX2;
1071 column->ItemWidth = ImTrunc(column->WidthGiven * 0.65f);
1072 column->ClipRect.Min.x = column->MinX;
1073 column->ClipRect.Min.y = work_rect.Min.y;
1074 column->ClipRect.Max.x = column->MaxX;
1075 column->ClipRect.Max.y = FLT_MAX;
1076 column->ClipRect.ClipWithFull(host_clip_rect);
1085 column->IsVisibleX = (column->ClipRect.Max.x > column->ClipRect.Min.x);
1086 column->IsVisibleY =
true;
1087 const bool is_visible = column->IsVisibleX;
1089 ImBitArraySetBit(table->VisibleMaskByIndex, column_n);
1092 column->IsRequestOutput = is_visible || column->AutoFitQueue != 0 || column->CannotSkipItemsQueue != 0;
1096 column->IsSkipItems = !column->IsEnabled || table->HostSkipItems;
1097 if (column->IsSkipItems)
1098 IM_ASSERT(!is_visible);
1099 if (column->IsRequestOutput && !column->IsSkipItems)
1100 has_at_least_one_column_requesting_output =
true;
1103 column->Flags |= ImGuiTableColumnFlags_IsEnabled;
1105 column->Flags |= ImGuiTableColumnFlags_IsVisible;
1106 if (column->SortOrder != -1)
1107 column->Flags |= ImGuiTableColumnFlags_IsSorted;
1108 if (table->HoveredColumnBody == column_n)
1109 column->Flags |= ImGuiTableColumnFlags_IsHovered;
1121 column->ContentMaxXFrozen = column->ContentMaxXUnfrozen = column->WorkMinX;
1122 column->ContentMaxXHeadersUsed = column->ContentMaxXHeadersIdeal = column->WorkMinX;
1125 if (table->HostSkipItems ==
false)
1127 column->AutoFitQueue >>= 1;
1128 column->CannotSkipItemsQueue >>= 1;
1131 if (visible_n < table->FreezeColumnsCount)
1132 host_clip_rect.Min.x = ImClamp(column->MaxX + TABLE_BORDER_SIZE, host_clip_rect.Min.x, host_clip_rect.Max.x);
1134 offset_x += column->WidthGiven + table->CellSpacingX1 + table->CellSpacingX2 + table->CellPaddingX * 2.0f;
1140 if (has_at_least_one_column_requesting_output ==
false)
1142 table->Columns[table->LeftMostEnabledColumn].IsRequestOutput =
true;
1143 table->Columns[table->LeftMostEnabledColumn].IsSkipItems =
false;
1149 const float unused_x1 = ImMax(table->WorkRect.Min.x, table->Columns[table->RightMostEnabledColumn].ClipRect.Max.x);
1150 if (is_hovering_table && table->HoveredColumnBody == -1)
1151 if (mouse_skewed_x >= unused_x1)
1152 table->HoveredColumnBody = (ImGuiTableColumnIdx)table->ColumnsCount;
1153 if (has_resizable ==
false && (table->Flags & ImGuiTableFlags_Resizable))
1154 table->Flags &= ~ImGuiTableFlags_Resizable;
1156 table->IsActiveIdAliveBeforeTable = (
g.ActiveIdIsAlive != 0);
1161 if (table->RightMostStretchedColumn != -1)
1162 table->Flags &= ~ImGuiTableFlags_NoHostExtendX;
1163 if (table->Flags & ImGuiTableFlags_NoHostExtendX)
1165 table->OuterRect.Max.x = table->WorkRect.Max.x = unused_x1;
1166 table->InnerClipRect.Max.x = ImMin(table->InnerClipRect.Max.x, unused_x1);
1168 table->InnerWindow->ParentWorkRect = table->WorkRect;
1169 table->BorderX1 = table->InnerClipRect.Min.x;
1170 table->BorderX2 = table->InnerClipRect.Max.x;
1173 float window_content_max_y;
1174 if (table->Flags & ImGuiTableFlags_NoHostExtendY)
1175 window_content_max_y = table->OuterRect.Max.y;
1177 window_content_max_y = ImMax(table->InnerWindow->ContentRegionRect.Max.y, (table->Flags & ImGuiTableFlags_ScrollY) ? 0.0f : table->OuterRect.Max.y);
1178 table->InnerWindow->WorkRect.Max.y = ImClamp(window_content_max_y -
g.Style.CellPadding.y, table->InnerWindow->WorkRect.Min.y, table->InnerWindow->WorkRect.Max.y);
1181 TableSetupDrawChannels(table);
1184 if (table->Flags & ImGuiTableFlags_Resizable)
1185 TableUpdateBorders(table);
1186 table_instance->LastTopHeadersRowHeight = 0.0f;
1187 table->IsLayoutLocked =
true;
1188 table->IsUsingHeaders =
false;
1191 table->HighlightColumnHeader = -1;
1192 if (table->IsContextPopupOpen && table->ContextPopupColumn != -1 && table->InstanceInteracted == table->InstanceCurrent)
1193 table->HighlightColumnHeader = table->ContextPopupColumn;
1194 else if ((table->Flags & ImGuiTableFlags_HighlightHoveredColumn) && table->HoveredColumnBody != -1 && table->HoveredColumnBody != table->ColumnsCount && table->HoveredColumnBorder == -1)
1195 if (
g.ActiveId == 0 || (table->IsActiveIdInTable ||
g.DragDropActive))
1196 table->HighlightColumnHeader = table->HoveredColumnBody;
1203 if (table->DisableDefaultContextMenu ==
false && TableBeginContextMenuPopup(table))
1205 TableDrawDefaultContextMenu(table, table->Flags);
1211 if (table->IsSortSpecsDirty && (table->Flags & ImGuiTableFlags_Sortable))
1212 TableSortSpecsBuild(table);
1215 if (table->FreezeColumnsRequest > 0)
1216 table->InnerWindow->DecoInnerSizeX1 = table->Columns[table->DisplayOrderToIndex[table->FreezeColumnsRequest - 1]].MaxX - table->OuterRect.Min.x;
1217 if (table->FreezeRowsRequest > 0)
1218 table->InnerWindow->DecoInnerSizeY1 = table_instance->LastFrozenHeight;
1219 table_instance->LastFrozenHeight = 0.0f;
1222 ImGuiWindow* inner_window = table->InnerWindow;
1223 if (table->Flags & ImGuiTableFlags_NoClip)
1224 table->DrawSplitter->SetCurrentChannel(inner_window->DrawList, TABLE_DRAW_CHANNEL_NOCLIP);
1226 inner_window->DrawList->PushClipRect(inner_window->ClipRect.Min, inner_window->ClipRect.Max,
false);
1231void ImGui::TableUpdateBorders(ImGuiTable* table)
1234 IM_ASSERT(table->Flags & ImGuiTableFlags_Resizable);
1240 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
1241 const float hit_half_width = TABLE_RESIZE_SEPARATOR_HALF_THICKNESS;
1242 const float hit_y1 = (table->FreezeRowsCount >= 1 ? table->OuterRect.Min.y : table->WorkRect.Min.y) + table->AngledHeadersHeight;
1243 const float hit_y2_body = ImMax(table->OuterRect.Max.y, hit_y1 + table_instance->LastOuterHeight);
1244 const float hit_y2_head = hit_y1 + table_instance->LastTopHeadersRowHeight;
1246 for (
int order_n = 0; order_n < table->ColumnsCount; order_n++)
1248 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n))
1251 const int column_n = table->DisplayOrderToIndex[order_n];
1252 ImGuiTableColumn* column = &table->Columns[column_n];
1253 if (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_))
1257 const float border_y2_hit = (table->Flags & ImGuiTableFlags_NoBordersInBody) ? hit_y2_head : hit_y2_body;
1258 if ((table->Flags & ImGuiTableFlags_NoBordersInBody) && table->IsUsingHeaders ==
false)
1261 if (!column->IsVisibleX && table->LastResizedColumn != column_n)
1264 ImGuiID column_id = TableGetColumnResizeID(table, column_n, table->InstanceCurrent);
1265 ImRect hit_rect(column->MaxX - hit_half_width, hit_y1, column->MaxX + hit_half_width, border_y2_hit);
1266 ItemAdd(hit_rect, column_id, NULL, ImGuiItemFlags_NoNav);
1269 bool hovered =
false, held =
false;
1270 bool pressed = ButtonBehavior(hit_rect, column_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_NoNavFocus);
1271 if (pressed && IsMouseDoubleClicked(0))
1273 TableSetColumnWidthAutoSingle(table, column_n);
1279 if (table->LastResizedColumn == -1)
1280 table->ResizeLockMinContentsX2 = table->RightMostEnabledColumn != -1 ? table->Columns[table->RightMostEnabledColumn].MaxX : -FLT_MAX;
1281 table->ResizedColumn = (ImGuiTableColumnIdx)column_n;
1282 table->InstanceInteracted = table->InstanceCurrent;
1284 if ((hovered &&
g.HoveredIdTimer > TABLE_RESIZE_SEPARATOR_FEEDBACK_TIMER) || held)
1286 table->HoveredColumnBorder = (ImGuiTableColumnIdx)column_n;
1287 SetMouseCursor(ImGuiMouseCursor_ResizeEW);
1292void ImGui::EndTable()
1295 ImGuiTable* table =
g.CurrentTable;
1296 IM_ASSERT(table != NULL &&
"Only call EndTable() if BeginTable() returns true!");
1304 if (!table->IsLayoutLocked)
1305 TableUpdateLayout(table);
1307 const ImGuiTableFlags flags = table->Flags;
1308 ImGuiWindow* inner_window = table->InnerWindow;
1309 ImGuiWindow* outer_window = table->OuterWindow;
1310 ImGuiTableTempData* temp_data = table->TempData;
1311 IM_ASSERT(inner_window ==
g.CurrentWindow);
1312 IM_ASSERT(outer_window == inner_window || outer_window == inner_window->ParentWindow);
1314 if (table->IsInsideRow)
1318 if (flags & ImGuiTableFlags_ContextMenuInBody)
1319 if (table->HoveredColumnBody != -1 && !IsAnyItemHovered() && IsMouseReleased(ImGuiMouseButton_Right))
1320 TableOpenContextMenu((
int)table->HoveredColumnBody);
1323 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
1324 inner_window->DC.PrevLineSize = temp_data->HostBackupPrevLineSize;
1325 inner_window->DC.CurrLineSize = temp_data->HostBackupCurrLineSize;
1326 inner_window->DC.CursorMaxPos = temp_data->HostBackupCursorMaxPos;
1327 const float inner_content_max_y = table->RowPosY2;
1328 IM_ASSERT(table->RowPosY2 == inner_window->DC.CursorPos.y);
1329 if (inner_window != outer_window)
1330 inner_window->DC.CursorMaxPos.y = inner_content_max_y;
1331 else if (!(flags & ImGuiTableFlags_NoHostExtendY))
1332 table->OuterRect.Max.y = table->InnerRect.Max.y = ImMax(table->OuterRect.Max.y, inner_content_max_y);
1333 table->WorkRect.Max.y = ImMax(table->WorkRect.Max.y, table->OuterRect.Max.y);
1334 table_instance->LastOuterHeight = table->OuterRect.GetHeight();
1339 if (table->Flags & ImGuiTableFlags_ScrollX)
1341 const float outer_padding_for_border = (table->Flags & ImGuiTableFlags_BordersOuterV) ? TABLE_BORDER_SIZE : 0.0f;
1342 float max_pos_x = table->InnerWindow->DC.CursorMaxPos.x;
1343 if (table->RightMostEnabledColumn != -1)
1344 max_pos_x = ImMax(max_pos_x, table->Columns[table->RightMostEnabledColumn].WorkMaxX + table->CellPaddingX + table->OuterPaddingX - outer_padding_for_border);
1345 if (table->ResizedColumn != -1)
1346 max_pos_x = ImMax(max_pos_x, table->ResizeLockMinContentsX2);
1347 table->InnerWindow->DC.CursorMaxPos.x = max_pos_x + table->TempData->AngledHeadersExtraWidth;
1351 if (!(flags & ImGuiTableFlags_NoClip))
1352 inner_window->DrawList->PopClipRect();
1353 inner_window->ClipRect = inner_window->DrawList->_ClipRectStack.back();
1356 if ((flags & ImGuiTableFlags_Borders) != 0)
1357 TableDrawBorders(table);
1364 if (table->DummyDrawChannel != (ImGuiTableColumnIdx)-1)
1366 ImDrawChannel* dummy_channel = &table->DrawSplitter._Channels[table->DummyDrawChannel];
1367 dummy_channel->_CmdBuffer.resize(0);
1368 dummy_channel->_IdxBuffer.resize(0);
1373 ImDrawListSplitter* splitter = table->DrawSplitter;
1374 splitter->SetCurrentChannel(inner_window->DrawList, 0);
1375 if ((table->Flags & ImGuiTableFlags_NoClip) == 0)
1376 TableMergeDrawChannels(table);
1377 splitter->Merge(inner_window->DrawList);
1380 float auto_fit_width_for_fixed = 0.0f;
1381 float auto_fit_width_for_stretched = 0.0f;
1382 float auto_fit_width_for_stretched_min = 0.0f;
1383 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
1384 if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
1386 ImGuiTableColumn* column = &table->Columns[column_n];
1387 float column_width_request = ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !(column->Flags & ImGuiTableColumnFlags_NoResize)) ? column->WidthRequest : TableGetColumnWidthAuto(table, column);
1388 if (column->Flags & ImGuiTableColumnFlags_WidthFixed)
1389 auto_fit_width_for_fixed += column_width_request;
1391 auto_fit_width_for_stretched += column_width_request;
1392 if ((column->Flags & ImGuiTableColumnFlags_WidthStretch) && (column->Flags & ImGuiTableColumnFlags_NoResize) != 0)
1393 auto_fit_width_for_stretched_min = ImMax(auto_fit_width_for_stretched_min, column_width_request / (column->StretchWeight / table->ColumnsStretchSumWeights));
1395 const float width_spacings = (table->OuterPaddingX * 2.0f) + (table->CellSpacingX1 + table->CellSpacingX2) * (table->ColumnsEnabledCount - 1);
1396 table->ColumnsAutoFitWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount + auto_fit_width_for_fixed + ImMax(auto_fit_width_for_stretched, auto_fit_width_for_stretched_min);
1399 if ((table->Flags & ImGuiTableFlags_ScrollX) == 0 && inner_window != outer_window)
1401 inner_window->Scroll.x = 0.0f;
1403 else if (table->LastResizedColumn != -1 && table->ResizedColumn == -1 && inner_window->ScrollbarX && table->InstanceInteracted == table->InstanceCurrent)
1406 const float neighbor_width_to_keep_visible = table->MinColumnWidth + table->CellPaddingX * 2.0f;
1407 ImGuiTableColumn* column = &table->Columns[table->LastResizedColumn];
1408 if (column->MaxX < table->InnerClipRect.Min.x)
1409 SetScrollFromPosX(inner_window, column->MaxX - inner_window->Pos.x - neighbor_width_to_keep_visible, 1.0f);
1410 else if (column->MaxX > table->InnerClipRect.Max.x)
1411 SetScrollFromPosX(inner_window, column->MaxX - inner_window->Pos.x + neighbor_width_to_keep_visible, 1.0f);
1415 if (table->ResizedColumn != -1 && table->InstanceCurrent == table->InstanceInteracted)
1417 ImGuiTableColumn* column = &table->Columns[table->ResizedColumn];
1418 const float new_x2 = (
g.IO.MousePos.x -
g.ActiveIdClickOffset.x + TABLE_RESIZE_SEPARATOR_HALF_THICKNESS);
1419 const float new_width = ImTrunc(new_x2 - column->MinX - table->CellSpacingX1 - table->CellPaddingX * 2.0f);
1420 table->ResizedColumnNextWidth = new_width;
1423 table->IsActiveIdInTable = (
g.ActiveIdIsAlive != 0 && table->IsActiveIdAliveBeforeTable ==
false);
1426 IM_ASSERT_USER_ERROR(inner_window->IDStack.back() == table_instance->TableInstanceID,
"Mismatching PushID/PopID!");
1427 IM_ASSERT_USER_ERROR(outer_window->DC.ItemWidthStack.Size >= temp_data->HostBackupItemWidthStackSize,
"Too many PopItemWidth!");
1428 if (table->InstanceCurrent > 0)
1433 const ImVec2 backup_outer_max_pos = outer_window->DC.CursorMaxPos;
1434 inner_window->WorkRect = temp_data->HostBackupWorkRect;
1435 inner_window->ParentWorkRect = temp_data->HostBackupParentWorkRect;
1436 inner_window->SkipItems = table->HostSkipItems;
1437 outer_window->DC.CursorPos = table->OuterRect.Min;
1438 outer_window->DC.ItemWidth = temp_data->HostBackupItemWidth;
1439 outer_window->DC.ItemWidthStack.Size = temp_data->HostBackupItemWidthStackSize;
1440 outer_window->DC.ColumnsOffset = temp_data->HostBackupColumnsOffset;
1445 if (inner_window != outer_window)
1451 ItemSize(table->OuterRect.GetSize());
1452 ItemAdd(table->OuterRect, 0);
1456 if (table->Flags & ImGuiTableFlags_NoHostExtendX)
1460 IM_ASSERT((table->Flags & ImGuiTableFlags_ScrollX) == 0);
1461 outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, table->OuterRect.Min.x + table->ColumnsAutoFitWidth);
1463 else if (temp_data->UserOuterSize.x <= 0.0f)
1465 const float decoration_size = table->TempData->AngledHeadersExtraWidth + ((table->Flags & ImGuiTableFlags_ScrollX) ? inner_window->ScrollbarSizes.x : 0.0f);
1466 outer_window->DC.IdealMaxPos.x = ImMax(outer_window->DC.IdealMaxPos.x, table->OuterRect.Min.x + table->ColumnsAutoFitWidth + decoration_size - temp_data->UserOuterSize.x);
1467 outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, ImMin(table->OuterRect.Max.x, table->OuterRect.Min.x + table->ColumnsAutoFitWidth));
1471 outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, table->OuterRect.Max.x);
1473 if (temp_data->UserOuterSize.y <= 0.0f)
1475 const float decoration_size = (table->Flags & ImGuiTableFlags_ScrollY) ? inner_window->ScrollbarSizes.y : 0.0f;
1476 outer_window->DC.IdealMaxPos.y = ImMax(outer_window->DC.IdealMaxPos.y, inner_content_max_y + decoration_size - temp_data->UserOuterSize.y);
1477 outer_window->DC.CursorMaxPos.y = ImMax(backup_outer_max_pos.y, ImMin(table->OuterRect.Max.y, inner_content_max_y));
1482 outer_window->DC.CursorMaxPos.y = ImMax(backup_outer_max_pos.y, table->OuterRect.Max.y);
1486 if (table->IsSettingsDirty)
1487 TableSaveSettings(table);
1488 table->IsInitializing =
false;
1491 IM_ASSERT(
g.CurrentWindow == outer_window &&
g.CurrentTable == table);
1492 IM_ASSERT(
g.TablesTempDataStacked > 0);
1493 temp_data = (--
g.TablesTempDataStacked > 0) ? &
g.TablesTempData[
g.TablesTempDataStacked - 1] : NULL;
1494 g.CurrentTable = temp_data ?
g.Tables.GetByIndex(temp_data->TableIndex) : NULL;
1497 g.CurrentTable->TempData = temp_data;
1498 g.CurrentTable->DrawSplitter = &temp_data->DrawSplitter;
1500 outer_window->DC.CurrentTableIdx =
g.CurrentTable ?
g.Tables.GetIndex(
g.CurrentTable) : -1;
1501 NavUpdateCurrentWindowIsScrollPushableX();
1506void ImGui::TableSetupColumn(
const char* label, ImGuiTableColumnFlags flags,
float init_width_or_weight, ImGuiID user_id)
1509 ImGuiTable* table =
g.CurrentTable;
1510 IM_ASSERT(table != NULL &&
"Need to call TableSetupColumn() after BeginTable()!");
1511 IM_ASSERT(table->IsLayoutLocked ==
false &&
"Need to call call TableSetupColumn() before first row!");
1512 IM_ASSERT((flags & ImGuiTableColumnFlags_StatusMask_) == 0 &&
"Illegal to pass StatusMask values to TableSetupColumn()");
1513 if (table->DeclColumnsCount >= table->ColumnsCount)
1515 IM_ASSERT_USER_ERROR(table->DeclColumnsCount < table->ColumnsCount,
"Called TableSetupColumn() too many times!");
1519 ImGuiTableColumn* column = &table->Columns[table->DeclColumnsCount];
1520 table->DeclColumnsCount++;
1524 if (table->IsDefaultSizingPolicy && (flags & ImGuiTableColumnFlags_WidthMask_) == 0 && (flags & ImGuiTableFlags_ScrollX) == 0)
1525 IM_ASSERT(init_width_or_weight <= 0.0f &&
"Can only specify width/weight if sizing policy is set explicitly in either Table or Column.");
1529 if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0 && init_width_or_weight > 0.0f)
1530 if ((table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedFit || (table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedSame)
1531 flags |= ImGuiTableColumnFlags_WidthFixed;
1532 if (flags & ImGuiTableColumnFlags_AngledHeader)
1534 flags |= ImGuiTableColumnFlags_NoHeaderLabel;
1535 table->AngledHeadersCount++;
1538 TableSetupColumnFlags(table, column, flags);
1539 column->UserID = user_id;
1540 flags = column->Flags;
1543 column->InitStretchWeightOrWidth = init_width_or_weight;
1544 if (table->IsInitializing)
1547 if (column->WidthRequest < 0.0f && column->StretchWeight < 0.0f)
1549 if ((flags & ImGuiTableColumnFlags_WidthFixed) && init_width_or_weight > 0.0f)
1550 column->WidthRequest = init_width_or_weight;
1551 if (flags & ImGuiTableColumnFlags_WidthStretch)
1552 column->StretchWeight = (init_width_or_weight > 0.0f) ? init_width_or_weight : -1.0f;
1555 if (init_width_or_weight > 0.0f)
1556 column->AutoFitQueue = 0x00;
1560 if ((flags & ImGuiTableColumnFlags_DefaultHide) && (table->SettingsLoadedFlags & ImGuiTableFlags_Hideable) == 0)
1561 column->IsUserEnabled = column->IsUserEnabledNextFrame =
false;
1562 if (flags & ImGuiTableColumnFlags_DefaultSort && (table->SettingsLoadedFlags & ImGuiTableFlags_Sortable) == 0)
1564 column->SortOrder = 0;
1565 column->SortDirection = (column->Flags & ImGuiTableColumnFlags_PreferSortDescending) ? (ImS8)ImGuiSortDirection_Descending : (ImU8)(ImGuiSortDirection_Ascending);
1571 column->NameOffset = -1;
1572 if (label != NULL && label[0] != 0)
1574 column->NameOffset = (ImS16)table->ColumnsNames.size();
1575 table->ColumnsNames.append(label, label + strlen(label) + 1);
1580void ImGui::TableSetupScrollFreeze(
int columns,
int rows)
1583 ImGuiTable* table =
g.CurrentTable;
1584 IM_ASSERT(table != NULL &&
"Need to call TableSetupColumn() after BeginTable()!");
1585 IM_ASSERT(table->IsLayoutLocked ==
false &&
"Need to call TableSetupColumn() before first row!");
1586 IM_ASSERT(columns >= 0 && columns < IMGUI_TABLE_MAX_COLUMNS);
1587 IM_ASSERT(rows >= 0 && rows < 128);
1589 table->FreezeColumnsRequest = (table->Flags & ImGuiTableFlags_ScrollX) ? (ImGuiTableColumnIdx)ImMin(columns, table->ColumnsCount) : 0;
1590 table->FreezeColumnsCount = (table->InnerWindow->Scroll.x != 0.0f) ? table->FreezeColumnsRequest : 0;
1591 table->FreezeRowsRequest = (table->Flags & ImGuiTableFlags_ScrollY) ? (ImGuiTableColumnIdx)rows : 0;
1592 table->FreezeRowsCount = (table->InnerWindow->Scroll.y != 0.0f) ? table->FreezeRowsRequest : 0;
1593 table->IsUnfrozenRows = (table->FreezeRowsCount == 0);
1597 for (
int column_n = 0; column_n < table->FreezeColumnsRequest; column_n++)
1599 int order_n = table->DisplayOrderToIndex[column_n];
1600 if (order_n != column_n && order_n >= table->FreezeColumnsRequest)
1602 ImSwap(table->Columns[table->DisplayOrderToIndex[order_n]].DisplayOrder, table->Columns[table->DisplayOrderToIndex[column_n]].DisplayOrder);
1603 ImSwap(table->DisplayOrderToIndex[order_n], table->DisplayOrderToIndex[column_n]);
1623int ImGui::TableGetColumnCount()
1626 ImGuiTable* table =
g.CurrentTable;
1627 return table ? table->ColumnsCount : 0;
1630const char* ImGui::TableGetColumnName(
int column_n)
1633 ImGuiTable* table =
g.CurrentTable;
1637 column_n = table->CurrentColumn;
1638 return TableGetColumnName(table, column_n);
1641const char* ImGui::TableGetColumnName(
const ImGuiTable* table,
int column_n)
1643 if (table->IsLayoutLocked ==
false && column_n >= table->DeclColumnsCount)
1645 const ImGuiTableColumn* column = &table->Columns[column_n];
1646 if (column->NameOffset == -1)
1648 return &table->ColumnsNames.Buf[column->NameOffset];
1657void ImGui::TableSetColumnEnabled(
int column_n,
bool enabled)
1660 ImGuiTable* table =
g.CurrentTable;
1661 IM_ASSERT(table != NULL);
1664 IM_ASSERT(table->Flags & ImGuiTableFlags_Hideable);
1666 column_n = table->CurrentColumn;
1667 IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
1668 ImGuiTableColumn* column = &table->Columns[column_n];
1669 column->IsUserEnabledNextFrame = enabled;
1673ImGuiTableColumnFlags ImGui::TableGetColumnFlags(
int column_n)
1676 ImGuiTable* table =
g.CurrentTable;
1678 return ImGuiTableColumnFlags_None;
1680 column_n = table->CurrentColumn;
1681 if (column_n == table->ColumnsCount)
1682 return (table->HoveredColumnBody == column_n) ? ImGuiTableColumnFlags_IsHovered : ImGuiTableColumnFlags_None;
1683 return table->Columns[column_n].Flags;
1692ImRect ImGui::TableGetCellBgRect(
const ImGuiTable* table,
int column_n)
1694 const ImGuiTableColumn* column = &table->Columns[column_n];
1695 float x1 = column->MinX;
1696 float x2 = column->MaxX;
1701 x1 = ImMax(x1, table->WorkRect.Min.x);
1702 x2 = ImMin(x2, table->WorkRect.Max.x);
1703 return ImRect(x1, table->RowPosY1, x2, table->RowPosY2);
1707ImGuiID ImGui::TableGetColumnResizeID(ImGuiTable* table,
int column_n,
int instance_no)
1709 IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
1710 ImGuiID instance_id = TableGetInstanceID(table, instance_no);
1711 return instance_id + 1 + column_n;
1715int ImGui::TableGetHoveredColumn()
1718 ImGuiTable* table =
g.CurrentTable;
1721 return (
int)table->HoveredColumnBody;
1727int ImGui::TableGetHoveredRow()
1730 ImGuiTable* table =
g.CurrentTable;
1733 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
1734 return (
int)table_instance->HoveredRowLast;
1737void ImGui::TableSetBgColor(ImGuiTableBgTarget target, ImU32 color,
int column_n)
1740 ImGuiTable* table =
g.CurrentTable;
1741 IM_ASSERT(target != ImGuiTableBgTarget_None);
1743 if (color == IM_COL32_DISABLE)
1749 case ImGuiTableBgTarget_CellBg:
1751 if (table->RowPosY1 > table->InnerClipRect.Max.y)
1754 column_n = table->CurrentColumn;
1755 if (!IM_BITARRAY_TESTBIT(table->VisibleMaskByIndex, column_n))
1757 if (table->RowCellDataCurrent < 0 || table->RowCellData[table->RowCellDataCurrent].Column != column_n)
1758 table->RowCellDataCurrent++;
1759 ImGuiTableCellData* cell_data = &table->RowCellData[table->RowCellDataCurrent];
1760 cell_data->BgColor = color;
1761 cell_data->Column = (ImGuiTableColumnIdx)column_n;
1764 case ImGuiTableBgTarget_RowBg0:
1765 case ImGuiTableBgTarget_RowBg1:
1767 if (table->RowPosY1 > table->InnerClipRect.Max.y)
1769 IM_ASSERT(column_n == -1);
1770 int bg_idx = (target == ImGuiTableBgTarget_RowBg1) ? 1 : 0;
1771 table->RowBgColor[bg_idx] = color;
1789int ImGui::TableGetRowIndex()
1792 ImGuiTable* table =
g.CurrentTable;
1795 return table->CurrentRow;
1799void ImGui::TableNextRow(ImGuiTableRowFlags row_flags,
float row_min_height)
1802 ImGuiTable* table =
g.CurrentTable;
1804 if (!table->IsLayoutLocked)
1805 TableUpdateLayout(table);
1806 if (table->IsInsideRow)
1809 table->LastRowFlags = table->RowFlags;
1810 table->RowFlags = row_flags;
1811 table->RowCellPaddingY =
g.Style.CellPadding.y;
1812 table->RowMinHeight = row_min_height;
1813 TableBeginRow(table);
1817 table->RowPosY2 += table->RowCellPaddingY * 2.0f;
1818 table->RowPosY2 = ImMax(table->RowPosY2, table->RowPosY1 + row_min_height);
1821 table->InnerWindow->SkipItems =
true;
1825void ImGui::TableBeginRow(ImGuiTable* table)
1827 ImGuiWindow* window = table->InnerWindow;
1828 IM_ASSERT(!table->IsInsideRow);
1831 table->CurrentRow++;
1832 table->CurrentColumn = -1;
1833 table->RowBgColor[0] = table->RowBgColor[1] = IM_COL32_DISABLE;
1834 table->RowCellDataCurrent = -1;
1835 table->IsInsideRow =
true;
1838 float next_y1 = table->RowPosY2;
1839 if (table->CurrentRow == 0 && table->FreezeRowsCount > 0)
1840 next_y1 = window->DC.CursorPos.y = table->OuterRect.Min.y;
1842 table->RowPosY1 = table->RowPosY2 = next_y1;
1843 table->RowTextBaseline = 0.0f;
1844 table->RowIndentOffsetX = window->DC.Indent.x - table->HostIndentX;
1846 window->DC.PrevLineTextBaseOffset = 0.0f;
1847 window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x, window->DC.CursorPos.y + table->RowCellPaddingY);
1848 window->DC.PrevLineSize = window->DC.CurrLineSize = ImVec2(0.0f, 0.0f);
1849 window->DC.IsSameLine = window->DC.IsSetPos =
false;
1850 window->DC.CursorMaxPos.y = next_y1;
1853 if (table->RowFlags & ImGuiTableRowFlags_Headers)
1855 TableSetBgColor(ImGuiTableBgTarget_RowBg0, GetColorU32(ImGuiCol_TableHeaderBg));
1856 if (table->CurrentRow == 0)
1857 table->IsUsingHeaders =
true;
1862void ImGui::TableEndRow(ImGuiTable* table)
1865 ImGuiWindow* window =
g.CurrentWindow;
1866 IM_ASSERT(window == table->InnerWindow);
1867 IM_ASSERT(table->IsInsideRow);
1869 if (table->CurrentColumn != -1)
1870 TableEndCell(table);
1874 LogRenderedText(NULL,
"|");
1878 window->DC.CursorPos.y = table->RowPosY2;
1881 const float bg_y1 = table->RowPosY1;
1882 const float bg_y2 = table->RowPosY2;
1883 const bool unfreeze_rows_actual = (table->CurrentRow + 1 == table->FreezeRowsCount);
1884 const bool unfreeze_rows_request = (table->CurrentRow + 1 == table->FreezeRowsRequest);
1885 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
1886 if ((table->RowFlags & ImGuiTableRowFlags_Headers) && (table->CurrentRow == 0 || (table->LastRowFlags & ImGuiTableRowFlags_Headers)))
1887 table_instance->LastTopHeadersRowHeight += bg_y2 - bg_y1;
1889 const bool is_visible = (bg_y2 >= table->InnerClipRect.Min.y && bg_y1 <= table->InnerClipRect.Max.y);
1893 if (table->HoveredColumnBody != -1 &&
g.IO.MousePos.y >= bg_y1 &&
g.IO.MousePos.y < bg_y2 && table_instance->HoveredRowNext < 0)
1894 table_instance->HoveredRowNext = table->CurrentRow;
1899 if (table->RowBgColor[0] != IM_COL32_DISABLE)
1900 bg_col0 = table->RowBgColor[0];
1901 else if (table->Flags & ImGuiTableFlags_RowBg)
1902 bg_col0 = GetColorU32((table->RowBgColorCounter & 1) ? ImGuiCol_TableRowBgAlt : ImGuiCol_TableRowBg);
1903 if (table->RowBgColor[1] != IM_COL32_DISABLE)
1904 bg_col1 = table->RowBgColor[1];
1907 ImU32 top_border_col = 0;
1908 const float border_size = TABLE_BORDER_SIZE;
1909 if (table->CurrentRow > 0 && (table->Flags & ImGuiTableFlags_BordersInnerH))
1910 top_border_col = (table->LastRowFlags & ImGuiTableRowFlags_Headers) ? table->BorderColorStrong : table->BorderColorLight;
1912 const bool draw_cell_bg_color = table->RowCellDataCurrent >= 0;
1913 const bool draw_strong_bottom_border = unfreeze_rows_actual;
1914 if ((bg_col0 | bg_col1 | top_border_col) != 0 || draw_strong_bottom_border || draw_cell_bg_color)
1918 if ((table->Flags & ImGuiTableFlags_NoClip) == 0)
1919 window->DrawList->_CmdHeader.ClipRect = table->Bg0ClipRectForDrawCmd.ToVec4();
1920 table->DrawSplitter->SetCurrentChannel(window->DrawList, TABLE_DRAW_CHANNEL_BG0);
1925 if (bg_col0 || bg_col1)
1927 ImRect row_rect(table->WorkRect.Min.x, bg_y1, table->WorkRect.Max.x, bg_y2);
1928 row_rect.ClipWith(table->BgClipRect);
1929 if (bg_col0 != 0 && row_rect.Min.y < row_rect.Max.y)
1930 window->DrawList->AddRectFilled(row_rect.Min, row_rect.Max, bg_col0);
1931 if (bg_col1 != 0 && row_rect.Min.y < row_rect.Max.y)
1932 window->DrawList->AddRectFilled(row_rect.Min, row_rect.Max, bg_col1);
1936 if (draw_cell_bg_color)
1938 ImGuiTableCellData* cell_data_end = &table->RowCellData[table->RowCellDataCurrent];
1939 for (ImGuiTableCellData* cell_data = &table->RowCellData[0]; cell_data <= cell_data_end; cell_data++)
1943 const ImGuiTableColumn* column = &table->Columns[cell_data->Column];
1944 ImRect cell_bg_rect = TableGetCellBgRect(table, cell_data->Column);
1945 cell_bg_rect.ClipWith(table->BgClipRect);
1946 cell_bg_rect.Min.x = ImMax(cell_bg_rect.Min.x, column->ClipRect.Min.x);
1947 cell_bg_rect.Max.x = ImMin(cell_bg_rect.Max.x, column->MaxX);
1948 window->DrawList->AddRectFilled(cell_bg_rect.Min, cell_bg_rect.Max, cell_data->BgColor);
1953 if (top_border_col && bg_y1 >= table->BgClipRect.Min.y && bg_y1 < table->BgClipRect.Max.y)
1954 window->DrawList->AddLine(ImVec2(table->BorderX1, bg_y1), ImVec2(table->BorderX2, bg_y1), top_border_col, border_size);
1957 if (draw_strong_bottom_border && bg_y2 >= table->BgClipRect.Min.y && bg_y2 < table->BgClipRect.Max.y)
1958 window->DrawList->AddLine(ImVec2(table->BorderX1, bg_y2), ImVec2(table->BorderX2, bg_y2), table->BorderColorStrong, border_size);
1964 if (unfreeze_rows_request)
1965 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
1966 table->Columns[column_n].NavLayerCurrent = ImGuiNavLayer_Main;
1967 if (unfreeze_rows_actual)
1969 IM_ASSERT(table->IsUnfrozenRows ==
false);
1970 const float y0 = ImMax(table->RowPosY2 + 1, window->InnerClipRect.Min.y);
1971 table->IsUnfrozenRows =
true;
1972 table_instance->LastFrozenHeight = y0 - table->OuterRect.Min.y;
1975 table->BgClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y = ImMin(y0, window->InnerClipRect.Max.y);
1976 table->BgClipRect.Max.y = table->Bg2ClipRectForDrawCmd.Max.y = window->InnerClipRect.Max.y;
1977 table->Bg2DrawChannelCurrent = table->Bg2DrawChannelUnfrozen;
1978 IM_ASSERT(table->Bg2ClipRectForDrawCmd.Min.y <= table->Bg2ClipRectForDrawCmd.Max.y);
1980 float row_height = table->RowPosY2 - table->RowPosY1;
1981 table->RowPosY2 = window->DC.CursorPos.y = table->WorkRect.Min.y + table->RowPosY2 - table->OuterRect.Min.y;
1982 table->RowPosY1 = table->RowPosY2 - row_height;
1983 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
1985 ImGuiTableColumn* column = &table->Columns[column_n];
1986 column->DrawChannelCurrent = column->DrawChannelUnfrozen;
1987 column->ClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y;
1991 SetWindowClipRectBeforeSetChannel(window, table->Columns[0].ClipRect);
1992 table->DrawSplitter->SetCurrentChannel(window->DrawList, table->Columns[0].DrawChannelCurrent);
1995 if (!(table->RowFlags & ImGuiTableRowFlags_Headers))
1996 table->RowBgColorCounter++;
1997 table->IsInsideRow =
false;
2010int ImGui::TableGetColumnIndex()
2013 ImGuiTable* table =
g.CurrentTable;
2016 return table->CurrentColumn;
2020bool ImGui::TableSetColumnIndex(
int column_n)
2023 ImGuiTable* table =
g.CurrentTable;
2027 if (table->CurrentColumn != column_n)
2029 if (table->CurrentColumn != -1)
2030 TableEndCell(table);
2031 IM_ASSERT(column_n >= 0 && table->ColumnsCount);
2032 TableBeginCell(table, column_n);
2037 return table->Columns[column_n].IsRequestOutput;
2041bool ImGui::TableNextColumn()
2044 ImGuiTable* table =
g.CurrentTable;
2048 if (table->IsInsideRow && table->CurrentColumn + 1 < table->ColumnsCount)
2050 if (table->CurrentColumn != -1)
2051 TableEndCell(table);
2052 TableBeginCell(table, table->CurrentColumn + 1);
2057 TableBeginCell(table, 0);
2062 return table->Columns[table->CurrentColumn].IsRequestOutput;
2069void ImGui::TableBeginCell(ImGuiTable* table,
int column_n)
2072 ImGuiTableColumn* column = &table->Columns[column_n];
2073 ImGuiWindow* window = table->InnerWindow;
2074 table->CurrentColumn = column_n;
2077 float start_x = column->WorkMinX;
2078 if (column->Flags & ImGuiTableColumnFlags_IndentEnable)
2079 start_x += table->RowIndentOffsetX;
2081 window->DC.CursorPos.x = start_x;
2082 window->DC.CursorPos.y = table->RowPosY1 + table->RowCellPaddingY;
2083 window->DC.CursorMaxPos.x = window->DC.CursorPos.x;
2084 window->DC.ColumnsOffset.x = start_x - window->Pos.x - window->DC.Indent.x;
2085 window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x;
2086 window->DC.CurrLineTextBaseOffset = table->RowTextBaseline;
2087 window->DC.NavLayerCurrent = (ImGuiNavLayer)column->NavLayerCurrent;
2090 window->WorkRect.Min.y = window->DC.CursorPos.y;
2091 window->WorkRect.Min.x = column->WorkMinX;
2092 window->WorkRect.Max.x = column->WorkMaxX;
2093 window->DC.ItemWidth = column->ItemWidth;
2095 window->SkipItems = column->IsSkipItems;
2096 if (column->IsSkipItems)
2098 g.LastItemData.ID = 0;
2099 g.LastItemData.StatusFlags = 0;
2102 if (table->Flags & ImGuiTableFlags_NoClip)
2105 table->DrawSplitter->SetCurrentChannel(window->DrawList, TABLE_DRAW_CHANNEL_NOCLIP);
2111 SetWindowClipRectBeforeSetChannel(window, column->ClipRect);
2112 table->DrawSplitter->SetCurrentChannel(window->DrawList, column->DrawChannelCurrent);
2116 if (
g.LogEnabled && !column->IsSkipItems)
2118 LogRenderedText(&window->DC.CursorPos,
"|");
2119 g.LogLinePosY = FLT_MAX;
2124void ImGui::TableEndCell(ImGuiTable* table)
2126 ImGuiTableColumn* column = &table->Columns[table->CurrentColumn];
2127 ImGuiWindow* window = table->InnerWindow;
2129 if (window->DC.IsSetPos)
2130 ErrorCheckUsingSetCursorPosToExtendParentBoundaries();
2134 if (table->RowFlags & ImGuiTableRowFlags_Headers)
2135 p_max_pos_x = &column->ContentMaxXHeadersUsed;
2137 p_max_pos_x = table->IsUnfrozenRows ? &column->ContentMaxXUnfrozen : &column->ContentMaxXFrozen;
2138 *p_max_pos_x = ImMax(*p_max_pos_x, window->DC.CursorMaxPos.x);
2139 if (column->IsEnabled)
2140 table->RowPosY2 = ImMax(table->RowPosY2, window->DC.CursorMaxPos.y + table->RowCellPaddingY);
2141 column->ItemWidth = window->DC.ItemWidth;
2145 table->RowTextBaseline = ImMax(table->RowTextBaseline, window->DC.PrevLineTextBaseOffset);
2162float ImGui::TableGetMaxColumnWidth(
const ImGuiTable* table,
int column_n)
2164 const ImGuiTableColumn* column = &table->Columns[column_n];
2165 float max_width = FLT_MAX;
2166 const float min_column_distance = table->MinColumnWidth + table->CellPaddingX * 2.0f + table->CellSpacingX1 + table->CellSpacingX2;
2167 if (table->Flags & ImGuiTableFlags_ScrollX)
2171 if (column->DisplayOrder < table->FreezeColumnsRequest)
2173 max_width = (table->InnerClipRect.Max.x - (table->FreezeColumnsRequest - column->DisplayOrder) * min_column_distance) - column->MinX;
2174 max_width = max_width - table->OuterPaddingX - table->CellPaddingX - table->CellSpacingX2;
2177 else if ((table->Flags & ImGuiTableFlags_NoKeepColumnsVisible) == 0)
2184 max_width = table->WorkRect.Max.x - (table->ColumnsEnabledCount - column->IndexWithinEnabledSet - 1) * min_column_distance - column->MinX;
2186 max_width -= table->CellSpacingX2;
2187 max_width -= table->CellPaddingX * 2.0f;
2188 max_width -= table->OuterPaddingX;
2194float ImGui::TableGetColumnWidthAuto(ImGuiTable* table, ImGuiTableColumn* column)
2196 const float content_width_body = ImMax(column->ContentMaxXFrozen, column->ContentMaxXUnfrozen) - column->WorkMinX;
2197 const float content_width_headers = column->ContentMaxXHeadersIdeal - column->WorkMinX;
2198 float width_auto = content_width_body;
2199 if (!(column->Flags & ImGuiTableColumnFlags_NoHeaderWidth))
2200 width_auto = ImMax(width_auto, content_width_headers);
2203 if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && column->InitStretchWeightOrWidth > 0.0f)
2204 if (!(table->Flags & ImGuiTableFlags_Resizable) || (column->Flags & ImGuiTableColumnFlags_NoResize))
2205 width_auto = column->InitStretchWeightOrWidth;
2207 return ImMax(width_auto, table->MinColumnWidth);
2211void ImGui::TableSetColumnWidth(
int column_n,
float width)
2214 ImGuiTable* table =
g.CurrentTable;
2215 IM_ASSERT(table != NULL && table->IsLayoutLocked ==
false);
2216 IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
2217 ImGuiTableColumn* column_0 = &table->Columns[column_n];
2218 float column_0_width = width;
2222 IM_ASSERT(table->MinColumnWidth > 0.0f);
2223 const float min_width = table->MinColumnWidth;
2224 const float max_width = ImMax(min_width, TableGetMaxColumnWidth(table, column_n));
2225 column_0_width = ImClamp(column_0_width, min_width, max_width);
2226 if (column_0->WidthGiven == column_0_width || column_0->WidthRequest == column_0_width)
2230 ImGuiTableColumn* column_1 = (column_0->NextEnabledColumn != -1) ? &table->Columns[column_0->NextEnabledColumn] : NULL;
2266 if (column_0->Flags & ImGuiTableColumnFlags_WidthFixed)
2267 if (!column_1 || table->LeftMostStretchedColumn == -1 || table->Columns[table->LeftMostStretchedColumn].DisplayOrder >= column_0->DisplayOrder)
2269 column_0->WidthRequest = column_0_width;
2270 table->IsSettingsDirty =
true;
2275 if (column_1 == NULL)
2276 column_1 = (column_0->PrevEnabledColumn != -1) ? &table->Columns[column_0->PrevEnabledColumn] : NULL;
2277 if (column_1 == NULL)
2282 float column_1_width = ImMax(column_1->WidthRequest - (column_0_width - column_0->WidthRequest), min_width);
2283 column_0_width = column_0->WidthRequest + column_1->WidthRequest - column_1_width;
2284 IM_ASSERT(column_0_width > 0.0f && column_1_width > 0.0f);
2285 column_0->WidthRequest = column_0_width;
2286 column_1->WidthRequest = column_1_width;
2287 if ((column_0->Flags | column_1->Flags) & ImGuiTableColumnFlags_WidthStretch)
2288 TableUpdateColumnsWeightFromWidth(table);
2289 table->IsSettingsDirty =
true;
2294void ImGui::TableSetColumnWidthAutoSingle(ImGuiTable* table,
int column_n)
2297 ImGuiTableColumn* column = &table->Columns[column_n];
2298 if (!column->IsEnabled)
2300 column->CannotSkipItemsQueue = (1 << 0);
2301 table->AutoFitSingleColumn = (ImGuiTableColumnIdx)column_n;
2304void ImGui::TableSetColumnWidthAutoAll(ImGuiTable* table)
2306 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2308 ImGuiTableColumn* column = &table->Columns[column_n];
2309 if (!column->IsEnabled && !(column->Flags & ImGuiTableColumnFlags_WidthStretch))
2311 column->CannotSkipItemsQueue = (1 << 0);
2312 column->AutoFitQueue = (1 << 1);
2316void ImGui::TableUpdateColumnsWeightFromWidth(ImGuiTable* table)
2318 IM_ASSERT(table->LeftMostStretchedColumn != -1 && table->RightMostStretchedColumn != -1);
2321 float visible_weight = 0.0f;
2322 float visible_width = 0.0f;
2323 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2325 ImGuiTableColumn* column = &table->Columns[column_n];
2326 if (!column->IsEnabled || !(column->Flags & ImGuiTableColumnFlags_WidthStretch))
2328 IM_ASSERT(column->StretchWeight > 0.0f);
2329 visible_weight += column->StretchWeight;
2330 visible_width += column->WidthRequest;
2332 IM_ASSERT(visible_weight > 0.0f && visible_width > 0.0f);
2335 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2337 ImGuiTableColumn* column = &table->Columns[column_n];
2338 if (!column->IsEnabled || !(column->Flags & ImGuiTableColumnFlags_WidthStretch))
2340 column->StretchWeight = (column->WidthRequest / visible_width) * visible_weight;
2341 IM_ASSERT(column->StretchWeight > 0.0f);
2358void ImGui::TablePushBackgroundChannel()
2361 ImGuiWindow* window =
g.CurrentWindow;
2362 ImGuiTable* table =
g.CurrentTable;
2365 table->HostBackupInnerClipRect = window->ClipRect;
2366 SetWindowClipRectBeforeSetChannel(window, table->Bg2ClipRectForDrawCmd);
2367 table->DrawSplitter->SetCurrentChannel(window->DrawList, table->Bg2DrawChannelCurrent);
2370void ImGui::TablePopBackgroundChannel()
2373 ImGuiWindow* window =
g.CurrentWindow;
2374 ImGuiTable* table =
g.CurrentTable;
2375 ImGuiTableColumn* column = &table->Columns[table->CurrentColumn];
2378 SetWindowClipRectBeforeSetChannel(window, table->HostBackupInnerClipRect);
2379 table->DrawSplitter->SetCurrentChannel(window->DrawList, column->DrawChannelCurrent);
2398void ImGui::TableSetupDrawChannels(ImGuiTable* table)
2400 const int freeze_row_multiplier = (table->FreezeRowsCount > 0) ? 2 : 1;
2401 const int channels_for_row = (table->Flags & ImGuiTableFlags_NoClip) ? 1 : table->ColumnsEnabledCount;
2402 const int channels_for_bg = 1 + 1 * freeze_row_multiplier;
2403 const int channels_for_dummy = (table->ColumnsEnabledCount < table->ColumnsCount || (memcmp(table->VisibleMaskByIndex, table->EnabledMaskByIndex, ImBitArrayGetStorageSizeInBytes(table->ColumnsCount)) != 0)) ? +1 : 0;
2404 const int channels_total = channels_for_bg + (channels_for_row * freeze_row_multiplier) + channels_for_dummy;
2405 table->DrawSplitter->Split(table->InnerWindow->DrawList, channels_total);
2406 table->DummyDrawChannel = (ImGuiTableDrawChannelIdx)((channels_for_dummy > 0) ? channels_total - 1 : -1);
2407 table->Bg2DrawChannelCurrent = TABLE_DRAW_CHANNEL_BG2_FROZEN;
2408 table->Bg2DrawChannelUnfrozen = (ImGuiTableDrawChannelIdx)((table->FreezeRowsCount > 0) ? 2 + channels_for_row : TABLE_DRAW_CHANNEL_BG2_FROZEN);
2410 int draw_channel_current = 2;
2411 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2413 ImGuiTableColumn* column = &table->Columns[column_n];
2414 if (column->IsVisibleX && column->IsVisibleY)
2416 column->DrawChannelFrozen = (ImGuiTableDrawChannelIdx)(draw_channel_current);
2417 column->DrawChannelUnfrozen = (ImGuiTableDrawChannelIdx)(draw_channel_current + (table->FreezeRowsCount > 0 ? channels_for_row + 1 : 0));
2418 if (!(table->Flags & ImGuiTableFlags_NoClip))
2419 draw_channel_current++;
2423 column->DrawChannelFrozen = column->DrawChannelUnfrozen = table->DummyDrawChannel;
2425 column->DrawChannelCurrent = column->DrawChannelFrozen;
2431 table->BgClipRect = table->InnerClipRect;
2432 table->Bg0ClipRectForDrawCmd = table->OuterWindow->ClipRect;
2433 table->Bg2ClipRectForDrawCmd = table->HostClipRect;
2434 IM_ASSERT(table->BgClipRect.Min.y <= table->BgClipRect.Max.y);
2466void ImGui::TableMergeDrawChannels(ImGuiTable* table)
2469 ImDrawListSplitter* splitter = table->DrawSplitter;
2470 const bool has_freeze_v = (table->FreezeRowsCount > 0);
2471 const bool has_freeze_h = (table->FreezeColumnsCount > 0);
2472 IM_ASSERT(splitter->_Current == 0);
2478 int ChannelsCount = 0;
2479 ImBitArrayPtr ChannelsMask = NULL;
2481 int merge_group_mask = 0x00;
2482 MergeGroup merge_groups[4];
2485 const int max_draw_channels = (4 + table->ColumnsCount * 2);
2486 const int size_for_masks_bitarrays_one = (int)ImBitArrayGetStorageSizeInBytes(max_draw_channels);
2487 g.TempBuffer.reserve(size_for_masks_bitarrays_one * 5);
2488 memset(
g.TempBuffer.Data, 0, size_for_masks_bitarrays_one * 5);
2489 for (
int n = 0; n < IM_ARRAYSIZE(merge_groups); n++)
2490 merge_groups[n].ChannelsMask = (ImBitArrayPtr)(
void*)(
g.TempBuffer.Data + (size_for_masks_bitarrays_one * n));
2491 ImBitArrayPtr remaining_mask = (ImBitArrayPtr)(
void*)(
g.TempBuffer.Data + (size_for_masks_bitarrays_one * 4));
2494 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2496 if (!IM_BITARRAY_TESTBIT(table->VisibleMaskByIndex, column_n))
2498 ImGuiTableColumn* column = &table->Columns[column_n];
2500 const int merge_group_sub_count = has_freeze_v ? 2 : 1;
2501 for (
int merge_group_sub_n = 0; merge_group_sub_n < merge_group_sub_count; merge_group_sub_n++)
2503 const int channel_no = (merge_group_sub_n == 0) ? column->DrawChannelFrozen : column->DrawChannelUnfrozen;
2506 ImDrawChannel* src_channel = &splitter->_Channels[channel_no];
2507 if (src_channel->_CmdBuffer.Size > 0 && src_channel->_CmdBuffer.back().ElemCount == 0 && src_channel->_CmdBuffer.back().UserCallback == NULL)
2508 src_channel->_CmdBuffer.pop_back();
2509 if (src_channel->_CmdBuffer.Size != 1)
2514 if (!(column->Flags & ImGuiTableColumnFlags_NoClip))
2516 float content_max_x;
2518 content_max_x = ImMax(column->ContentMaxXUnfrozen, column->ContentMaxXHeadersUsed);
2519 else if (merge_group_sub_n == 0)
2520 content_max_x = ImMax(column->ContentMaxXFrozen, column->ContentMaxXHeadersUsed);
2522 content_max_x = column->ContentMaxXUnfrozen;
2523 if (content_max_x > column->ClipRect.Max.x)
2527 const int merge_group_n = (has_freeze_h && column_n < table->FreezeColumnsCount ? 0 : 1) + (has_freeze_v && merge_group_sub_n == 0 ? 0 : 2);
2528 IM_ASSERT(channel_no < max_draw_channels);
2529 MergeGroup* merge_group = &merge_groups[merge_group_n];
2530 if (merge_group->ChannelsCount == 0)
2531 merge_group->ClipRect = ImRect(+FLT_MAX, +FLT_MAX, -FLT_MAX, -FLT_MAX);
2532 ImBitArraySetBit(merge_group->ChannelsMask, channel_no);
2533 merge_group->ChannelsCount++;
2534 merge_group->ClipRect.Add(src_channel->_CmdBuffer[0].ClipRect);
2535 merge_group_mask |= (1 << merge_group_n);
2540 column->DrawChannelCurrent = (ImGuiTableDrawChannelIdx)-1;
2546 for (
int merge_group_n = 0; merge_group_n < IM_ARRAYSIZE(merge_groups); merge_group_n++)
2548 MergeGroup* merge_group = &merge_groups[merge_group_n];
2549 if (merge_group->ChannelsCount == 0)
2552 ImFormatString(buf, 32,
"MG%d:%d", merge_group_n, merge_group->ChannelsCount);
2553 ImVec2 text_pos = merge_group->ClipRect.Min + ImVec2(4, 4);
2555 GetForegroundDrawList()->AddRectFilled(text_pos, text_pos + text_size, IM_COL32(0, 0, 0, 255));
2556 GetForegroundDrawList()->AddText(text_pos, IM_COL32(255, 255, 0, 255), buf, NULL);
2557 GetForegroundDrawList()->AddRect(merge_group->ClipRect.Min, merge_group->ClipRect.Max, IM_COL32(255, 255, 0, 255));
2562 if (merge_group_mask != 0)
2565 const int LEADING_DRAW_CHANNELS = 2;
2566 g.DrawChannelsTempMergeBuffer.resize(splitter->_Count - LEADING_DRAW_CHANNELS);
2567 ImDrawChannel* dst_tmp =
g.DrawChannelsTempMergeBuffer.Data;
2568 ImBitArraySetBitRange(remaining_mask, LEADING_DRAW_CHANNELS, splitter->_Count);
2569 ImBitArrayClearBit(remaining_mask, table->Bg2DrawChannelUnfrozen);
2570 IM_ASSERT(has_freeze_v ==
false || table->Bg2DrawChannelUnfrozen != TABLE_DRAW_CHANNEL_BG2_FROZEN);
2571 int remaining_count = splitter->_Count - (has_freeze_v ? LEADING_DRAW_CHANNELS + 1 : LEADING_DRAW_CHANNELS);
2573 ImRect host_rect = table->HostClipRect;
2574 for (
int merge_group_n = 0; merge_group_n < IM_ARRAYSIZE(merge_groups); merge_group_n++)
2576 if (
int merge_channels_count = merge_groups[merge_group_n].ChannelsCount)
2578 MergeGroup* merge_group = &merge_groups[merge_group_n];
2579 ImRect merge_clip_rect = merge_group->ClipRect;
2588 if ((merge_group_n & 1) == 0 || !has_freeze_h)
2589 merge_clip_rect.Min.x = ImMin(merge_clip_rect.Min.x, host_rect.Min.x);
2590 if ((merge_group_n & 2) == 0 || !has_freeze_v)
2591 merge_clip_rect.Min.y = ImMin(merge_clip_rect.Min.y, host_rect.Min.y);
2592 if ((merge_group_n & 1) != 0)
2593 merge_clip_rect.Max.x = ImMax(merge_clip_rect.Max.x, host_rect.Max.x);
2594 if ((merge_group_n & 2) != 0 && (table->Flags & ImGuiTableFlags_NoHostExtendY) == 0)
2595 merge_clip_rect.Max.y = ImMax(merge_clip_rect.Max.y, host_rect.Max.y);
2599 remaining_count -= merge_group->ChannelsCount;
2600 for (
int n = 0; n < (size_for_masks_bitarrays_one >> 2); n++)
2601 remaining_mask[n] &= ~merge_group->ChannelsMask[n];
2602 for (
int n = 0; n < splitter->_Count && merge_channels_count != 0; n++)
2605 if (!IM_BITARRAY_TESTBIT(merge_group->ChannelsMask, n))
2607 IM_BITARRAY_CLEARBIT(merge_group->ChannelsMask, n);
2608 merge_channels_count--;
2610 ImDrawChannel* channel = &splitter->_Channels[n];
2611 IM_ASSERT(channel->_CmdBuffer.Size == 1 && merge_clip_rect.Contains(ImRect(channel->_CmdBuffer[0].ClipRect)));
2612 channel->_CmdBuffer[0].ClipRect = merge_clip_rect.ToVec4();
2613 memcpy(dst_tmp++, channel,
sizeof(ImDrawChannel));
2618 if (merge_group_n == 1 && has_freeze_v)
2619 memcpy(dst_tmp++, &splitter->_Channels[table->Bg2DrawChannelUnfrozen],
sizeof(ImDrawChannel));
2623 for (
int n = 0; n < splitter->_Count && remaining_count != 0; n++)
2625 if (!IM_BITARRAY_TESTBIT(remaining_mask, n))
2627 ImDrawChannel* channel = &splitter->_Channels[n];
2628 memcpy(dst_tmp++, channel,
sizeof(ImDrawChannel));
2631 IM_ASSERT(dst_tmp ==
g.DrawChannelsTempMergeBuffer.Data +
g.DrawChannelsTempMergeBuffer.Size);
2632 memcpy(splitter->_Channels.Data + LEADING_DRAW_CHANNELS,
g.DrawChannelsTempMergeBuffer.Data, (splitter->_Count - LEADING_DRAW_CHANNELS) *
sizeof(ImDrawChannel));
2636static ImU32 TableGetColumnBorderCol(ImGuiTable* table,
int order_n,
int column_n)
2638 const bool is_hovered = (table->HoveredColumnBorder == column_n);
2639 const bool is_resized = (table->ResizedColumn == column_n) && (table->InstanceInteracted == table->InstanceCurrent);
2640 const bool is_frozen_separator = (table->FreezeColumnsCount == order_n + 1);
2641 if (is_resized || is_hovered)
2642 return ImGui::GetColorU32(is_resized ? ImGuiCol_SeparatorActive : ImGuiCol_SeparatorHovered);
2643 if (is_frozen_separator || (table->Flags & (ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_NoBordersInBodyUntilResize)))
2644 return table->BorderColorStrong;
2645 return table->BorderColorLight;
2649void ImGui::TableDrawBorders(ImGuiTable* table)
2651 ImGuiWindow* inner_window = table->InnerWindow;
2652 if (!table->OuterWindow->ClipRect.Overlaps(table->OuterRect))
2655 ImDrawList* inner_drawlist = inner_window->DrawList;
2656 table->DrawSplitter->SetCurrentChannel(inner_drawlist, TABLE_DRAW_CHANNEL_BG0);
2657 inner_drawlist->PushClipRect(table->Bg0ClipRectForDrawCmd.Min, table->Bg0ClipRectForDrawCmd.Max,
false);
2660 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
2661 const float border_size = TABLE_BORDER_SIZE;
2662 const float draw_y1 = ImMax(table->InnerRect.Min.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table->AngledHeadersHeight) + ((table->Flags & ImGuiTableFlags_BordersOuterH) ? 1.0f : 0.0f);
2663 const float draw_y2_body = table->InnerRect.Max.y;
2664 const float draw_y2_head = table->IsUsingHeaders ? ImMin(table->InnerRect.Max.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table_instance->LastTopHeadersRowHeight) : draw_y1;
2665 if (table->Flags & ImGuiTableFlags_BordersInnerV)
2667 for (
int order_n = 0; order_n < table->ColumnsCount; order_n++)
2669 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n))
2672 const int column_n = table->DisplayOrderToIndex[order_n];
2673 ImGuiTableColumn* column = &table->Columns[column_n];
2674 const bool is_hovered = (table->HoveredColumnBorder == column_n);
2675 const bool is_resized = (table->ResizedColumn == column_n) && (table->InstanceInteracted == table->InstanceCurrent);
2676 const bool is_resizable = (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_)) == 0;
2677 const bool is_frozen_separator = (table->FreezeColumnsCount == order_n + 1);
2678 if (column->MaxX > table->InnerClipRect.Max.x && !is_resized)
2682 if (column->NextEnabledColumn == -1 && !is_resizable)
2683 if ((table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame || (table->Flags & ImGuiTableFlags_NoHostExtendX))
2685 if (column->MaxX <= column->ClipRect.Min.x)
2690 float draw_y2 = (is_hovered || is_resized || is_frozen_separator || (table->Flags & (ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_NoBordersInBodyUntilResize)) == 0) ? draw_y2_body : draw_y2_head;
2691 if (draw_y2 > draw_y1)
2692 inner_drawlist->AddLine(ImVec2(column->MaxX, draw_y1), ImVec2(column->MaxX, draw_y2), TableGetColumnBorderCol(table, order_n, column_n), border_size);
2698 if (table->Flags & ImGuiTableFlags_BordersOuter)
2705 const ImRect outer_border = table->OuterRect;
2706 const ImU32 outer_col = table->BorderColorStrong;
2707 if ((table->Flags & ImGuiTableFlags_BordersOuter) == ImGuiTableFlags_BordersOuter)
2709 inner_drawlist->AddRect(outer_border.Min, outer_border.Max + ImVec2(1, 1), outer_col, 0.0f, 0, border_size);
2711 else if (table->Flags & ImGuiTableFlags_BordersOuterV)
2713 inner_drawlist->AddLine(outer_border.Min, ImVec2(outer_border.Min.x, outer_border.Max.y), outer_col, border_size);
2714 inner_drawlist->AddLine(ImVec2(outer_border.Max.x, outer_border.Min.y), outer_border.Max, outer_col, border_size);
2716 else if (table->Flags & ImGuiTableFlags_BordersOuterH)
2718 inner_drawlist->AddLine(outer_border.Min, ImVec2(outer_border.Max.x, outer_border.Min.y), outer_col, border_size);
2719 inner_drawlist->AddLine(ImVec2(outer_border.Min.x, outer_border.Max.y), outer_border.Max, outer_col, border_size);
2722 if ((table->Flags & ImGuiTableFlags_BordersInnerH) && table->RowPosY2 < table->OuterRect.Max.y)
2725 const float border_y = table->RowPosY2;
2726 if (border_y >= table->BgClipRect.Min.y && border_y < table->BgClipRect.Max.y)
2727 inner_drawlist->AddLine(ImVec2(table->BorderX1, border_y), ImVec2(table->BorderX2, border_y), table->BorderColorLight, border_size);
2730 inner_drawlist->PopClipRect();
2749ImGuiTableSortSpecs* ImGui::TableGetSortSpecs()
2752 ImGuiTable* table =
g.CurrentTable;
2753 IM_ASSERT(table != NULL);
2755 if (!(table->Flags & ImGuiTableFlags_Sortable))
2759 if (!table->IsLayoutLocked)
2760 TableUpdateLayout(table);
2762 TableSortSpecsBuild(table);
2763 return &table->SortSpecs;
2766static inline ImGuiSortDirection TableGetColumnAvailSortDirection(ImGuiTableColumn* column,
int n)
2768 IM_ASSERT(n < column->SortDirectionsAvailCount);
2769 return (column->SortDirectionsAvailList >> (n << 1)) & 0x03;
2773void ImGui::TableFixColumnSortDirection(ImGuiTable* table, ImGuiTableColumn* column)
2775 if (column->SortOrder == -1 || (column->SortDirectionsAvailMask & (1 << column->SortDirection)) != 0)
2777 column->SortDirection = (ImU8)TableGetColumnAvailSortDirection(column, 0);
2778 table->IsSortSpecsDirty =
true;
2784IM_STATIC_ASSERT(ImGuiSortDirection_None == 0 && ImGuiSortDirection_Ascending == 1 && ImGuiSortDirection_Descending == 2);
2785ImGuiSortDirection ImGui::TableGetColumnNextSortDirection(ImGuiTableColumn* column)
2787 IM_ASSERT(column->SortDirectionsAvailCount > 0);
2788 if (column->SortOrder == -1)
2789 return TableGetColumnAvailSortDirection(column, 0);
2790 for (
int n = 0; n < 3; n++)
2791 if (column->SortDirection == TableGetColumnAvailSortDirection(column, n))
2792 return TableGetColumnAvailSortDirection(column, (n + 1) % column->SortDirectionsAvailCount);
2794 return ImGuiSortDirection_None;
2799void ImGui::TableSetColumnSortDirection(
int column_n, ImGuiSortDirection sort_direction,
bool append_to_sort_specs)
2802 ImGuiTable* table =
g.CurrentTable;
2804 if (!(table->Flags & ImGuiTableFlags_SortMulti))
2805 append_to_sort_specs =
false;
2806 if (!(table->Flags & ImGuiTableFlags_SortTristate))
2807 IM_ASSERT(sort_direction != ImGuiSortDirection_None);
2809 ImGuiTableColumnIdx sort_order_max = 0;
2810 if (append_to_sort_specs)
2811 for (
int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++)
2812 sort_order_max = ImMax(sort_order_max, table->Columns[other_column_n].SortOrder);
2814 ImGuiTableColumn* column = &table->Columns[column_n];
2815 column->SortDirection = (ImU8)sort_direction;
2816 if (column->SortDirection == ImGuiSortDirection_None)
2817 column->SortOrder = -1;
2818 else if (column->SortOrder == -1 || !append_to_sort_specs)
2819 column->SortOrder = append_to_sort_specs ? sort_order_max + 1 : 0;
2821 for (
int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++)
2823 ImGuiTableColumn* other_column = &table->Columns[other_column_n];
2824 if (other_column != column && !append_to_sort_specs)
2825 other_column->SortOrder = -1;
2826 TableFixColumnSortDirection(table, other_column);
2828 table->IsSettingsDirty =
true;
2829 table->IsSortSpecsDirty =
true;
2832void ImGui::TableSortSpecsSanitize(ImGuiTable* table)
2834 IM_ASSERT(table->Flags & ImGuiTableFlags_Sortable);
2837 int sort_order_count = 0;
2838 ImU64 sort_order_mask = 0x00;
2839 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2841 ImGuiTableColumn* column = &table->Columns[column_n];
2842 if (column->SortOrder != -1 && !column->IsEnabled)
2843 column->SortOrder = -1;
2844 if (column->SortOrder == -1)
2847 sort_order_mask |= ((ImU64)1 << column->SortOrder);
2848 IM_ASSERT(sort_order_count < (
int)
sizeof(sort_order_mask) * 8);
2851 const bool need_fix_linearize = ((ImU64)1 << sort_order_count) != (sort_order_mask + 1);
2852 const bool need_fix_single_sort_order = (sort_order_count > 1) && !(table->Flags & ImGuiTableFlags_SortMulti);
2853 if (need_fix_linearize || need_fix_single_sort_order)
2855 ImU64 fixed_mask = 0x00;
2856 for (
int sort_n = 0; sort_n < sort_order_count; sort_n++)
2860 int column_with_smallest_sort_order = -1;
2861 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2862 if ((fixed_mask & ((ImU64)1 << (ImU64)column_n)) == 0 && table->Columns[column_n].SortOrder != -1)
2863 if (column_with_smallest_sort_order == -1 || table->Columns[column_n].SortOrder < table->Columns[column_with_smallest_sort_order].SortOrder)
2864 column_with_smallest_sort_order = column_n;
2865 IM_ASSERT(column_with_smallest_sort_order != -1);
2866 fixed_mask |= ((ImU64)1 << column_with_smallest_sort_order);
2867 table->Columns[column_with_smallest_sort_order].SortOrder = (ImGuiTableColumnIdx)sort_n;
2870 if (need_fix_single_sort_order)
2872 sort_order_count = 1;
2873 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2874 if (column_n != column_with_smallest_sort_order)
2875 table->Columns[column_n].SortOrder = -1;
2882 if (sort_order_count == 0 && !(table->Flags & ImGuiTableFlags_SortTristate))
2883 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2885 ImGuiTableColumn* column = &table->Columns[column_n];
2886 if (column->IsEnabled && !(column->Flags & ImGuiTableColumnFlags_NoSort))
2888 sort_order_count = 1;
2889 column->SortOrder = 0;
2890 column->SortDirection = (ImU8)TableGetColumnAvailSortDirection(column, 0);
2895 table->SortSpecsCount = (ImGuiTableColumnIdx)sort_order_count;
2898void ImGui::TableSortSpecsBuild(ImGuiTable* table)
2900 bool dirty = table->IsSortSpecsDirty;
2903 TableSortSpecsSanitize(table);
2904 table->SortSpecsMulti.resize(table->SortSpecsCount <= 1 ? 0 : table->SortSpecsCount);
2905 table->SortSpecs.SpecsDirty =
true;
2906 table->IsSortSpecsDirty =
false;
2910 ImGuiTableColumnSortSpecs* sort_specs = (table->SortSpecsCount == 0) ? NULL : (table->SortSpecsCount == 1) ? &table->SortSpecsSingle : table->SortSpecsMulti.Data;
2911 if (dirty && sort_specs != NULL)
2912 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2914 ImGuiTableColumn* column = &table->Columns[column_n];
2915 if (column->SortOrder == -1)
2917 IM_ASSERT(column->SortOrder < table->SortSpecsCount);
2918 ImGuiTableColumnSortSpecs* sort_spec = &sort_specs[column->SortOrder];
2919 sort_spec->ColumnUserID = column->UserID;
2920 sort_spec->ColumnIndex = (ImGuiTableColumnIdx)column_n;
2921 sort_spec->SortOrder = (ImGuiTableColumnIdx)column->SortOrder;
2922 sort_spec->SortDirection = column->SortDirection;
2925 table->SortSpecs.Specs = sort_specs;
2926 table->SortSpecs.SpecsCount = table->SortSpecsCount;
2940float ImGui::TableGetHeaderRowHeight()
2947 ImGuiTable* table =
g.CurrentTable;
2948 float row_height =
g.FontSize;
2949 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2950 if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
2951 if ((table->Columns[column_n].Flags & ImGuiTableColumnFlags_NoHeaderLabel) == 0)
2952 row_height = ImMax(row_height,
CalcTextSize(TableGetColumnName(table, column_n)).y);
2953 return row_height +
g.Style.CellPadding.y * 2.0f;
2956float ImGui::TableGetHeaderAngledMaxLabelWidth()
2959 ImGuiTable* table =
g.CurrentTable;
2961 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2962 if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
2963 if (table->Columns[column_n].Flags & ImGuiTableColumnFlags_AngledHeader)
2964 width = ImMax(width,
CalcTextSize(TableGetColumnName(table, column_n), NULL,
true).x);
2965 return width +
g.Style.CellPadding.y * 2.0f;
2974void ImGui::TableHeadersRow()
2977 ImGuiTable* table =
g.CurrentTable;
2978 IM_ASSERT(table != NULL &&
"Need to call TableHeadersRow() after BeginTable()!");
2981 if (!table->IsLayoutLocked)
2982 TableUpdateLayout(table);
2985 const float row_height = TableGetHeaderRowHeight();
2986 TableNextRow(ImGuiTableRowFlags_Headers, row_height);
2987 const float row_y1 = GetCursorScreenPos().y;
2988 if (table->HostSkipItems)
2991 const int columns_count = TableGetColumnCount();
2992 for (
int column_n = 0; column_n < columns_count; column_n++)
2994 if (!TableSetColumnIndex(column_n))
2999 const char* name = (TableGetColumnFlags(column_n) & ImGuiTableColumnFlags_NoHeaderLabel) ?
"" : TableGetColumnName(column_n);
3006 ImVec2 mouse_pos = ImGui::GetMousePos();
3007 if (IsMouseReleased(1) && TableGetHoveredColumn() == columns_count)
3008 if (mouse_pos.y >= row_y1 && mouse_pos.y < row_y1 + row_height)
3009 TableOpenContextMenu(columns_count);
3015void ImGui::TableHeader(
const char* label)
3018 ImGuiWindow* window =
g.CurrentWindow;
3019 if (window->SkipItems)
3022 ImGuiTable* table =
g.CurrentTable;
3023 IM_ASSERT(table != NULL &&
"Need to call TableHeader() after BeginTable()!");
3024 IM_ASSERT(table->CurrentColumn != -1);
3025 const int column_n = table->CurrentColumn;
3026 ImGuiTableColumn* column = &table->Columns[column_n];
3031 const char* label_end = FindRenderedTextEnd(label);
3032 ImVec2 label_size =
CalcTextSize(label, label_end,
true);
3033 ImVec2 label_pos = window->DC.CursorPos;
3037 ImRect cell_r = TableGetCellBgRect(table, column_n);
3038 float label_height = ImMax(label_size.y, table->RowMinHeight - table->RowCellPaddingY * 2.0f);
3041 float w_arrow = 0.0f;
3042 float w_sort_text = 0.0f;
3043 bool sort_arrow =
false;
3044 char sort_order_suf[4] =
"";
3045 const float ARROW_SCALE = 0.65f;
3046 if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort))
3048 w_arrow = ImTrunc(
g.FontSize * ARROW_SCALE +
g.Style.FramePadding.x);
3049 if (column->SortOrder != -1)
3051 if (column->SortOrder > 0)
3053 ImFormatString(sort_order_suf, IM_ARRAYSIZE(sort_order_suf),
"%d", column->SortOrder + 1);
3054 w_sort_text =
g.Style.ItemInnerSpacing.x +
CalcTextSize(sort_order_suf).x;
3059 float max_pos_x = label_pos.x + label_size.x + w_sort_text + w_arrow;
3060 column->ContentMaxXHeadersUsed = ImMax(column->ContentMaxXHeadersUsed, sort_arrow ? cell_r.Max.x : ImMin(max_pos_x, cell_r.Max.x));
3061 column->ContentMaxXHeadersIdeal = ImMax(column->ContentMaxXHeadersIdeal, max_pos_x);
3064 ImGuiID
id = window->GetID(label);
3065 ImRect bb(cell_r.Min.x, cell_r.Min.y, cell_r.Max.x, ImMax(cell_r.Max.y, cell_r.Min.y + label_height +
g.Style.CellPadding.y * 2.0f));
3066 ItemSize(ImVec2(0.0f, label_height));
3067 if (!ItemAdd(bb,
id))
3074 const bool highlight = (table->HighlightColumnHeader == column_n);
3076 bool pressed = ButtonBehavior(bb,
id, &hovered, &held, ImGuiButtonFlags_AllowOverlap);
3077 if (held || hovered || highlight)
3079 const ImU32 col = GetColorU32(held ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
3081 TableSetBgColor(ImGuiTableBgTarget_CellBg, col, table->CurrentColumn);
3086 if ((table->RowFlags & ImGuiTableRowFlags_Headers) == 0)
3087 TableSetBgColor(ImGuiTableBgTarget_CellBg, GetColorU32(ImGuiCol_TableHeaderBg), table->CurrentColumn);
3089 RenderNavHighlight(bb,
id, ImGuiNavHighlightFlags_Compact | ImGuiNavHighlightFlags_NoRounding);
3091 table->HeldHeaderColumn = (ImGuiTableColumnIdx)column_n;
3092 window->DC.CursorPos.y -=
g.Style.ItemSpacing.y * 0.5f;
3096 if (held && (table->Flags & ImGuiTableFlags_Reorderable) && IsMouseDragging(0) && !
g.DragDropActive)
3099 table->ReorderColumn = (ImGuiTableColumnIdx)column_n;
3100 table->InstanceInteracted = table->InstanceCurrent;
3103 if (
g.IO.MouseDelta.x < 0.0f &&
g.IO.MousePos.x < cell_r.Min.x)
3104 if (ImGuiTableColumn* prev_column = (column->PrevEnabledColumn != -1) ? &table->Columns[column->PrevEnabledColumn] : NULL)
3105 if (!((column->Flags | prev_column->Flags) & ImGuiTableColumnFlags_NoReorder))
3106 if ((column->IndexWithinEnabledSet < table->FreezeColumnsRequest) == (prev_column->IndexWithinEnabledSet < table->FreezeColumnsRequest))
3107 table->ReorderColumnDir = -1;
3108 if (
g.IO.MouseDelta.x > 0.0f &&
g.IO.MousePos.x > cell_r.Max.x)
3109 if (ImGuiTableColumn* next_column = (column->NextEnabledColumn != -1) ? &table->Columns[column->NextEnabledColumn] : NULL)
3110 if (!((column->Flags | next_column->Flags) & ImGuiTableColumnFlags_NoReorder))
3111 if ((column->IndexWithinEnabledSet < table->FreezeColumnsRequest) == (next_column->IndexWithinEnabledSet < table->FreezeColumnsRequest))
3112 table->ReorderColumnDir = +1;
3116 const float ellipsis_max = ImMax(cell_r.Max.x - w_arrow - w_sort_text, label_pos.x);
3117 if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort))
3119 if (column->SortOrder != -1)
3121 float x = ImMax(cell_r.Min.x, cell_r.Max.x - w_arrow - w_sort_text);
3122 float y = label_pos.y;
3123 if (column->SortOrder > 0)
3125 PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_Text, 0.70f));
3126 RenderText(ImVec2(x +
g.Style.ItemInnerSpacing.x, y), sort_order_suf);
3130 RenderArrow(window->DrawList, ImVec2(x, y), GetColorU32(ImGuiCol_Text), column->SortDirection == ImGuiSortDirection_Ascending ? ImGuiDir_Up : ImGuiDir_Down, ARROW_SCALE);
3134 if (pressed && table->ReorderColumn != column_n)
3136 ImGuiSortDirection sort_direction = TableGetColumnNextSortDirection(column);
3137 TableSetColumnSortDirection(column_n, sort_direction,
g.IO.KeyShift);
3144 RenderTextEllipsis(window->DrawList, label_pos, ImVec2(ellipsis_max, label_pos.y + label_height +
g.Style.FramePadding.y), ellipsis_max, ellipsis_max, label, label_end, &label_size);
3146 const bool text_clipped = label_size.x > (ellipsis_max - label_pos.x);
3147 if (text_clipped && hovered &&
g.ActiveId == 0)
3148 SetItemTooltip(
"%.*s", (
int)(label_end - label), label);
3151 if (IsMouseReleased(1) && IsItemHovered())
3152 TableOpenContextMenu(column_n);
3158void ImGui::TableAngledHeadersRow()
3161 TableAngledHeadersRowEx(
g.Style.TableAngledHeadersAngle, 0.0f);
3164void ImGui::TableAngledHeadersRowEx(
float angle,
float max_label_width)
3167 ImGuiTable* table =
g.CurrentTable;
3168 ImGuiWindow* window =
g.CurrentWindow;
3169 ImDrawList* draw_list = window->DrawList;
3170 IM_ASSERT(table != NULL &&
"Need to call TableHeadersRow() after BeginTable()!");
3171 IM_ASSERT(table->CurrentRow == -1 &&
"Must be first row");
3173 if (max_label_width == 0.0f)
3174 max_label_width = TableGetHeaderAngledMaxLabelWidth();
3177 const bool flip_label = (angle < 0.0f);
3178 angle -= IM_PI * 0.5f;
3179 const float cos_a = ImCos(angle);
3180 const float sin_a = ImSin(angle);
3181 const float label_cos_a = flip_label ? ImCos(angle + IM_PI) : cos_a;
3182 const float label_sin_a = flip_label ? ImSin(angle + IM_PI) : sin_a;
3183 const ImVec2 unit_right = ImVec2(cos_a, sin_a);
3187 const float header_height =
g.FontSize +
g.Style.CellPadding.x * 2.0f;
3188 const float row_height = ImFabs(ImRotate(ImVec2(max_label_width, flip_label ? +header_height : -header_height), cos_a, sin_a).y);
3189 table->AngledHeadersHeight = row_height;
3190 table->AngledHeadersSlope = (sin_a != 0.0f) ? (cos_a / sin_a) : 0.0f;
3191 const ImVec2 header_angled_vector = unit_right * (row_height / -sin_a);
3194 TableNextRow(ImGuiTableRowFlags_Headers, row_height);
3196 const ImRect row_r(table->WorkRect.Min.x, table->BgClipRect.Min.y, table->WorkRect.Max.x, table->RowPosY2);
3197 table->DrawSplitter->SetCurrentChannel(draw_list, TABLE_DRAW_CHANNEL_BG0);
3198 float clip_rect_min_x = table->BgClipRect.Min.x;
3199 if (table->FreezeColumnsCount > 0)
3200 clip_rect_min_x = ImMax(clip_rect_min_x, table->Columns[table->FreezeColumnsCount - 1].MaxX);
3201 TableSetBgColor(ImGuiTableBgTarget_RowBg0, 0);
3202 PushClipRect(table->BgClipRect.Min, table->BgClipRect.Max,
false);
3203 draw_list->AddRectFilled(ImVec2(table->BgClipRect.Min.x, row_r.Min.y), ImVec2(table->BgClipRect.Max.x, row_r.Max.y), GetColorU32(ImGuiCol_TableHeaderBg, 0.25f));
3204 PushClipRect(ImVec2(clip_rect_min_x, table->BgClipRect.Min.y), table->BgClipRect.Max,
true);
3206 const ImGuiID row_id = GetID(
"##AngledHeaders");
3207 ButtonBehavior(row_r, row_id, NULL, NULL);
3208 KeepAliveID(row_id);
3210 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
3211 int highlight_column_n = table->HighlightColumnHeader;
3212 if (highlight_column_n == -1 && table->HoveredColumnBody != -1)
3213 if (table_instance->HoveredRowLast == 0 && table->HoveredColumnBorder == -1 && (
g.ActiveId == 0 ||
g.ActiveId == row_id || (table->IsActiveIdInTable ||
g.DragDropActive)))
3214 highlight_column_n = table->HoveredColumnBody;
3218 ImVec2 padding =
g.Style.CellPadding;
3219 for (
int pass = 0; pass < 2; pass++)
3220 for (
int order_n = 0; order_n < table->ColumnsCount; order_n++)
3222 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n))
3224 const int column_n = table->DisplayOrderToIndex[order_n];
3225 ImGuiTableColumn* column = &table->Columns[column_n];
3226 if ((column->Flags & ImGuiTableColumnFlags_AngledHeader) == 0)
3230 bg_shape[0] = ImVec2(column->MaxX, row_r.Max.y);
3231 bg_shape[1] = ImVec2(column->MinX, row_r.Max.y);
3232 bg_shape[2] = bg_shape[1] + header_angled_vector;
3233 bg_shape[3] = bg_shape[0] + header_angled_vector;
3237 draw_list->AddQuadFilled(bg_shape[0], bg_shape[1], bg_shape[2], bg_shape[3], GetColorU32(ImGuiCol_TableHeaderBg));
3238 if (column_n == highlight_column_n)
3239 draw_list->AddQuadFilled(bg_shape[0], bg_shape[1], bg_shape[2], bg_shape[3], GetColorU32(ImGuiCol_Header));
3240 max_x = ImMax(max_x, bg_shape[3].x);
3245 const char* label_name = TableGetColumnName(table, column_n);
3246 const char* label_name_end = FindRenderedTextEnd(label_name);
3247 const float line_off_step_x =
g.FontSize / -sin_a;
3248 float line_off_curr_x = 0.0f;
3249 while (label_name < label_name_end)
3251 const char* label_name_eol = strchr(label_name,
'\n');
3252 if (label_name_eol == NULL)
3253 label_name_eol = label_name_end;
3256 ImVec2 label_size =
CalcTextSize(label_name, label_name_eol);
3257 float clip_width = max_label_width - padding.y;
3258 float clip_height = ImMin(label_size.y, column->ClipRect.Max.x - column->WorkMinX - line_off_curr_x);
3259 ImRect clip_r(window->ClipRect.Min, window->ClipRect.Min + ImVec2(clip_width, clip_height));
3260 int vtx_idx_begin = draw_list->_VtxCurrentIdx;
3261 RenderTextEllipsis(draw_list, clip_r.Min, clip_r.Max, clip_r.Max.x, clip_r.Max.x, label_name, label_name_eol, &label_size);
3262 int vtx_idx_end = draw_list->_VtxCurrentIdx;
3265 ImVec2 pivot_in = ImVec2(window->ClipRect.Min.x, window->ClipRect.Min.y + label_size.y);
3266 ImVec2 pivot_out = ImVec2(column->WorkMinX, row_r.Max.y);
3267 line_off_curr_x += line_off_step_x;
3268 pivot_out += unit_right * padding.y;
3270 pivot_out += unit_right * (clip_width - ImMax(0.0f, clip_width - label_size.x));
3271 pivot_out.x += flip_label ? line_off_curr_x - line_off_step_x : line_off_curr_x;
3272 ShadeVertsTransformPos(draw_list, vtx_idx_begin, vtx_idx_end, pivot_in, label_cos_a, label_sin_a, pivot_out);
3276 column->ContentMaxXHeadersUsed = column->ContentMaxXHeadersIdeal = column->WorkMinX + ImCeil(line_off_curr_x);
3277 label_name = label_name_eol + 1;
3283 draw_list->AddLine(bg_shape[0], bg_shape[3], TableGetColumnBorderCol(table, order_n, column_n));
3288 table->TempData->AngledHeadersExtraWidth = ImMax(0.0f, max_x - table->Columns[table->RightMostEnabledColumn].MaxX);
3300void ImGui::TableOpenContextMenu(
int column_n)
3303 ImGuiTable* table =
g.CurrentTable;
3304 if (column_n == -1 && table->CurrentColumn != -1)
3305 column_n = table->CurrentColumn;
3306 if (column_n == table->ColumnsCount)
3308 IM_ASSERT(column_n >= -1 && column_n < table->ColumnsCount);
3309 if (table->Flags & (ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable))
3311 table->IsContextPopupOpen =
true;
3312 table->ContextPopupColumn = (ImGuiTableColumnIdx)column_n;
3313 table->InstanceInteracted = table->InstanceCurrent;
3314 const ImGuiID context_menu_id =
ImHashStr(
"##ContextMenu", 0, table->ID);
3315 OpenPopupEx(context_menu_id, ImGuiPopupFlags_None);
3319bool ImGui::TableBeginContextMenuPopup(ImGuiTable* table)
3321 if (!table->IsContextPopupOpen || table->InstanceCurrent != table->InstanceInteracted)
3323 const ImGuiID context_menu_id =
ImHashStr(
"##ContextMenu", 0, table->ID);
3324 if (BeginPopupEx(context_menu_id, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings))
3326 table->IsContextPopupOpen =
false;
3338void ImGui::TableDrawDefaultContextMenu(ImGuiTable* table, ImGuiTableFlags flags_for_section_to_display)
3341 ImGuiWindow* window =
g.CurrentWindow;
3342 if (window->SkipItems)
3345 bool want_separator =
false;
3346 const int column_n = (table->ContextPopupColumn >= 0 && table->ContextPopupColumn < table->ColumnsCount) ? table->ContextPopupColumn : -1;
3347 ImGuiTableColumn* column = (column_n != -1) ? &table->Columns[column_n] : NULL;
3350 if (flags_for_section_to_display & ImGuiTableFlags_Resizable)
3354 const bool can_resize = !(column->Flags & ImGuiTableColumnFlags_NoResize) && column->IsEnabled;
3355 if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableSizeOne), NULL,
false, can_resize))
3356 TableSetColumnWidthAutoSingle(table, column_n);
3359 const char* size_all_desc;
3360 if (table->ColumnsEnabledFixedCount == table->ColumnsEnabledCount && (table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame)
3361 size_all_desc = LocalizeGetMsg(ImGuiLocKey_TableSizeAllFit);
3363 size_all_desc = LocalizeGetMsg(ImGuiLocKey_TableSizeAllDefault);
3364 if (MenuItem(size_all_desc, NULL))
3365 TableSetColumnWidthAutoAll(table);
3366 want_separator =
true;
3370 if (flags_for_section_to_display & ImGuiTableFlags_Reorderable)
3372 if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetOrder), NULL,
false, !table->IsDefaultDisplayOrder))
3373 table->IsResetDisplayOrderRequest =
true;
3374 want_separator =
true;
3384 if ((flags_for_section_to_display & ImGuiTableFlags_Sortable) && column != NULL && (column->Flags & ImGuiTableColumnFlags_NoSort) == 0)
3388 want_separator =
true;
3390 bool append_to_sort_specs =
g.IO.KeyShift;
3391 if (MenuItem(
"Sort in Ascending Order", NULL, column->SortOrder != -1 && column->SortDirection == ImGuiSortDirection_Ascending, (column->Flags & ImGuiTableColumnFlags_NoSortAscending) == 0))
3392 TableSetColumnSortDirection(table, column_n, ImGuiSortDirection_Ascending, append_to_sort_specs);
3393 if (MenuItem(
"Sort in Descending Order", NULL, column->SortOrder != -1 && column->SortDirection == ImGuiSortDirection_Descending, (column->Flags & ImGuiTableColumnFlags_NoSortDescending) == 0))
3394 TableSetColumnSortDirection(table, column_n, ImGuiSortDirection_Descending, append_to_sort_specs);
3399 if (flags_for_section_to_display & ImGuiTableFlags_Hideable)
3403 want_separator =
true;
3405 PushItemFlag(ImGuiItemFlags_SelectableDontClosePopup,
true);
3406 for (
int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++)
3408 ImGuiTableColumn* other_column = &table->Columns[other_column_n];
3409 if (other_column->Flags & ImGuiTableColumnFlags_Disabled)
3412 const char* name = TableGetColumnName(table, other_column_n);
3413 if (name == NULL || name[0] == 0)
3417 bool menu_item_active = (other_column->Flags & ImGuiTableColumnFlags_NoHide) ?
false : true;
3418 if (other_column->IsUserEnabled && table->ColumnsEnabledCount <= 1)
3419 menu_item_active =
false;
3420 if (MenuItem(name, NULL, other_column->IsUserEnabled, menu_item_active))
3421 other_column->IsUserEnabledNextFrame = !other_column->IsUserEnabled;
3454static void TableSettingsInit(ImGuiTableSettings* settings, ImGuiID
id,
int columns_count,
int columns_count_max)
3456 IM_PLACEMENT_NEW(settings) ImGuiTableSettings();
3457 ImGuiTableColumnSettings* settings_column = settings->GetColumnSettings();
3458 for (
int n = 0; n < columns_count_max; n++, settings_column++)
3459 IM_PLACEMENT_NEW(settings_column) ImGuiTableColumnSettings();
3461 settings->ColumnsCount = (ImGuiTableColumnIdx)columns_count;
3462 settings->ColumnsCountMax = (ImGuiTableColumnIdx)columns_count_max;
3463 settings->WantApply =
true;
3466static size_t TableSettingsCalcChunkSize(
int columns_count)
3468 return sizeof(ImGuiTableSettings) + (
size_t)columns_count *
sizeof(ImGuiTableColumnSettings);
3471ImGuiTableSettings* ImGui::TableSettingsCreate(ImGuiID
id,
int columns_count)
3474 ImGuiTableSettings* settings =
g.SettingsTables.alloc_chunk(TableSettingsCalcChunkSize(columns_count));
3475 TableSettingsInit(settings,
id, columns_count, columns_count);
3480ImGuiTableSettings* ImGui::TableSettingsFindByID(ImGuiID
id)
3484 for (ImGuiTableSettings* settings =
g.SettingsTables.begin(); settings != NULL; settings =
g.SettingsTables.next_chunk(settings))
3485 if (settings->ID ==
id)
3491ImGuiTableSettings* ImGui::TableGetBoundSettings(ImGuiTable* table)
3493 if (table->SettingsOffset != -1)
3496 ImGuiTableSettings* settings =
g.SettingsTables.ptr_from_offset(table->SettingsOffset);
3497 IM_ASSERT(settings->ID == table->ID);
3498 if (settings->ColumnsCountMax >= table->ColumnsCount)
3506void ImGui::TableResetSettings(ImGuiTable* table)
3508 table->IsInitializing = table->IsSettingsDirty =
true;
3509 table->IsResetAllRequest =
false;
3510 table->IsSettingsRequestLoad =
false;
3511 table->SettingsLoadedFlags = ImGuiTableFlags_None;
3514void ImGui::TableSaveSettings(ImGuiTable* table)
3516 table->IsSettingsDirty =
false;
3517 if (table->Flags & ImGuiTableFlags_NoSavedSettings)
3522 ImGuiTableSettings* settings = TableGetBoundSettings(table);
3523 if (settings == NULL)
3525 settings = TableSettingsCreate(table->ID, table->ColumnsCount);
3526 table->SettingsOffset =
g.SettingsTables.offset_from_ptr(settings);
3528 settings->ColumnsCount = (ImGuiTableColumnIdx)table->ColumnsCount;
3531 IM_ASSERT(settings->ID == table->ID);
3532 IM_ASSERT(settings->ColumnsCount == table->ColumnsCount && settings->ColumnsCountMax >= settings->ColumnsCount);
3533 ImGuiTableColumn* column = table->Columns.Data;
3534 ImGuiTableColumnSettings* column_settings = settings->GetColumnSettings();
3536 bool save_ref_scale =
false;
3537 settings->SaveFlags = ImGuiTableFlags_None;
3538 for (
int n = 0; n < table->ColumnsCount; n++, column++, column_settings++)
3540 const float width_or_weight = (column->Flags & ImGuiTableColumnFlags_WidthStretch) ? column->StretchWeight : column->WidthRequest;
3541 column_settings->WidthOrWeight = width_or_weight;
3542 column_settings->Index = (ImGuiTableColumnIdx)n;
3543 column_settings->DisplayOrder = column->DisplayOrder;
3544 column_settings->SortOrder = column->SortOrder;
3545 column_settings->SortDirection = column->SortDirection;
3546 column_settings->IsEnabled = column->IsUserEnabled;
3547 column_settings->IsStretch = (column->Flags & ImGuiTableColumnFlags_WidthStretch) ? 1 : 0;
3548 if ((column->Flags & ImGuiTableColumnFlags_WidthStretch) == 0)
3549 save_ref_scale =
true;
3554 if (width_or_weight != column->InitStretchWeightOrWidth)
3555 settings->SaveFlags |= ImGuiTableFlags_Resizable;
3556 if (column->DisplayOrder != n)
3557 settings->SaveFlags |= ImGuiTableFlags_Reorderable;
3558 if (column->SortOrder != -1)
3559 settings->SaveFlags |= ImGuiTableFlags_Sortable;
3560 if (column->IsUserEnabled != ((column->Flags & ImGuiTableColumnFlags_DefaultHide) == 0))
3561 settings->SaveFlags |= ImGuiTableFlags_Hideable;
3563 settings->SaveFlags &= table->Flags;
3564 settings->RefScale = save_ref_scale ? table->RefScale : 0.0f;
3566 MarkIniSettingsDirty();
3569void ImGui::TableLoadSettings(ImGuiTable* table)
3572 table->IsSettingsRequestLoad =
false;
3573 if (table->Flags & ImGuiTableFlags_NoSavedSettings)
3577 ImGuiTableSettings* settings;
3578 if (table->SettingsOffset == -1)
3580 settings = TableSettingsFindByID(table->ID);
3581 if (settings == NULL)
3583 if (settings->ColumnsCount != table->ColumnsCount)
3584 table->IsSettingsDirty =
true;
3585 table->SettingsOffset =
g.SettingsTables.offset_from_ptr(settings);
3589 settings = TableGetBoundSettings(table);
3592 table->SettingsLoadedFlags = settings->SaveFlags;
3593 table->RefScale = settings->RefScale;
3596 ImGuiTableColumnSettings* column_settings = settings->GetColumnSettings();
3597 ImU64 display_order_mask = 0;
3598 for (
int data_n = 0; data_n < settings->ColumnsCount; data_n++, column_settings++)
3600 int column_n = column_settings->Index;
3601 if (column_n < 0 || column_n >= table->ColumnsCount)
3604 ImGuiTableColumn* column = &table->Columns[column_n];
3605 if (settings->SaveFlags & ImGuiTableFlags_Resizable)
3607 if (column_settings->IsStretch)
3608 column->StretchWeight = column_settings->WidthOrWeight;
3610 column->WidthRequest = column_settings->WidthOrWeight;
3611 column->AutoFitQueue = 0x00;
3613 if (settings->SaveFlags & ImGuiTableFlags_Reorderable)
3614 column->DisplayOrder = column_settings->DisplayOrder;
3616 column->DisplayOrder = (ImGuiTableColumnIdx)column_n;
3617 display_order_mask |= (ImU64)1 << column->DisplayOrder;
3618 column->IsUserEnabled = column->IsUserEnabledNextFrame = column_settings->IsEnabled;
3619 column->SortOrder = column_settings->SortOrder;
3620 column->SortDirection = column_settings->SortDirection;
3624 const ImU64 expected_display_order_mask = (settings->ColumnsCount == 64) ? ~0 : ((ImU64)1 << settings->ColumnsCount) - 1;
3625 if (display_order_mask != expected_display_order_mask)
3626 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
3627 table->Columns[column_n].DisplayOrder = (ImGuiTableColumnIdx)column_n;
3630 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
3631 table->DisplayOrderToIndex[table->Columns[column_n].DisplayOrder] = (ImGuiTableColumnIdx)column_n;
3634static void TableSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
3636 ImGuiContext&
g = *ctx;
3637 for (
int i = 0; i !=
g.Tables.GetMapSize(); i++)
3638 if (ImGuiTable* table =
g.Tables.TryGetMapData(i))
3639 table->SettingsOffset = -1;
3640 g.SettingsTables.clear();
3644static void TableSettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
3646 ImGuiContext&
g = *ctx;
3647 for (
int i = 0; i !=
g.Tables.GetMapSize(); i++)
3648 if (ImGuiTable* table =
g.Tables.TryGetMapData(i))
3650 table->IsSettingsRequestLoad =
true;
3651 table->SettingsOffset = -1;
3655static void* TableSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*,
const char* name)
3658 int columns_count = 0;
3659 if (sscanf(name,
"0x%08X,%d", &
id, &columns_count) < 2)
3662 if (ImGuiTableSettings* settings = ImGui::TableSettingsFindByID(
id))
3664 if (settings->ColumnsCountMax >= columns_count)
3666 TableSettingsInit(settings,
id, columns_count, settings->ColumnsCountMax);
3671 return ImGui::TableSettingsCreate(
id, columns_count);
3674static void TableSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*,
void* entry,
const char* line)
3677 ImGuiTableSettings* settings = (ImGuiTableSettings*)entry;
3679 int column_n = 0, r = 0, n = 0;
3681 if (sscanf(line,
"RefScale=%f", &f) == 1) { settings->RefScale = f;
return; }
3683 if (sscanf(line,
"Column %d%n", &column_n, &r) == 1)
3685 if (column_n < 0 || column_n >= settings->ColumnsCount)
3689 ImGuiTableColumnSettings* column = settings->GetColumnSettings() + column_n;
3690 column->Index = (ImGuiTableColumnIdx)column_n;
3691 if (sscanf(line,
"UserID=0x%08X%n", (ImU32*)&n, &r)==1) { line =
ImStrSkipBlank(line + r); column->UserID = (ImGuiID)n; }
3692 if (sscanf(line,
"Width=%d%n", &n, &r) == 1) { line =
ImStrSkipBlank(line + r); column->WidthOrWeight = (float)n; column->IsStretch = 0; settings->SaveFlags |= ImGuiTableFlags_Resizable; }
3693 if (sscanf(line,
"Weight=%f%n", &f, &r) == 1) { line =
ImStrSkipBlank(line + r); column->WidthOrWeight = f; column->IsStretch = 1; settings->SaveFlags |= ImGuiTableFlags_Resizable; }
3694 if (sscanf(line,
"Visible=%d%n", &n, &r) == 1) { line =
ImStrSkipBlank(line + r); column->IsEnabled = (ImU8)n; settings->SaveFlags |= ImGuiTableFlags_Hideable; }
3695 if (sscanf(line,
"Order=%d%n", &n, &r) == 1) { line =
ImStrSkipBlank(line + r); column->DisplayOrder = (ImGuiTableColumnIdx)n; settings->SaveFlags |= ImGuiTableFlags_Reorderable; }
3696 if (sscanf(line,
"Sort=%d%c%n", &n, &c, &r) == 2) { line =
ImStrSkipBlank(line + r); column->SortOrder = (ImGuiTableColumnIdx)n; column->SortDirection = (c ==
'^') ? ImGuiSortDirection_Descending : ImGuiSortDirection_Ascending; settings->SaveFlags |= ImGuiTableFlags_Sortable; }
3700static void TableSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf)
3702 ImGuiContext&
g = *ctx;
3703 for (ImGuiTableSettings* settings =
g.SettingsTables.begin(); settings != NULL; settings =
g.SettingsTables.next_chunk(settings))
3705 if (settings->ID == 0)
3710 const bool save_size = (settings->SaveFlags & ImGuiTableFlags_Resizable) != 0;
3711 const bool save_visible = (settings->SaveFlags & ImGuiTableFlags_Hideable) != 0;
3712 const bool save_order = (settings->SaveFlags & ImGuiTableFlags_Reorderable) != 0;
3713 const bool save_sort = (settings->SaveFlags & ImGuiTableFlags_Sortable) != 0;
3714 if (!save_size && !save_visible && !save_order && !save_sort)
3717 buf->reserve(buf->size() + 30 + settings->ColumnsCount * 50);
3718 buf->appendf(
"[%s][0x%08X,%d]\n", handler->TypeName, settings->ID, settings->ColumnsCount);
3719 if (settings->RefScale != 0.0f)
3720 buf->appendf(
"RefScale=%g\n", settings->RefScale);
3721 ImGuiTableColumnSettings* column = settings->GetColumnSettings();
3722 for (
int column_n = 0; column_n < settings->ColumnsCount; column_n++, column++)
3725 bool save_column = column->UserID != 0 || save_size || save_visible || save_order || (save_sort && column->SortOrder != -1);
3728 buf->appendf(
"Column %-2d", column_n);
3729 if (column->UserID != 0) { buf->appendf(
" UserID=%08X", column->UserID); }
3730 if (save_size && column->IsStretch) { buf->appendf(
" Weight=%.4f", column->WidthOrWeight); }
3731 if (save_size && !column->IsStretch) { buf->appendf(
" Width=%d", (
int)column->WidthOrWeight); }
3732 if (save_visible) { buf->appendf(
" Visible=%d", column->IsEnabled); }
3733 if (save_order) { buf->appendf(
" Order=%d", column->DisplayOrder); }
3734 if (save_sort && column->SortOrder != -1) { buf->appendf(
" Sort=%d%c", column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ?
'v' :
'^'); }
3741void ImGui::TableSettingsAddSettingsHandler()
3743 ImGuiSettingsHandler ini_handler;
3744 ini_handler.TypeName =
"Table";
3745 ini_handler.TypeHash =
ImHashStr(
"Table");
3746 ini_handler.ClearAllFn = TableSettingsHandler_ClearAll;
3747 ini_handler.ReadOpenFn = TableSettingsHandler_ReadOpen;
3748 ini_handler.ReadLineFn = TableSettingsHandler_ReadLine;
3749 ini_handler.ApplyAllFn = TableSettingsHandler_ApplyAll;
3750 ini_handler.WriteAllFn = TableSettingsHandler_WriteAll;
3751 AddSettingsHandler(&ini_handler);
3763void ImGui::TableRemove(ImGuiTable* table)
3767 int table_idx =
g.Tables.GetIndex(table);
3770 g.Tables.Remove(table->ID, table);
3771 g.TablesLastTimeActive[table_idx] = -1.0f;
3775void ImGui::TableGcCompactTransientBuffers(ImGuiTable* table)
3779 IM_ASSERT(table->MemoryCompacted ==
false);
3780 table->SortSpecs.Specs = NULL;
3781 table->SortSpecsMulti.clear();
3782 table->IsSortSpecsDirty =
true;
3783 table->ColumnsNames.clear();
3784 table->MemoryCompacted =
true;
3785 for (
int n = 0; n < table->ColumnsCount; n++)
3786 table->Columns[n].NameOffset = -1;
3787 g.TablesLastTimeActive[
g.Tables.GetIndex(table)] = -1.0f;
3790void ImGui::TableGcCompactTransientBuffers(ImGuiTableTempData* temp_data)
3792 temp_data->DrawSplitter.ClearFreeMemory();
3793 temp_data->LastTimeActive = -1.0f;
3797void ImGui::TableGcCompactSettings()
3800 int required_memory = 0;
3801 for (ImGuiTableSettings* settings =
g.SettingsTables.begin(); settings != NULL; settings =
g.SettingsTables.next_chunk(settings))
3802 if (settings->ID != 0)
3803 required_memory += (int)TableSettingsCalcChunkSize(settings->ColumnsCount);
3804 if (required_memory ==
g.SettingsTables.Buf.Size)
3806 ImChunkStream<ImGuiTableSettings> new_chunk_stream;
3807 new_chunk_stream.Buf.reserve(required_memory);
3808 for (ImGuiTableSettings* settings =
g.SettingsTables.begin(); settings != NULL; settings =
g.SettingsTables.next_chunk(settings))
3809 if (settings->ID != 0)
3810 memcpy(new_chunk_stream.alloc_chunk(TableSettingsCalcChunkSize(settings->ColumnsCount)), settings, TableSettingsCalcChunkSize(settings->ColumnsCount));
3811 g.SettingsTables.swap(new_chunk_stream);
3821#ifndef IMGUI_DISABLE_DEBUG_TOOLS
3823static const char* DebugNodeTableGetSizingPolicyDesc(ImGuiTableFlags sizing_policy)
3825 sizing_policy &= ImGuiTableFlags_SizingMask_;
3826 if (sizing_policy == ImGuiTableFlags_SizingFixedFit) {
return "FixedFit"; }
3827 if (sizing_policy == ImGuiTableFlags_SizingFixedSame) {
return "FixedSame"; }
3828 if (sizing_policy == ImGuiTableFlags_SizingStretchProp) {
return "StretchProp"; }
3829 if (sizing_policy == ImGuiTableFlags_SizingStretchSame) {
return "StretchSame"; }
3833void ImGui::DebugNodeTable(ImGuiTable* table)
3836 const bool is_active = (table->LastFrameActive >=
g.FrameCount - 2);
3837 if (!is_active) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); }
3838 bool open =
TreeNode(table,
"Table 0x%08X (%d columns, in '%s')%s", table->ID, table->ColumnsCount, table->OuterWindow->Name, is_active ?
"" :
" *Inactive*");
3839 if (!is_active) { PopStyleColor(); }
3840 if (IsItemHovered())
3841 GetForegroundDrawList()->AddRect(table->OuterRect.Min, table->OuterRect.Max, IM_COL32(255, 255, 0, 255));
3842 if (IsItemVisible() && table->HoveredColumnBody != -1)
3843 GetForegroundDrawList()->AddRect(GetItemRectMin(), GetItemRectMax(), IM_COL32(255, 255, 0, 255));
3846 if (table->InstanceCurrent > 0)
3847 Text(
"** %d instances of same table! Some data below will refer to last instance.", table->InstanceCurrent + 1);
3848 if (
g.IO.ConfigDebugIsDebuggerPresent)
3850 if (DebugBreakButton(
"**DebugBreak**",
"in BeginTable()"))
3851 g.DebugBreakInTable = table->ID;
3855 bool clear_settings = SmallButton(
"Clear settings");
3856 BulletText(
"OuterRect: Pos: (%.1f,%.1f) Size: (%.1f,%.1f) Sizing: '%s'", table->OuterRect.Min.x, table->OuterRect.Min.y, table->OuterRect.GetWidth(), table->OuterRect.GetHeight(), DebugNodeTableGetSizingPolicyDesc(table->Flags));
3857 BulletText(
"ColumnsGivenWidth: %.1f, ColumnsAutoFitWidth: %.1f, InnerWidth: %.1f%s", table->ColumnsGivenWidth, table->ColumnsAutoFitWidth, table->InnerWidth, table->InnerWidth == 0.0f ?
" (auto)" :
"");
3858 BulletText(
"CellPaddingX: %.1f, CellSpacingX: %.1f/%.1f, OuterPaddingX: %.1f", table->CellPaddingX, table->CellSpacingX1, table->CellSpacingX2, table->OuterPaddingX);
3859 BulletText(
"HoveredColumnBody: %d, HoveredColumnBorder: %d", table->HoveredColumnBody, table->HoveredColumnBorder);
3860 BulletText(
"ResizedColumn: %d, ReorderColumn: %d, HeldHeaderColumn: %d", table->ResizedColumn, table->ReorderColumn, table->HeldHeaderColumn);
3861 for (
int n = 0; n < table->InstanceCurrent + 1; n++)
3863 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, n);
3864 BulletText(
"Instance %d: HoveredRow: %d, LastOuterHeight: %.2f", n, table_instance->HoveredRowLast, table_instance->LastOuterHeight);
3867 float sum_weights = 0.0f;
3868 for (
int n = 0; n < table->ColumnsCount; n++)
3869 if (table->Columns[n].Flags & ImGuiTableColumnFlags_WidthStretch)
3870 sum_weights += table->Columns[n].StretchWeight;
3871 for (
int n = 0; n < table->ColumnsCount; n++)
3873 ImGuiTableColumn* column = &table->Columns[n];
3874 const char* name = TableGetColumnName(table, n);
3877 "Column %d order %d '%s': offset %+.2f to %+.2f%s\n"
3878 "Enabled: %d, VisibleX/Y: %d/%d, RequestOutput: %d, SkipItems: %d, DrawChannels: %d,%d\n"
3879 "WidthGiven: %.1f, Request/Auto: %.1f/%.1f, StretchWeight: %.3f (%.1f%%)\n"
3880 "MinX: %.1f, MaxX: %.1f (%+.1f), ClipRect: %.1f to %.1f (+%.1f)\n"
3881 "ContentWidth: %.1f,%.1f, HeadersUsed/Ideal %.1f/%.1f\n"
3882 "Sort: %d%s, UserID: 0x%08X, Flags: 0x%04X: %s%s%s..",
3883 n, column->DisplayOrder, name, column->MinX - table->WorkRect.Min.x, column->MaxX - table->WorkRect.Min.x, (n < table->FreezeColumnsRequest) ?
" (Frozen)" :
"",
3884 column->IsEnabled, column->IsVisibleX, column->IsVisibleY, column->IsRequestOutput, column->IsSkipItems, column->DrawChannelFrozen, column->DrawChannelUnfrozen,
3885 column->WidthGiven, column->WidthRequest, column->WidthAuto, column->StretchWeight, column->StretchWeight > 0.0f ? (column->StretchWeight / sum_weights) * 100.0f : 0.0f,
3886 column->MinX, column->MaxX, column->MaxX - column->MinX, column->ClipRect.Min.x, column->ClipRect.Max.x, column->ClipRect.Max.x - column->ClipRect.Min.x,
3887 column->ContentMaxXFrozen - column->WorkMinX, column->ContentMaxXUnfrozen - column->WorkMinX, column->ContentMaxXHeadersUsed - column->WorkMinX, column->ContentMaxXHeadersIdeal - column->WorkMinX,
3888 column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ?
" (Asc)" : (column->SortDirection == ImGuiSortDirection_Descending) ?
" (Des)" :
"", column->UserID, column->Flags,
3889 (column->Flags & ImGuiTableColumnFlags_WidthStretch) ?
"WidthStretch " :
"",
3890 (column->Flags & ImGuiTableColumnFlags_WidthFixed) ?
"WidthFixed " :
"",
3891 (column->Flags & ImGuiTableColumnFlags_NoResize) ?
"NoResize " :
"");
3894 if (IsItemHovered())
3896 ImRect r(column->MinX, table->OuterRect.Min.y, column->MaxX, table->OuterRect.Max.y);
3897 GetForegroundDrawList()->AddRect(r.Min, r.Max, IM_COL32(255, 255, 0, 255));
3900 if (ImGuiTableSettings* settings = TableGetBoundSettings(table))
3901 DebugNodeTableSettings(settings);
3903 table->IsResetAllRequest =
true;
3907void ImGui::DebugNodeTableSettings(ImGuiTableSettings* settings)
3909 if (!
TreeNode((
void*)(intptr_t)settings->ID,
"Settings 0x%08X (%d columns)", settings->ID, settings->ColumnsCount))
3911 BulletText(
"SaveFlags: 0x%08X", settings->SaveFlags);
3912 BulletText(
"ColumnsCount: %d (max %d)", settings->ColumnsCount, settings->ColumnsCountMax);
3913 for (
int n = 0; n < settings->ColumnsCount; n++)
3915 ImGuiTableColumnSettings* column_settings = &settings->GetColumnSettings()[n];
3916 ImGuiSortDirection sort_dir = (column_settings->SortOrder != -1) ? (ImGuiSortDirection)column_settings->SortDirection : ImGuiSortDirection_None;
3917 BulletText(
"Column %d Order %d SortOrder %d %s Vis %d %s %7.3f UserID 0x%08X",
3918 n, column_settings->DisplayOrder, column_settings->SortOrder,
3919 (sort_dir == ImGuiSortDirection_Ascending) ?
"Asc" : (sort_dir == ImGuiSortDirection_Descending) ?
"Des" :
"---",
3920 column_settings->IsEnabled, column_settings->IsStretch ?
"Weight" :
"Width ", column_settings->WidthOrWeight, column_settings->UserID);
3927void ImGui::DebugNodeTable(ImGuiTable*) {}
3928void ImGui::DebugNodeTableSettings(ImGuiTableSettings*) {}
3961void ImGui::SetWindowClipRectBeforeSetChannel(ImGuiWindow* window,
const ImRect& clip_rect)
3963 ImVec4 clip_rect_vec4 = clip_rect.ToVec4();
3964 window->ClipRect = clip_rect;
3965 window->DrawList->_CmdHeader.ClipRect = clip_rect_vec4;
3966 window->DrawList->_ClipRectStack.Data[window->DrawList->_ClipRectStack.Size - 1] = clip_rect_vec4;
3969int ImGui::GetColumnIndex()
3971 ImGuiWindow* window = GetCurrentWindowRead();
3972 return window->DC.CurrentColumns ? window->DC.CurrentColumns->Current : 0;
3975int ImGui::GetColumnsCount()
3977 ImGuiWindow* window = GetCurrentWindowRead();
3978 return window->DC.CurrentColumns ? window->DC.CurrentColumns->Count : 1;
3981float ImGui::GetColumnOffsetFromNorm(
const ImGuiOldColumns* columns,
float offset_norm)
3983 return offset_norm * (columns->OffMaxX - columns->OffMinX);
3986float ImGui::GetColumnNormFromOffset(
const ImGuiOldColumns* columns,
float offset)
3988 return offset / (columns->OffMaxX - columns->OffMinX);
3991static const float COLUMNS_HIT_RECT_HALF_WIDTH = 4.0f;
3993static float GetDraggedColumnOffset(ImGuiOldColumns* columns,
int column_index)
3998 ImGuiWindow* window =
g.CurrentWindow;
3999 IM_ASSERT(column_index > 0);
4000 IM_ASSERT(
g.ActiveId == columns->ID + ImGuiID(column_index));
4002 float x =
g.IO.MousePos.x -
g.ActiveIdClickOffset.x + COLUMNS_HIT_RECT_HALF_WIDTH - window->Pos.x;
4003 x = ImMax(x, ImGui::GetColumnOffset(column_index - 1) +
g.Style.ColumnsMinSpacing);
4004 if ((columns->Flags & ImGuiOldColumnFlags_NoPreserveWidths))
4005 x = ImMin(x, ImGui::GetColumnOffset(column_index + 1) -
g.Style.ColumnsMinSpacing);
4010float ImGui::GetColumnOffset(
int column_index)
4012 ImGuiWindow* window = GetCurrentWindowRead();
4013 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4014 if (columns == NULL)
4017 if (column_index < 0)
4018 column_index = columns->Current;
4019 IM_ASSERT(column_index < columns->Columns.Size);
4021 const float t = columns->Columns[column_index].OffsetNorm;
4022 const float x_offset = ImLerp(columns->OffMinX, columns->OffMaxX,
t);
4026static float GetColumnWidthEx(ImGuiOldColumns* columns,
int column_index,
bool before_resize =
false)
4028 if (column_index < 0)
4029 column_index = columns->Current;
4033 offset_norm = columns->Columns[column_index + 1].OffsetNormBeforeResize - columns->Columns[column_index].OffsetNormBeforeResize;
4035 offset_norm = columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm;
4036 return ImGui::GetColumnOffsetFromNorm(columns, offset_norm);
4039float ImGui::GetColumnWidth(
int column_index)
4042 ImGuiWindow* window =
g.CurrentWindow;
4043 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4044 if (columns == NULL)
4045 return GetContentRegionAvail().x;
4047 if (column_index < 0)
4048 column_index = columns->Current;
4049 return GetColumnOffsetFromNorm(columns, columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm);
4052void ImGui::SetColumnOffset(
int column_index,
float offset)
4055 ImGuiWindow* window =
g.CurrentWindow;
4056 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4057 IM_ASSERT(columns != NULL);
4059 if (column_index < 0)
4060 column_index = columns->Current;
4061 IM_ASSERT(column_index < columns->Columns.Size);
4063 const bool preserve_width = !(columns->Flags & ImGuiOldColumnFlags_NoPreserveWidths) && (column_index < columns->Count - 1);
4064 const float width = preserve_width ? GetColumnWidthEx(columns, column_index, columns->IsBeingResized) : 0.0f;
4066 if (!(columns->Flags & ImGuiOldColumnFlags_NoForceWithinWindow))
4067 offset = ImMin(offset, columns->OffMaxX -
g.Style.ColumnsMinSpacing * (columns->Count - column_index));
4068 columns->Columns[column_index].OffsetNorm = GetColumnNormFromOffset(columns, offset - columns->OffMinX);
4071 SetColumnOffset(column_index + 1, offset + ImMax(
g.Style.ColumnsMinSpacing, width));
4074void ImGui::SetColumnWidth(
int column_index,
float width)
4076 ImGuiWindow* window = GetCurrentWindowRead();
4077 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4078 IM_ASSERT(columns != NULL);
4080 if (column_index < 0)
4081 column_index = columns->Current;
4082 SetColumnOffset(column_index + 1, GetColumnOffset(column_index) + width);
4085void ImGui::PushColumnClipRect(
int column_index)
4087 ImGuiWindow* window = GetCurrentWindowRead();
4088 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4089 if (column_index < 0)
4090 column_index = columns->Current;
4092 ImGuiOldColumnData* column = &columns->Columns[column_index];
4093 PushClipRect(column->ClipRect.Min, column->ClipRect.Max,
false);
4097void ImGui::PushColumnsBackground()
4099 ImGuiWindow* window = GetCurrentWindowRead();
4100 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4101 if (columns->Count == 1)
4105 columns->HostBackupClipRect = window->ClipRect;
4106 SetWindowClipRectBeforeSetChannel(window, columns->HostInitialClipRect);
4107 columns->Splitter.SetCurrentChannel(window->DrawList, 0);
4110void ImGui::PopColumnsBackground()
4112 ImGuiWindow* window = GetCurrentWindowRead();
4113 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4114 if (columns->Count == 1)
4118 SetWindowClipRectBeforeSetChannel(window, columns->HostBackupClipRect);
4119 columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1);
4122ImGuiOldColumns* ImGui::FindOrCreateColumns(ImGuiWindow* window, ImGuiID
id)
4125 for (
int n = 0; n < window->ColumnsStorage.Size; n++)
4126 if (window->ColumnsStorage[n].ID ==
id)
4127 return &window->ColumnsStorage[n];
4129 window->ColumnsStorage.push_back(ImGuiOldColumns());
4130 ImGuiOldColumns* columns = &window->ColumnsStorage.back();
4135ImGuiID ImGui::GetColumnsID(
const char* str_id,
int columns_count)
4137 ImGuiWindow* window = GetCurrentWindow();
4141 PushID(0x11223347 + (str_id ? 0 : columns_count));
4142 ImGuiID
id = window->GetID(str_id ? str_id :
"columns");
4148void ImGui::BeginColumns(
const char* str_id,
int columns_count, ImGuiOldColumnFlags flags)
4151 ImGuiWindow* window = GetCurrentWindow();
4153 IM_ASSERT(columns_count >= 1);
4154 IM_ASSERT(window->DC.CurrentColumns == NULL);
4157 ImGuiID
id = GetColumnsID(str_id, columns_count);
4158 ImGuiOldColumns* columns = FindOrCreateColumns(window,
id);
4159 IM_ASSERT(columns->ID ==
id);
4160 columns->Current = 0;
4161 columns->Count = columns_count;
4162 columns->Flags = flags;
4163 window->DC.CurrentColumns = columns;
4164 window->DC.NavIsScrollPushableX =
false;
4166 columns->HostCursorPosY = window->DC.CursorPos.y;
4167 columns->HostCursorMaxPosX = window->DC.CursorMaxPos.x;
4168 columns->HostInitialClipRect = window->ClipRect;
4169 columns->HostBackupParentWorkRect = window->ParentWorkRect;
4170 window->ParentWorkRect = window->WorkRect;
4174 const float column_padding =
g.Style.ItemSpacing.x;
4175 const float half_clip_extend_x = ImTrunc(ImMax(window->WindowPadding.x * 0.5f, window->WindowBorderSize));
4176 const float max_1 = window->WorkRect.Max.x + column_padding - ImMax(column_padding - window->WindowPadding.x, 0.0f);
4177 const float max_2 = window->WorkRect.Max.x + half_clip_extend_x;
4178 columns->OffMinX = window->DC.Indent.x - column_padding + ImMax(column_padding - window->WindowPadding.x, 0.0f);
4179 columns->OffMaxX = ImMax(ImMin(max_1, max_2) - window->Pos.x, columns->OffMinX + 1.0f);
4180 columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y;
4183 if (columns->Columns.Size != 0 && columns->Columns.Size != columns_count + 1)
4184 columns->Columns.resize(0);
4187 columns->IsFirstFrame = (columns->Columns.Size == 0);
4188 if (columns->Columns.Size == 0)
4190 columns->Columns.reserve(columns_count + 1);
4191 for (
int n = 0; n < columns_count + 1; n++)
4193 ImGuiOldColumnData column;
4194 column.OffsetNorm = n / (float)columns_count;
4195 columns->Columns.push_back(column);
4199 for (
int n = 0; n < columns_count; n++)
4202 ImGuiOldColumnData* column = &columns->Columns[n];
4203 float clip_x1 = IM_ROUND(window->Pos.x + GetColumnOffset(n));
4204 float clip_x2 = IM_ROUND(window->Pos.x + GetColumnOffset(n + 1) - 1.0f);
4205 column->ClipRect = ImRect(clip_x1, -FLT_MAX, clip_x2, +FLT_MAX);
4206 column->ClipRect.ClipWithFull(window->ClipRect);
4209 if (columns->Count > 1)
4211 columns->Splitter.Split(window->DrawList, 1 + columns->Count);
4212 columns->Splitter.SetCurrentChannel(window->DrawList, 1);
4213 PushColumnClipRect(0);
4217 float offset_0 = GetColumnOffset(columns->Current);
4218 float offset_1 = GetColumnOffset(columns->Current + 1);
4219 float width = offset_1 - offset_0;
4220 PushItemWidth(width * 0.65f);
4221 window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
4222 window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
4223 window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding;
4224 window->WorkRect.Max.y = window->ContentRegionRect.Max.y;
4227void ImGui::NextColumn()
4229 ImGuiWindow* window = GetCurrentWindow();
4230 if (window->SkipItems || window->DC.CurrentColumns == NULL)
4234 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4236 if (columns->Count == 1)
4238 window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
4239 IM_ASSERT(columns->Current == 0);
4244 if (++columns->Current == columns->Count)
4245 columns->Current = 0;
4251 ImGuiOldColumnData* column = &columns->Columns[columns->Current];
4252 SetWindowClipRectBeforeSetChannel(window, column->ClipRect);
4253 columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1);
4255 const float column_padding =
g.Style.ItemSpacing.x;
4256 columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y);
4257 if (columns->Current > 0)
4261 window->DC.ColumnsOffset.x = GetColumnOffset(columns->Current) - window->DC.Indent.x + column_padding;
4266 window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
4267 window->DC.IsSameLine =
false;
4268 columns->LineMinY = columns->LineMaxY;
4270 window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
4271 window->DC.CursorPos.y = columns->LineMinY;
4272 window->DC.CurrLineSize = ImVec2(0.0f, 0.0f);
4273 window->DC.CurrLineTextBaseOffset = 0.0f;
4276 float offset_0 = GetColumnOffset(columns->Current);
4277 float offset_1 = GetColumnOffset(columns->Current + 1);
4278 float width = offset_1 - offset_0;
4279 PushItemWidth(width * 0.65f);
4280 window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding;
4283void ImGui::EndColumns()
4286 ImGuiWindow* window = GetCurrentWindow();
4287 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4288 IM_ASSERT(columns != NULL);
4291 if (columns->Count > 1)
4294 columns->Splitter.Merge(window->DrawList);
4297 const ImGuiOldColumnFlags flags = columns->Flags;
4298 columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y);
4299 window->DC.CursorPos.y = columns->LineMaxY;
4300 if (!(flags & ImGuiOldColumnFlags_GrowParentContentsSize))
4301 window->DC.CursorMaxPos.x = columns->HostCursorMaxPosX;
4305 bool is_being_resized =
false;
4306 if (!(flags & ImGuiOldColumnFlags_NoBorder) && !window->SkipItems)
4309 const float y1 = ImMax(columns->HostCursorPosY, window->ClipRect.Min.y);
4310 const float y2 = ImMin(window->DC.CursorPos.y, window->ClipRect.Max.y);
4311 int dragging_column = -1;
4312 for (
int n = 1; n < columns->Count; n++)
4314 ImGuiOldColumnData* column = &columns->Columns[n];
4315 float x = window->Pos.x + GetColumnOffset(n);
4316 const ImGuiID column_id = columns->ID + ImGuiID(n);
4317 const float column_hit_hw = COLUMNS_HIT_RECT_HALF_WIDTH;
4318 const ImRect column_hit_rect(ImVec2(x - column_hit_hw, y1), ImVec2(x + column_hit_hw, y2));
4319 if (!ItemAdd(column_hit_rect, column_id, NULL, ImGuiItemFlags_NoNav))
4322 bool hovered =
false, held =
false;
4323 if (!(flags & ImGuiOldColumnFlags_NoResize))
4325 ButtonBehavior(column_hit_rect, column_id, &hovered, &held);
4326 if (hovered || held)
4327 g.MouseCursor = ImGuiMouseCursor_ResizeEW;
4328 if (held && !(column->Flags & ImGuiOldColumnFlags_NoResize))
4329 dragging_column = n;
4333 const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator);
4334 const float xi = IM_TRUNC(x);
4335 window->DrawList->AddLine(ImVec2(xi, y1 + 1.0f), ImVec2(xi, y2), col);
4339 if (dragging_column != -1)
4341 if (!columns->IsBeingResized)
4342 for (
int n = 0; n < columns->Count + 1; n++)
4343 columns->Columns[n].OffsetNormBeforeResize = columns->Columns[n].OffsetNorm;
4344 columns->IsBeingResized = is_being_resized =
true;
4345 float x = GetDraggedColumnOffset(columns, dragging_column);
4346 SetColumnOffset(dragging_column, x);
4349 columns->IsBeingResized = is_being_resized;
4351 window->WorkRect = window->ParentWorkRect;
4352 window->ParentWorkRect = columns->HostBackupParentWorkRect;
4353 window->DC.CurrentColumns = NULL;
4354 window->DC.ColumnsOffset.x = 0.0f;
4355 window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
4356 NavUpdateCurrentWindowIsScrollPushableX();
4359void ImGui::Columns(
int columns_count,
const char*
id,
bool border)
4361 ImGuiWindow* window = GetCurrentWindow();
4362 IM_ASSERT(columns_count >= 1);
4364 ImGuiOldColumnFlags flags = (border ? 0 : ImGuiOldColumnFlags_NoBorder);
4366 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4367 if (columns != NULL && columns->Count == columns_count && columns->Flags == flags)
4370 if (columns != NULL)
4373 if (columns_count != 1)
4374 BeginColumns(
id, columns_count, flags);
int ImFormatString(char *buf, size_t buf_size, const char *fmt,...)
const char * ImStrSkipBlank(const char *str)
ImGuiID ImHashStr(const char *data_p, size_t data_size, ImGuiID seed)
IM_STATIC_ASSERT(ImGuiSortDirection_None==0 &&ImGuiSortDirection_Ascending==1 &&ImGuiSortDirection_Descending==2)
ImGuiTableFlags TableFixFlags(ImGuiTableFlags flags, ImGuiWindow *outer_window)
auto CalcTextSize(std::string_view str)
ALWAYS_INLINE unsigned count(const uint8_t *pIn, const uint8_t *pMatch, const uint8_t *pInLimit)
bool TreeNode(const char *label, ImGuiTreeNodeFlags flags, std::invocable<> auto next)