190#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
191#define _CRT_SECURE_NO_WARNINGS
194#ifndef IMGUI_DEFINE_MATH_OPERATORS
195#define IMGUI_DEFINE_MATH_OPERATORS
200#include "imgui_internal.h"
207#pragma warning (disable: 4127)
208#pragma warning (disable: 4996)
209#if defined(_MSC_VER) && _MSC_VER >= 1922
210#pragma warning (disable: 5054)
212#pragma warning (disable: 26451)
213#pragma warning (disable: 26812)
217#if defined(__clang__)
218#if __has_warning("-Wunknown-warning-option")
219#pragma clang diagnostic ignored "-Wunknown-warning-option"
221#pragma clang diagnostic ignored "-Wunknown-pragmas"
222#pragma clang diagnostic ignored "-Wold-style-cast"
223#pragma clang diagnostic ignored "-Wfloat-equal"
224#pragma clang diagnostic ignored "-Wformat-nonliteral"
225#pragma clang diagnostic ignored "-Wsign-conversion"
226#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
227#pragma clang diagnostic ignored "-Wdouble-promotion"
228#pragma clang diagnostic ignored "-Wenum-enum-conversion"
229#pragma clang diagnostic ignored "-Wdeprecated-enum-enum-conversion"
230#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
231#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
232#pragma clang diagnostic ignored "-Wnontrivial-memaccess"
233#elif defined(__GNUC__)
234#pragma GCC diagnostic ignored "-Wpragmas"
235#pragma GCC diagnostic ignored "-Wfloat-equal"
236#pragma GCC diagnostic ignored "-Wformat-nonliteral"
237#pragma GCC diagnostic ignored "-Wdouble-promotion"
238#pragma GCC diagnostic ignored "-Wformat"
239#pragma GCC diagnostic ignored "-Wstrict-overflow"
240#pragma GCC diagnostic ignored "-Wclass-memaccess"
261static const int TABLE_DRAW_CHANNEL_BG0 = 0;
262static const int TABLE_DRAW_CHANNEL_BG2_FROZEN = 1;
263static const int TABLE_DRAW_CHANNEL_NOCLIP = 2;
264static const float TABLE_BORDER_SIZE = 1.0f;
265static const float TABLE_RESIZE_SEPARATOR_HALF_THICKNESS = 4.0f;
266static const float TABLE_RESIZE_SEPARATOR_FEEDBACK_TIMER = 0.06f;
269inline ImGuiTableFlags
TableFixFlags(ImGuiTableFlags flags, ImGuiWindow* outer_window)
272 if ((flags & ImGuiTableFlags_SizingMask_) == 0)
273 flags |= ((flags & ImGuiTableFlags_ScrollX) || (outer_window->Flags & ImGuiWindowFlags_AlwaysAutoResize)) ? ImGuiTableFlags_SizingFixedFit : ImGuiTableFlags_SizingStretchSame;
276 if ((flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedSame)
277 flags |= ImGuiTableFlags_NoKeepColumnsVisible;
280 if (flags & ImGuiTableFlags_Resizable)
281 flags |= ImGuiTableFlags_BordersInnerV;
284 if (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY))
285 flags &= ~(ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_NoHostExtendY);
288 if (flags & ImGuiTableFlags_NoBordersInBodyUntilResize)
289 flags &= ~ImGuiTableFlags_NoBordersInBody;
292 if ((flags & (ImGuiTableFlags_Resizable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Sortable)) == 0)
293 flags |= ImGuiTableFlags_NoSavedSettings;
296 if (outer_window->RootWindow->Flags & ImGuiWindowFlags_NoSavedSettings)
297 flags |= ImGuiTableFlags_NoSavedSettings;
302ImGuiTable* ImGui::TableFindByID(ImGuiID
id)
305 return g.Tables.GetByKey(
id);
309bool ImGui::BeginTable(
const char* str_id,
int columns_count, ImGuiTableFlags flags,
const ImVec2& outer_size,
float inner_width)
311 ImGuiID
id = GetID(str_id);
312 return BeginTableEx(str_id,
id, columns_count, flags, outer_size, inner_width);
315bool ImGui::BeginTableEx(
const char* name, ImGuiID
id,
int columns_count, ImGuiTableFlags flags,
const ImVec2& outer_size,
float inner_width)
318 ImGuiWindow* outer_window = GetCurrentWindow();
319 if (outer_window->SkipItems)
323 IM_ASSERT(columns_count > 0 && columns_count < IMGUI_TABLE_MAX_COLUMNS);
324 if (flags & ImGuiTableFlags_ScrollX)
325 IM_ASSERT(inner_width >= 0.0f);
334 const bool use_child_window = (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) != 0;
335 const ImVec2 avail_size = GetContentRegionAvail();
336 const ImVec2 actual_outer_size = ImTrunc(CalcItemSize(outer_size, ImMax(avail_size.x, 1.0f), use_child_window ? ImMax(avail_size.y, 1.0f) : 0.0f));
337 const ImRect outer_rect(outer_window->DC.CursorPos, outer_window->DC.CursorPos + actual_outer_size);
338 const bool outer_window_is_measuring_size = (outer_window->AutoFitFramesX > 0) || (outer_window->AutoFitFramesY > 0);
339 if (use_child_window && IsClippedEx(outer_rect, 0) && !outer_window_is_measuring_size)
341 ItemSize(outer_rect);
342 ItemAdd(outer_rect,
id);
347 if (
g.DebugBreakInTable ==
id)
351 ImGuiTable* table =
g.Tables.GetOrAddByKey(
id);
354 const int table_idx =
g.Tables.GetIndex(table);
355 if (++
g.TablesTempDataStacked >
g.TablesTempData.Size)
356 g.TablesTempData.resize(
g.TablesTempDataStacked, ImGuiTableTempData());
357 ImGuiTableTempData* temp_data = table->TempData = &
g.TablesTempData[
g.TablesTempDataStacked - 1];
358 temp_data->TableIndex = table_idx;
359 table->DrawSplitter = &table->TempData->DrawSplitter;
360 table->DrawSplitter->Clear();
363 table->IsDefaultSizingPolicy = (flags & ImGuiTableFlags_SizingMask_) == 0;
367 const int previous_frame_active = table->LastFrameActive;
368 const int instance_no = (previous_frame_active !=
g.FrameCount) ? 0 : table->InstanceCurrent + 1;
369 const ImGuiTableFlags previous_flags = table->Flags;
371 table->Flags = flags;
372 table->LastFrameActive =
g.FrameCount;
373 table->OuterWindow = table->InnerWindow = outer_window;
374 table->ColumnsCount = columns_count;
375 table->IsLayoutLocked =
false;
376 table->InnerWidth = inner_width;
377 temp_data->UserOuterSize = outer_size;
381 table->InstanceCurrent = (ImS16)instance_no;
384 IM_ASSERT(table->ColumnsCount == columns_count &&
"BeginTable(): Cannot change columns count mid-frame while preserving same ID");
385 if (table->InstanceDataExtra.Size < instance_no)
386 table->InstanceDataExtra.push_back(ImGuiTableInstanceData());
387 instance_id = GetIDWithSeed(instance_no, GetIDWithSeed(
"##Instances", NULL,
id));
393 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
394 table_instance->TableInstanceID = instance_id;
397 if (use_child_window)
401 ImVec2 override_content_size(FLT_MAX, FLT_MAX);
402 if ((flags & ImGuiTableFlags_ScrollX) && !(flags & ImGuiTableFlags_ScrollY))
403 override_content_size.y = FLT_MIN;
409 if ((flags & ImGuiTableFlags_ScrollX) && inner_width > 0.0f)
410 override_content_size.x = inner_width;
412 if (override_content_size.x != FLT_MAX || override_content_size.y != FLT_MAX)
413 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));
416 if ((previous_flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) == 0)
417 if ((
g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasScroll) == 0)
418 SetNextWindowScroll(ImVec2(0.0f, 0.0f));
421 ImGuiWindowFlags child_window_flags = (flags & ImGuiTableFlags_ScrollX) ? ImGuiWindowFlags_HorizontalScrollbar : ImGuiWindowFlags_None;
422 BeginChildEx(name, instance_id, outer_rect.GetSize(), ImGuiChildFlags_None, child_window_flags);
423 table->InnerWindow =
g.CurrentWindow;
424 table->WorkRect = table->InnerWindow->WorkRect;
425 table->OuterRect = table->InnerWindow->Rect();
426 table->InnerRect = table->InnerWindow->InnerRect;
427 IM_ASSERT(table->InnerWindow->WindowPadding.x == 0.0f && table->InnerWindow->WindowPadding.y == 0.0f && table->InnerWindow->WindowBorderSize == 0.0f);
430 if (table->InnerWindow->SkipItems && outer_window_is_measuring_size)
431 table->InnerWindow->SkipItems =
false;
434 if (instance_no == 0)
436 table->HasScrollbarYPrev = table->HasScrollbarYCurr;
437 table->HasScrollbarYCurr =
false;
439 table->HasScrollbarYCurr |= table->InnerWindow->ScrollbarY;
445 table->WorkRect = table->OuterRect = table->InnerRect = outer_rect;
446 table->HasScrollbarYPrev = table->HasScrollbarYCurr =
false;
452 PushOverrideID(instance_id);
455 ImGuiWindow* inner_window = table->InnerWindow;
456 table->HostIndentX = inner_window->DC.Indent.x;
457 table->HostClipRect = inner_window->ClipRect;
458 table->HostSkipItems = inner_window->SkipItems;
459 temp_data->HostBackupWorkRect = inner_window->WorkRect;
460 temp_data->HostBackupParentWorkRect = inner_window->ParentWorkRect;
461 temp_data->HostBackupColumnsOffset = outer_window->DC.ColumnsOffset;
462 temp_data->HostBackupPrevLineSize = inner_window->DC.PrevLineSize;
463 temp_data->HostBackupCurrLineSize = inner_window->DC.CurrLineSize;
464 temp_data->HostBackupCursorMaxPos = inner_window->DC.CursorMaxPos;
465 temp_data->HostBackupItemWidth = outer_window->DC.ItemWidth;
466 temp_data->HostBackupItemWidthStackSize = outer_window->DC.ItemWidthStack.Size;
467 inner_window->DC.PrevLineSize = inner_window->DC.CurrLineSize = ImVec2(0.0f, 0.0f);
473 if (inner_window != outer_window)
478 if (flags & ImGuiTableFlags_BordersOuterV)
480 table->HostClipRect.Min.x = ImMin(table->HostClipRect.Min.x + TABLE_BORDER_SIZE, table->HostClipRect.Max.x);
481 if (inner_window->DecoOuterSizeX2 == 0.0f)
482 table->HostClipRect.Max.x = ImMax(table->HostClipRect.Max.x - TABLE_BORDER_SIZE, table->HostClipRect.Min.x);
484 if (flags & ImGuiTableFlags_BordersOuterH)
486 table->HostClipRect.Min.y = ImMin(table->HostClipRect.Min.y + TABLE_BORDER_SIZE, table->HostClipRect.Max.y);
487 if (inner_window->DecoOuterSizeY2 == 0.0f)
488 table->HostClipRect.Max.y = ImMax(table->HostClipRect.Max.y - TABLE_BORDER_SIZE, table->HostClipRect.Min.y);
497 const bool pad_outer_x = (flags & ImGuiTableFlags_NoPadOuterX) ?
false : (flags & ImGuiTableFlags_PadOuterX) ? true : (flags & ImGuiTableFlags_BordersOuterV) != 0;
498 const bool pad_inner_x = (flags & ImGuiTableFlags_NoPadInnerX) ?
false : true;
499 const float inner_spacing_for_border = (flags & ImGuiTableFlags_BordersInnerV) ? TABLE_BORDER_SIZE : 0.0f;
500 const float inner_spacing_explicit = (pad_inner_x && (flags & ImGuiTableFlags_BordersInnerV) == 0) ?
g.Style.CellPadding.x : 0.0f;
501 const float inner_padding_explicit = (pad_inner_x && (flags & ImGuiTableFlags_BordersInnerV) != 0) ?
g.Style.CellPadding.x : 0.0f;
502 table->CellSpacingX1 = inner_spacing_explicit + inner_spacing_for_border;
503 table->CellSpacingX2 = inner_spacing_explicit;
504 table->CellPaddingX = inner_padding_explicit;
506 const float outer_padding_for_border = (flags & ImGuiTableFlags_BordersOuterV) ? TABLE_BORDER_SIZE : 0.0f;
507 const float outer_padding_explicit = pad_outer_x ?
g.Style.CellPadding.x : 0.0f;
508 table->OuterPaddingX = (outer_padding_for_border + outer_padding_explicit) - table->CellPaddingX;
510 table->CurrentColumn = -1;
511 table->CurrentRow = -1;
512 table->RowBgColorCounter = 0;
513 table->LastRowFlags = ImGuiTableRowFlags_None;
514 table->InnerClipRect = (inner_window == outer_window) ? table->WorkRect : inner_window->ClipRect;
515 table->InnerClipRect.ClipWith(table->WorkRect);
516 table->InnerClipRect.ClipWithFull(table->HostClipRect);
517 table->InnerClipRect.Max.y = (flags & ImGuiTableFlags_NoHostExtendY) ? ImMin(table->InnerClipRect.Max.y, inner_window->WorkRect.Max.y) : table->HostClipRect.Max.y;
519 table->RowPosY1 = table->RowPosY2 = table->WorkRect.Min.y;
520 table->RowTextBaseline = 0.0f;
521 table->RowCellPaddingY = 0.0f;
522 table->FreezeRowsRequest = table->FreezeRowsCount = 0;
523 table->FreezeColumnsRequest = table->FreezeColumnsCount = 0;
524 table->IsUnfrozenRows =
true;
525 table->DeclColumnsCount = table->AngledHeadersCount = 0;
526 if (previous_frame_active + 1 <
g.FrameCount)
527 table->IsActiveIdInTable =
false;
528 table->AngledHeadersHeight = 0.0f;
529 temp_data->AngledHeadersExtraWidth = 0.0f;
532 table->BorderColorStrong = GetColorU32(ImGuiCol_TableBorderStrong);
533 table->BorderColorLight = GetColorU32(ImGuiCol_TableBorderLight);
536 g.CurrentTable = table;
537 outer_window->DC.NavIsScrollPushableX =
false;
538 outer_window->DC.CurrentTableIdx = table_idx;
539 if (inner_window != outer_window)
540 inner_window->DC.CurrentTableIdx = table_idx;
542 if ((previous_flags & ImGuiTableFlags_Reorderable) && (flags & ImGuiTableFlags_Reorderable) == 0)
543 table->IsResetDisplayOrderRequest =
true;
546 if (table_idx >=
g.TablesLastTimeActive.Size)
547 g.TablesLastTimeActive.resize(table_idx + 1, -1.0f);
548 g.TablesLastTimeActive[table_idx] = (float)
g.Time;
549 temp_data->LastTimeActive = (float)
g.Time;
550 table->MemoryCompacted =
false;
553 ImGuiTableColumn* old_columns_to_preserve = NULL;
554 void* old_columns_raw_data = NULL;
555 const int old_columns_count = table->Columns.size();
556 if (old_columns_count != 0 && old_columns_count != columns_count)
559 old_columns_to_preserve = table->Columns.Data;
560 old_columns_raw_data = table->RawData;
561 table->RawData = NULL;
563 if (table->RawData == NULL)
565 TableBeginInitMemory(table, columns_count);
566 table->IsInitializing = table->IsSettingsRequestLoad =
true;
568 if (table->IsResetAllRequest)
569 TableResetSettings(table);
570 if (table->IsInitializing)
573 table->SettingsOffset = -1;
574 table->IsSortSpecsDirty =
true;
575 table->InstanceInteracted = -1;
576 table->ContextPopupColumn = -1;
577 table->ReorderColumn = table->ResizedColumn = table->LastResizedColumn = -1;
578 table->AutoFitSingleColumn = -1;
579 table->HoveredColumnBody = table->HoveredColumnBorder = -1;
580 for (
int n = 0; n < columns_count; n++)
582 ImGuiTableColumn* column = &table->Columns[n];
583 if (old_columns_to_preserve && n < old_columns_count)
586 *column = old_columns_to_preserve[n];
590 float width_auto = column->WidthAuto;
591 *column = ImGuiTableColumn();
592 column->WidthAuto = width_auto;
593 column->IsPreserveWidthAuto =
true;
594 column->IsEnabled = column->IsUserEnabled = column->IsUserEnabledNextFrame =
true;
596 column->DisplayOrder = table->DisplayOrderToIndex[n] = (ImGuiTableColumnIdx)n;
599 if (old_columns_raw_data)
600 IM_FREE(old_columns_raw_data);
603 if (table->IsSettingsRequestLoad)
604 TableLoadSettings(table);
611 const float new_ref_scale_unit =
g.FontSize;
612 if (table->RefScale != 0.0f && table->RefScale != new_ref_scale_unit)
614 const float scale_factor = new_ref_scale_unit / table->RefScale;
616 for (
int n = 0; n < columns_count; n++)
617 table->Columns[n].WidthRequest = table->Columns[n].WidthRequest * scale_factor;
619 table->RefScale = new_ref_scale_unit;
624 inner_window->SkipItems =
true;
628 if (table->ColumnsNames.Buf.Size > 0)
629 table->ColumnsNames.Buf.resize(0);
632 TableBeginApplyRequests(table);
646void ImGui::TableBeginInitMemory(ImGuiTable* table,
int columns_count)
649 const int columns_bit_array_size = (int)ImBitArrayGetStorageSizeInBytes(columns_count);
650 ImSpanAllocator<6> span_allocator;
651 span_allocator.Reserve(0, columns_count *
sizeof(ImGuiTableColumn));
652 span_allocator.Reserve(1, columns_count *
sizeof(ImGuiTableColumnIdx));
653 span_allocator.Reserve(2, columns_count *
sizeof(ImGuiTableCellData), 4);
654 for (
int n = 3; n < 6; n++)
655 span_allocator.Reserve(n, columns_bit_array_size);
656 table->RawData = IM_ALLOC(span_allocator.GetArenaSizeInBytes());
657 memset(table->RawData, 0, span_allocator.GetArenaSizeInBytes());
658 span_allocator.SetArenaBasePtr(table->RawData);
659 span_allocator.GetSpan(0, &table->Columns);
660 span_allocator.GetSpan(1, &table->DisplayOrderToIndex);
661 span_allocator.GetSpan(2, &table->RowCellData);
662 table->EnabledMaskByDisplayOrder = (ImU32*)span_allocator.GetSpanPtrBegin(3);
663 table->EnabledMaskByIndex = (ImU32*)span_allocator.GetSpanPtrBegin(4);
664 table->VisibleMaskByIndex = (ImU32*)span_allocator.GetSpanPtrBegin(5);
668void ImGui::TableBeginApplyRequests(ImGuiTable* table)
673 if (table->InstanceCurrent == 0)
675 if (table->ResizedColumn != -1 && table->ResizedColumnNextWidth != FLT_MAX)
676 TableSetColumnWidth(table->ResizedColumn, table->ResizedColumnNextWidth);
677 table->LastResizedColumn = table->ResizedColumn;
678 table->ResizedColumnNextWidth = FLT_MAX;
679 table->ResizedColumn = -1;
683 if (table->AutoFitSingleColumn != -1)
685 TableSetColumnWidth(table->AutoFitSingleColumn, table->Columns[table->AutoFitSingleColumn].WidthAuto);
686 table->AutoFitSingleColumn = -1;
692 if (table->InstanceCurrent == 0)
694 if (table->HeldHeaderColumn == -1 && table->ReorderColumn != -1)
695 table->ReorderColumn = -1;
696 table->HeldHeaderColumn = -1;
697 if (table->ReorderColumn != -1 && table->ReorderColumnDir != 0)
703 const int reorder_dir = table->ReorderColumnDir;
704 IM_ASSERT(reorder_dir == -1 || reorder_dir == +1);
705 IM_ASSERT(table->Flags & ImGuiTableFlags_Reorderable);
706 ImGuiTableColumn* src_column = &table->Columns[table->ReorderColumn];
707 ImGuiTableColumn* dst_column = &table->Columns[(reorder_dir == -1) ? src_column->PrevEnabledColumn : src_column->NextEnabledColumn];
708 IM_UNUSED(dst_column);
709 const int src_order = src_column->DisplayOrder;
710 const int dst_order = dst_column->DisplayOrder;
711 src_column->DisplayOrder = (ImGuiTableColumnIdx)dst_order;
712 for (
int order_n = src_order + reorder_dir; order_n != dst_order + reorder_dir; order_n += reorder_dir)
713 table->Columns[table->DisplayOrderToIndex[order_n]].DisplayOrder -= (ImGuiTableColumnIdx)reorder_dir;
714 IM_ASSERT(dst_column->DisplayOrder == dst_order - reorder_dir);
717 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
718 table->DisplayOrderToIndex[table->Columns[column_n].DisplayOrder] = (ImGuiTableColumnIdx)column_n;
719 table->ReorderColumnDir = 0;
720 table->IsSettingsDirty =
true;
725 if (table->IsResetDisplayOrderRequest)
727 for (
int n = 0; n < table->ColumnsCount; n++)
728 table->DisplayOrderToIndex[n] = table->Columns[n].DisplayOrder = (ImGuiTableColumnIdx)n;
729 table->IsResetDisplayOrderRequest =
false;
730 table->IsSettingsDirty =
true;
735static void TableSetupColumnFlags(ImGuiTable* table, ImGuiTableColumn* column, ImGuiTableColumnFlags flags_in)
737 ImGuiTableColumnFlags flags = flags_in;
740 if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0)
742 const ImGuiTableFlags table_sizing_policy = (table->Flags & ImGuiTableFlags_SizingMask_);
743 if (table_sizing_policy == ImGuiTableFlags_SizingFixedFit || table_sizing_policy == ImGuiTableFlags_SizingFixedSame)
744 flags |= ImGuiTableColumnFlags_WidthFixed;
746 flags |= ImGuiTableColumnFlags_WidthStretch;
750 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiTableColumnFlags_WidthMask_));
754 if ((table->Flags & ImGuiTableFlags_Resizable) == 0)
755 flags |= ImGuiTableColumnFlags_NoResize;
758 if ((flags & ImGuiTableColumnFlags_NoSortAscending) && (flags & ImGuiTableColumnFlags_NoSortDescending))
759 flags |= ImGuiTableColumnFlags_NoSort;
762 if ((flags & ImGuiTableColumnFlags_IndentMask_) == 0)
763 flags |= (table->Columns.index_from_ptr(column) == 0) ? ImGuiTableColumnFlags_IndentEnable : ImGuiTableColumnFlags_IndentDisable;
771 column->Flags = flags | (column->Flags & ImGuiTableColumnFlags_StatusMask_);
774 column->SortDirectionsAvailCount = column->SortDirectionsAvailMask = column->SortDirectionsAvailList = 0;
775 if (table->Flags & ImGuiTableFlags_Sortable)
777 int count = 0, mask = 0, list = 0;
778 if ((flags & ImGuiTableColumnFlags_PreferSortAscending) != 0 && (flags & ImGuiTableColumnFlags_NoSortAscending) == 0) { mask |= 1 << ImGuiSortDirection_Ascending; list |= ImGuiSortDirection_Ascending << (
count << 1);
count++; }
779 if ((flags & ImGuiTableColumnFlags_PreferSortDescending) != 0 && (flags & ImGuiTableColumnFlags_NoSortDescending) == 0) { mask |= 1 << ImGuiSortDirection_Descending; list |= ImGuiSortDirection_Descending << (
count << 1);
count++; }
780 if ((flags & ImGuiTableColumnFlags_PreferSortAscending) == 0 && (flags & ImGuiTableColumnFlags_NoSortAscending) == 0) { mask |= 1 << ImGuiSortDirection_Ascending; list |= ImGuiSortDirection_Ascending << (
count << 1);
count++; }
781 if ((flags & ImGuiTableColumnFlags_PreferSortDescending) == 0 && (flags & ImGuiTableColumnFlags_NoSortDescending) == 0) { mask |= 1 << ImGuiSortDirection_Descending; list |= ImGuiSortDirection_Descending << (
count << 1);
count++; }
782 if ((table->Flags & ImGuiTableFlags_SortTristate) ||
count == 0) { mask |= 1 << ImGuiSortDirection_None;
count++; }
783 column->SortDirectionsAvailList = (ImU8)list;
784 column->SortDirectionsAvailMask = (ImU8)mask;
785 column->SortDirectionsAvailCount = (ImU8)count;
786 ImGui::TableFixColumnSortDirection(table, column);
794void ImGui::TableUpdateLayout(ImGuiTable* table)
797 IM_ASSERT(table->IsLayoutLocked ==
false);
799 const ImGuiTableFlags table_sizing_policy = (table->Flags & ImGuiTableFlags_SizingMask_);
800 table->IsDefaultDisplayOrder =
true;
801 table->ColumnsEnabledCount = 0;
802 ImBitArrayClearAllBits(table->EnabledMaskByIndex, table->ColumnsCount);
803 ImBitArrayClearAllBits(table->EnabledMaskByDisplayOrder, table->ColumnsCount);
804 table->LeftMostEnabledColumn = -1;
805 table->MinColumnWidth = ImMax(1.0f,
g.Style.FramePadding.x * 1.0f);
810 int count_stretch = 0;
811 int prev_visible_column_idx = -1;
812 bool has_auto_fit_request =
false;
813 bool has_resizable =
false;
814 float stretch_sum_width_auto = 0.0f;
815 float fixed_max_width_auto = 0.0f;
816 for (
int order_n = 0; order_n < table->ColumnsCount; order_n++)
818 const int column_n = table->DisplayOrderToIndex[order_n];
819 if (column_n != order_n)
820 table->IsDefaultDisplayOrder =
false;
821 ImGuiTableColumn* column = &table->Columns[column_n];
826 if (table->DeclColumnsCount <= column_n)
828 TableSetupColumnFlags(table, column, ImGuiTableColumnFlags_None);
829 column->NameOffset = -1;
831 column->InitStretchWeightOrWidth = -1.0f;
835 if (!(table->Flags & ImGuiTableFlags_Hideable) || (column->Flags & ImGuiTableColumnFlags_NoHide))
836 column->IsUserEnabledNextFrame =
true;
837 if (column->IsUserEnabled != column->IsUserEnabledNextFrame)
839 column->IsUserEnabled = column->IsUserEnabledNextFrame;
840 table->IsSettingsDirty =
true;
842 column->IsEnabled = column->IsUserEnabled && (column->Flags & ImGuiTableColumnFlags_Disabled) == 0;
844 if (column->SortOrder != -1 && !column->IsEnabled)
845 table->IsSortSpecsDirty =
true;
846 if (column->SortOrder > 0 && !(table->Flags & ImGuiTableFlags_SortMulti))
847 table->IsSortSpecsDirty =
true;
850 const bool start_auto_fit = (column->Flags & ImGuiTableColumnFlags_WidthFixed) ? (column->WidthRequest < 0.0f) : (column->StretchWeight < 0.0f);
852 column->AutoFitQueue = column->CannotSkipItemsQueue = (1 << 3) - 1;
854 if (!column->IsEnabled)
856 column->IndexWithinEnabledSet = -1;
861 column->PrevEnabledColumn = (ImGuiTableColumnIdx)prev_visible_column_idx;
862 column->NextEnabledColumn = -1;
863 if (prev_visible_column_idx != -1)
864 table->Columns[prev_visible_column_idx].NextEnabledColumn = (ImGuiTableColumnIdx)column_n;
866 table->LeftMostEnabledColumn = (ImGuiTableColumnIdx)column_n;
867 column->IndexWithinEnabledSet = table->ColumnsEnabledCount++;
868 ImBitArraySetBit(table->EnabledMaskByIndex, column_n);
869 ImBitArraySetBit(table->EnabledMaskByDisplayOrder, column->DisplayOrder);
870 prev_visible_column_idx = column_n;
871 IM_ASSERT(column->IndexWithinEnabledSet <= column->DisplayOrder);
875 if (!column->IsPreserveWidthAuto && table->InstanceCurrent == 0)
876 column->WidthAuto = TableGetColumnWidthAuto(table, column);
879 const bool column_is_resizable = (column->Flags & ImGuiTableColumnFlags_NoResize) == 0;
880 if (column_is_resizable)
881 has_resizable =
true;
882 if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && column->InitStretchWeightOrWidth > 0.0f && !column_is_resizable)
883 column->WidthAuto = column->InitStretchWeightOrWidth;
885 if (column->AutoFitQueue != 0x00)
886 has_auto_fit_request =
true;
887 if (column->Flags & ImGuiTableColumnFlags_WidthStretch)
889 stretch_sum_width_auto += column->WidthAuto;
894 fixed_max_width_auto = ImMax(fixed_max_width_auto, column->WidthAuto);
898 if ((table->Flags & ImGuiTableFlags_Sortable) && table->SortSpecsCount == 0 && !(table->Flags & ImGuiTableFlags_SortTristate))
899 table->IsSortSpecsDirty =
true;
900 table->RightMostEnabledColumn = (ImGuiTableColumnIdx)prev_visible_column_idx;
901 IM_ASSERT(table->LeftMostEnabledColumn >= 0 && table->RightMostEnabledColumn >= 0);
906 if (has_auto_fit_request && table->OuterWindow != table->InnerWindow)
907 table->InnerWindow->SkipItems =
false;
908 if (has_auto_fit_request)
909 table->IsSettingsDirty =
true;
912 float sum_width_requests = 0.0f;
913 float stretch_sum_weights = 0.0f;
914 table->LeftMostStretchedColumn = table->RightMostStretchedColumn = -1;
915 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
917 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
919 ImGuiTableColumn* column = &table->Columns[column_n];
921 const bool column_is_resizable = (column->Flags & ImGuiTableColumnFlags_NoResize) == 0;
922 if (column->Flags & ImGuiTableColumnFlags_WidthFixed)
925 float width_auto = column->WidthAuto;
926 if (table_sizing_policy == ImGuiTableFlags_SizingFixedSame && (column->AutoFitQueue != 0x00 || !column_is_resizable))
927 width_auto = fixed_max_width_auto;
931 if (column->AutoFitQueue != 0x00)
932 column->WidthRequest = width_auto;
933 else if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !column_is_resizable && column->IsRequestOutput)
934 column->WidthRequest = width_auto;
942 if (column->AutoFitQueue > 0x01 && table->IsInitializing && !column->IsPreserveWidthAuto)
943 column->WidthRequest = ImMax(column->WidthRequest, table->MinColumnWidth * 4.0f);
944 sum_width_requests += column->WidthRequest;
949 if (column->AutoFitQueue != 0x00 || column->StretchWeight < 0.0f || !column_is_resizable)
951 if (column->InitStretchWeightOrWidth > 0.0f)
952 column->StretchWeight = column->InitStretchWeightOrWidth;
953 else if (table_sizing_policy == ImGuiTableFlags_SizingStretchProp)
954 column->StretchWeight = (column->WidthAuto / stretch_sum_width_auto) * count_stretch;
956 column->StretchWeight = 1.0f;
959 stretch_sum_weights += column->StretchWeight;
960 if (table->LeftMostStretchedColumn == -1 || table->Columns[table->LeftMostStretchedColumn].DisplayOrder > column->DisplayOrder)
961 table->LeftMostStretchedColumn = (ImGuiTableColumnIdx)column_n;
962 if (table->RightMostStretchedColumn == -1 || table->Columns[table->RightMostStretchedColumn].DisplayOrder < column->DisplayOrder)
963 table->RightMostStretchedColumn = (ImGuiTableColumnIdx)column_n;
965 column->IsPreserveWidthAuto =
false;
966 sum_width_requests += table->CellPaddingX * 2.0f;
968 table->ColumnsEnabledFixedCount = (ImGuiTableColumnIdx)count_fixed;
969 table->ColumnsStretchSumWeights = stretch_sum_weights;
972 const ImRect work_rect = table->WorkRect;
973 const float width_spacings = (table->OuterPaddingX * 2.0f) + (table->CellSpacingX1 + table->CellSpacingX2) * (table->ColumnsEnabledCount - 1);
974 const float width_removed = (table->HasScrollbarYPrev && !table->InnerWindow->ScrollbarY) ?
g.Style.ScrollbarSize : 0.0f;
975 const float width_avail = ImMax(1.0f, (((table->Flags & ImGuiTableFlags_ScrollX) && table->InnerWidth == 0.0f) ? table->InnerClipRect.GetWidth() : work_rect.GetWidth()) - width_removed);
976 const float width_avail_for_stretched_columns = width_avail - width_spacings - sum_width_requests;
977 float width_remaining_for_stretched_columns = width_avail_for_stretched_columns;
978 table->ColumnsGivenWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount;
979 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
981 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
983 ImGuiTableColumn* column = &table->Columns[column_n];
986 if (column->Flags & ImGuiTableColumnFlags_WidthStretch)
988 float weight_ratio = column->StretchWeight / stretch_sum_weights;
989 column->WidthRequest = IM_TRUNC(ImMax(width_avail_for_stretched_columns * weight_ratio, table->MinColumnWidth) + 0.01f);
990 width_remaining_for_stretched_columns -= column->WidthRequest;
995 if (column->NextEnabledColumn == -1 && table->LeftMostStretchedColumn != -1)
996 column->Flags |= ImGuiTableColumnFlags_NoDirectResize_;
999 column->WidthGiven = ImTrunc(ImMax(column->WidthRequest, table->MinColumnWidth));
1000 table->ColumnsGivenWidth += column->WidthGiven;
1005 if (width_remaining_for_stretched_columns >= 1.0f && !(table->Flags & ImGuiTableFlags_PreciseWidths))
1006 for (
int order_n = table->ColumnsCount - 1; stretch_sum_weights > 0.0f && width_remaining_for_stretched_columns >= 1.0f && order_n >= 0; order_n--)
1008 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n))
1010 ImGuiTableColumn* column = &table->Columns[table->DisplayOrderToIndex[order_n]];
1011 if (!(column->Flags & ImGuiTableColumnFlags_WidthStretch))
1013 column->WidthRequest += 1.0f;
1014 column->WidthGiven += 1.0f;
1015 width_remaining_for_stretched_columns -= 1.0f;
1023 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
1024 table_instance->HoveredRowLast = table_instance->HoveredRowNext;
1025 table_instance->HoveredRowNext = -1;
1026 table->HoveredColumnBody = table->HoveredColumnBorder = -1;
1027 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));
1028 const ImGuiID backup_active_id =
g.ActiveId;
1030 const bool is_hovering_table = ItemHoverable(mouse_hit_rect, 0, ImGuiItemFlags_None);
1031 g.ActiveId = backup_active_id;
1034 float mouse_skewed_x =
g.IO.MousePos.x;
1035 if (table->AngledHeadersHeight > 0.0f)
1036 if (
g.IO.MousePos.y >= table->OuterRect.Min.y &&
g.IO.MousePos.y <= table->OuterRect.Min.y + table->AngledHeadersHeight)
1037 mouse_skewed_x += ImTrunc((table->OuterRect.Min.y + table->AngledHeadersHeight -
g.IO.MousePos.y) * table->AngledHeadersSlope);
1042 bool has_at_least_one_column_requesting_output =
false;
1043 bool offset_x_frozen = (table->FreezeColumnsCount > 0);
1044 float offset_x = ((table->FreezeColumnsCount > 0) ? table->OuterRect.Min.x : work_rect.Min.x) + table->OuterPaddingX - table->CellSpacingX1;
1045 ImRect host_clip_rect = table->InnerClipRect;
1047 ImBitArrayClearAllBits(table->VisibleMaskByIndex, table->ColumnsCount);
1048 for (
int order_n = 0; order_n < table->ColumnsCount; order_n++)
1050 const int column_n = table->DisplayOrderToIndex[order_n];
1051 ImGuiTableColumn* column = &table->Columns[column_n];
1053 column->NavLayerCurrent = (ImS8)(table->FreezeRowsCount > 0 ? ImGuiNavLayer_Menu : ImGuiNavLayer_Main);
1055 if (offset_x_frozen && table->FreezeColumnsCount == visible_n)
1057 offset_x += work_rect.Min.x - table->OuterRect.Min.x;
1058 offset_x_frozen =
false;
1062 column->Flags &= ~ImGuiTableColumnFlags_StatusMask_;
1064 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n))
1068 column->MinX = column->MaxX = column->WorkMinX = column->ClipRect.Min.x = column->ClipRect.Max.x = offset_x;
1069 column->WidthGiven = 0.0f;
1070 column->ClipRect.Min.y = work_rect.Min.y;
1071 column->ClipRect.Max.y = FLT_MAX;
1072 column->ClipRect.ClipWithFull(host_clip_rect);
1073 column->IsVisibleX = column->IsVisibleY = column->IsRequestOutput =
false;
1074 column->IsSkipItems =
true;
1075 column->ItemWidth = 1.0f;
1080 column->MinX = offset_x;
1083 column->WidthMax = TableCalcMaxColumnWidth(table, column_n);
1084 column->WidthGiven = ImMin(column->WidthGiven, column->WidthMax);
1085 column->WidthGiven = ImMax(column->WidthGiven, ImMin(column->WidthRequest, table->MinColumnWidth));
1086 column->MaxX = offset_x + column->WidthGiven + table->CellSpacingX1 + table->CellSpacingX2 + table->CellPaddingX * 2.0f;
1093 const float previous_instance_work_min_x = column->WorkMinX;
1094 column->WorkMinX = column->MinX + table->CellPaddingX + table->CellSpacingX1;
1095 column->WorkMaxX = column->MaxX - table->CellPaddingX - table->CellSpacingX2;
1096 column->ItemWidth = ImTrunc(column->WidthGiven * 0.65f);
1097 column->ClipRect.Min.x = column->MinX;
1098 column->ClipRect.Min.y = work_rect.Min.y;
1099 column->ClipRect.Max.x = column->MaxX;
1100 column->ClipRect.Max.y = FLT_MAX;
1101 column->ClipRect.ClipWithFull(host_clip_rect);
1110 column->IsVisibleX = (column->ClipRect.Max.x > column->ClipRect.Min.x);
1111 column->IsVisibleY =
true;
1112 const bool is_visible = column->IsVisibleX;
1114 ImBitArraySetBit(table->VisibleMaskByIndex, column_n);
1117 column->IsRequestOutput = is_visible || column->AutoFitQueue != 0 || column->CannotSkipItemsQueue != 0;
1121 column->IsSkipItems = !column->IsEnabled || table->HostSkipItems;
1122 if (column->IsSkipItems)
1123 IM_ASSERT(!is_visible);
1124 if (column->IsRequestOutput && !column->IsSkipItems)
1125 has_at_least_one_column_requesting_output =
true;
1128 column->Flags |= ImGuiTableColumnFlags_IsEnabled;
1130 column->Flags |= ImGuiTableColumnFlags_IsVisible;
1131 if (column->SortOrder != -1)
1132 column->Flags |= ImGuiTableColumnFlags_IsSorted;
1135 if (is_hovering_table && mouse_skewed_x >= column->ClipRect.Min.x && mouse_skewed_x < column->ClipRect.Max.x)
1137 column->Flags |= ImGuiTableColumnFlags_IsHovered;
1138 table->HoveredColumnBody = (ImGuiTableColumnIdx)column_n;
1151 if (table->InstanceCurrent == 0)
1153 column->ContentMaxXFrozen = column->WorkMinX;
1154 column->ContentMaxXUnfrozen = column->WorkMinX;
1155 column->ContentMaxXHeadersUsed = column->WorkMinX;
1156 column->ContentMaxXHeadersIdeal = column->WorkMinX;
1161 const float offset_from_previous_instance = column->WorkMinX - previous_instance_work_min_x;
1162 column->ContentMaxXFrozen += offset_from_previous_instance;
1163 column->ContentMaxXUnfrozen += offset_from_previous_instance;
1164 column->ContentMaxXHeadersUsed += offset_from_previous_instance;
1165 column->ContentMaxXHeadersIdeal += offset_from_previous_instance;
1169 if (table->HostSkipItems ==
false && table->InstanceCurrent == 0)
1171 column->AutoFitQueue >>= 1;
1172 column->CannotSkipItemsQueue >>= 1;
1175 if (visible_n < table->FreezeColumnsCount)
1176 host_clip_rect.Min.x = ImClamp(column->MaxX + TABLE_BORDER_SIZE, host_clip_rect.Min.x, host_clip_rect.Max.x);
1178 offset_x += column->WidthGiven + table->CellSpacingX1 + table->CellSpacingX2 + table->CellPaddingX * 2.0f;
1184 if (has_at_least_one_column_requesting_output ==
false)
1186 table->Columns[table->LeftMostEnabledColumn].IsRequestOutput =
true;
1187 table->Columns[table->LeftMostEnabledColumn].IsSkipItems =
false;
1193 const float unused_x1 = ImMax(table->WorkRect.Min.x, table->Columns[table->RightMostEnabledColumn].ClipRect.Max.x);
1194 if (is_hovering_table && table->HoveredColumnBody == -1)
1195 if (mouse_skewed_x >= unused_x1)
1196 table->HoveredColumnBody = (ImGuiTableColumnIdx)table->ColumnsCount;
1197 if (has_resizable ==
false && (table->Flags & ImGuiTableFlags_Resizable))
1198 table->Flags &= ~ImGuiTableFlags_Resizable;
1200 table->IsActiveIdAliveBeforeTable = (
g.ActiveIdIsAlive != 0);
1205 if (table->RightMostStretchedColumn != -1)
1206 table->Flags &= ~ImGuiTableFlags_NoHostExtendX;
1207 if (table->Flags & ImGuiTableFlags_NoHostExtendX)
1209 table->OuterRect.Max.x = table->WorkRect.Max.x = unused_x1;
1210 table->InnerClipRect.Max.x = ImMin(table->InnerClipRect.Max.x, unused_x1);
1212 table->InnerWindow->ParentWorkRect = table->WorkRect;
1213 table->BorderX1 = table->InnerClipRect.Min.x;
1214 table->BorderX2 = table->InnerClipRect.Max.x;
1217 float window_content_max_y;
1218 if (table->Flags & ImGuiTableFlags_NoHostExtendY)
1219 window_content_max_y = table->OuterRect.Max.y;
1221 window_content_max_y = ImMax(table->InnerWindow->ContentRegionRect.Max.y, (table->Flags & ImGuiTableFlags_ScrollY) ? 0.0f : table->OuterRect.Max.y);
1222 table->InnerWindow->WorkRect.Max.y = ImClamp(window_content_max_y -
g.Style.CellPadding.y, table->InnerWindow->WorkRect.Min.y, table->InnerWindow->WorkRect.Max.y);
1225 TableSetupDrawChannels(table);
1228 if (table->Flags & ImGuiTableFlags_Resizable)
1229 TableUpdateBorders(table);
1230 table_instance->LastTopHeadersRowHeight = 0.0f;
1231 table->IsLayoutLocked =
true;
1232 table->IsUsingHeaders =
false;
1235 table->HighlightColumnHeader = -1;
1236 if (table->IsContextPopupOpen && table->ContextPopupColumn != -1 && table->InstanceInteracted == table->InstanceCurrent)
1237 table->HighlightColumnHeader = table->ContextPopupColumn;
1238 else if ((table->Flags & ImGuiTableFlags_HighlightHoveredColumn) && table->HoveredColumnBody != -1 && table->HoveredColumnBody != table->ColumnsCount && table->HoveredColumnBorder == -1)
1239 if (
g.ActiveId == 0 || (table->IsActiveIdInTable ||
g.DragDropActive))
1240 table->HighlightColumnHeader = table->HoveredColumnBody;
1247 if (table->DisableDefaultContextMenu ==
false && TableBeginContextMenuPopup(table))
1249 TableDrawDefaultContextMenu(table, table->Flags);
1255 if (table->IsSortSpecsDirty && (table->Flags & ImGuiTableFlags_Sortable))
1256 TableSortSpecsBuild(table);
1259 if (table->FreezeColumnsRequest > 0)
1260 table->InnerWindow->DecoInnerSizeX1 = table->Columns[table->DisplayOrderToIndex[table->FreezeColumnsRequest - 1]].MaxX - table->OuterRect.Min.x;
1261 if (table->FreezeRowsRequest > 0)
1262 table->InnerWindow->DecoInnerSizeY1 = table_instance->LastFrozenHeight;
1263 table_instance->LastFrozenHeight = 0.0f;
1266 ImGuiWindow* inner_window = table->InnerWindow;
1267 if (table->Flags & ImGuiTableFlags_NoClip)
1268 table->DrawSplitter->SetCurrentChannel(inner_window->DrawList, TABLE_DRAW_CHANNEL_NOCLIP);
1270 inner_window->DrawList->PushClipRect(inner_window->InnerClipRect.Min, inner_window->InnerClipRect.Max,
false);
1275void ImGui::TableUpdateBorders(ImGuiTable* table)
1278 IM_ASSERT(table->Flags & ImGuiTableFlags_Resizable);
1284 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
1285 const float hit_half_width = ImTrunc(TABLE_RESIZE_SEPARATOR_HALF_THICKNESS *
g.CurrentDpiScale);
1286 const float hit_y1 = (table->FreezeRowsCount >= 1 ? table->OuterRect.Min.y : table->WorkRect.Min.y) + table->AngledHeadersHeight;
1287 const float hit_y2_body = ImMax(table->OuterRect.Max.y, hit_y1 + table_instance->LastOuterHeight - table->AngledHeadersHeight);
1288 const float hit_y2_head = hit_y1 + table_instance->LastTopHeadersRowHeight;
1290 for (
int order_n = 0; order_n < table->ColumnsCount; order_n++)
1292 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n))
1295 const int column_n = table->DisplayOrderToIndex[order_n];
1296 ImGuiTableColumn* column = &table->Columns[column_n];
1297 if (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_))
1301 const float border_y2_hit = (table->Flags & ImGuiTableFlags_NoBordersInBody) ? hit_y2_head : hit_y2_body;
1302 if ((table->Flags & ImGuiTableFlags_NoBordersInBody) && table->IsUsingHeaders ==
false)
1305 if (!column->IsVisibleX && table->LastResizedColumn != column_n)
1308 ImGuiID column_id = TableGetColumnResizeID(table, column_n, table->InstanceCurrent);
1309 ImRect hit_rect(column->MaxX - hit_half_width, hit_y1, column->MaxX + hit_half_width, border_y2_hit);
1310 ItemAdd(hit_rect, column_id, NULL, ImGuiItemFlags_NoNav);
1313 bool hovered =
false, held =
false;
1314 bool pressed = ButtonBehavior(hit_rect, column_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_NoNavFocus);
1315 if (pressed && IsMouseDoubleClicked(0))
1317 TableSetColumnWidthAutoSingle(table, column_n);
1323 if (table->LastResizedColumn == -1)
1324 table->ResizeLockMinContentsX2 = table->RightMostEnabledColumn != -1 ? table->Columns[table->RightMostEnabledColumn].MaxX : -FLT_MAX;
1325 table->ResizedColumn = (ImGuiTableColumnIdx)column_n;
1326 table->InstanceInteracted = table->InstanceCurrent;
1328 if ((hovered &&
g.HoveredIdTimer > TABLE_RESIZE_SEPARATOR_FEEDBACK_TIMER) || held)
1330 table->HoveredColumnBorder = (ImGuiTableColumnIdx)column_n;
1331 SetMouseCursor(ImGuiMouseCursor_ResizeEW);
1336void ImGui::EndTable()
1339 ImGuiTable* table =
g.CurrentTable;
1342 IM_ASSERT_USER_ERROR(table != NULL,
"EndTable() call should only be done while in BeginTable() scope!");
1352 if (!table->IsLayoutLocked)
1353 TableUpdateLayout(table);
1355 const ImGuiTableFlags flags = table->Flags;
1356 ImGuiWindow* inner_window = table->InnerWindow;
1357 ImGuiWindow* outer_window = table->OuterWindow;
1358 ImGuiTableTempData* temp_data = table->TempData;
1359 IM_ASSERT(inner_window ==
g.CurrentWindow);
1360 IM_ASSERT(outer_window == inner_window || outer_window == inner_window->ParentWindow);
1362 if (table->IsInsideRow)
1366 if (flags & ImGuiTableFlags_ContextMenuInBody)
1367 if (table->HoveredColumnBody != -1 && !IsAnyItemHovered() && IsMouseReleased(ImGuiMouseButton_Right))
1368 TableOpenContextMenu((
int)table->HoveredColumnBody);
1371 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
1372 inner_window->DC.PrevLineSize = temp_data->HostBackupPrevLineSize;
1373 inner_window->DC.CurrLineSize = temp_data->HostBackupCurrLineSize;
1374 inner_window->DC.CursorMaxPos = temp_data->HostBackupCursorMaxPos;
1375 const float inner_content_max_y = table->RowPosY2;
1376 IM_ASSERT(table->RowPosY2 == inner_window->DC.CursorPos.y);
1377 if (inner_window != outer_window)
1378 inner_window->DC.CursorMaxPos.y = inner_content_max_y;
1379 else if (!(flags & ImGuiTableFlags_NoHostExtendY))
1380 table->OuterRect.Max.y = table->InnerRect.Max.y = ImMax(table->OuterRect.Max.y, inner_content_max_y);
1381 table->WorkRect.Max.y = ImMax(table->WorkRect.Max.y, table->OuterRect.Max.y);
1382 table_instance->LastOuterHeight = table->OuterRect.GetHeight();
1387 if (table->Flags & ImGuiTableFlags_ScrollX)
1389 const float outer_padding_for_border = (table->Flags & ImGuiTableFlags_BordersOuterV) ? TABLE_BORDER_SIZE : 0.0f;
1390 float max_pos_x = table->InnerWindow->DC.CursorMaxPos.x;
1391 if (table->RightMostEnabledColumn != -1)
1392 max_pos_x = ImMax(max_pos_x, table->Columns[table->RightMostEnabledColumn].WorkMaxX + table->CellPaddingX + table->OuterPaddingX - outer_padding_for_border);
1393 if (table->ResizedColumn != -1)
1394 max_pos_x = ImMax(max_pos_x, table->ResizeLockMinContentsX2);
1395 table->InnerWindow->DC.CursorMaxPos.x = max_pos_x + table->TempData->AngledHeadersExtraWidth;
1399 if (!(flags & ImGuiTableFlags_NoClip))
1400 inner_window->DrawList->PopClipRect();
1401 inner_window->ClipRect = inner_window->DrawList->_ClipRectStack.back();
1404 if ((flags & ImGuiTableFlags_Borders) != 0)
1405 TableDrawBorders(table);
1412 if (table->DummyDrawChannel != (ImGuiTableColumnIdx)-1)
1414 ImDrawChannel* dummy_channel = &table->DrawSplitter._Channels[table->DummyDrawChannel];
1415 dummy_channel->_CmdBuffer.resize(0);
1416 dummy_channel->_IdxBuffer.resize(0);
1421 ImDrawListSplitter* splitter = table->DrawSplitter;
1422 splitter->SetCurrentChannel(inner_window->DrawList, 0);
1423 if ((table->Flags & ImGuiTableFlags_NoClip) == 0)
1424 TableMergeDrawChannels(table);
1425 splitter->Merge(inner_window->DrawList);
1428 float auto_fit_width_for_fixed = 0.0f;
1429 float auto_fit_width_for_stretched = 0.0f;
1430 float auto_fit_width_for_stretched_min = 0.0f;
1431 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
1432 if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
1434 ImGuiTableColumn* column = &table->Columns[column_n];
1435 float column_width_request = ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !(column->Flags & ImGuiTableColumnFlags_NoResize)) ? column->WidthRequest : TableGetColumnWidthAuto(table, column);
1436 if (column->Flags & ImGuiTableColumnFlags_WidthFixed)
1437 auto_fit_width_for_fixed += column_width_request;
1439 auto_fit_width_for_stretched += column_width_request;
1440 if ((column->Flags & ImGuiTableColumnFlags_WidthStretch) && (column->Flags & ImGuiTableColumnFlags_NoResize) != 0)
1441 auto_fit_width_for_stretched_min = ImMax(auto_fit_width_for_stretched_min, column_width_request / (column->StretchWeight / table->ColumnsStretchSumWeights));
1443 const float width_spacings = (table->OuterPaddingX * 2.0f) + (table->CellSpacingX1 + table->CellSpacingX2) * (table->ColumnsEnabledCount - 1);
1444 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);
1447 if ((table->Flags & ImGuiTableFlags_ScrollX) == 0 && inner_window != outer_window)
1449 inner_window->Scroll.x = 0.0f;
1451 else if (table->LastResizedColumn != -1 && table->ResizedColumn == -1 && inner_window->ScrollbarX && table->InstanceInteracted == table->InstanceCurrent)
1454 const float neighbor_width_to_keep_visible = table->MinColumnWidth + table->CellPaddingX * 2.0f;
1455 ImGuiTableColumn* column = &table->Columns[table->LastResizedColumn];
1456 if (column->MaxX < table->InnerClipRect.Min.x)
1457 SetScrollFromPosX(inner_window, column->MaxX - inner_window->Pos.x - neighbor_width_to_keep_visible, 1.0f);
1458 else if (column->MaxX > table->InnerClipRect.Max.x)
1459 SetScrollFromPosX(inner_window, column->MaxX - inner_window->Pos.x + neighbor_width_to_keep_visible, 1.0f);
1463 if (table->ResizedColumn != -1 && table->InstanceCurrent == table->InstanceInteracted)
1465 ImGuiTableColumn* column = &table->Columns[table->ResizedColumn];
1466 const float new_x2 = (
g.IO.MousePos.x -
g.ActiveIdClickOffset.x + ImTrunc(TABLE_RESIZE_SEPARATOR_HALF_THICKNESS *
g.CurrentDpiScale));
1467 const float new_width = ImTrunc(new_x2 - column->MinX - table->CellSpacingX1 - table->CellPaddingX * 2.0f);
1468 table->ResizedColumnNextWidth = new_width;
1471 table->IsActiveIdInTable = (
g.ActiveIdIsAlive != 0 && table->IsActiveIdAliveBeforeTable ==
false);
1474 IM_ASSERT_USER_ERROR(inner_window->IDStack.back() == table_instance->TableInstanceID,
"Mismatching PushID/PopID!");
1475 IM_ASSERT_USER_ERROR(outer_window->DC.ItemWidthStack.Size >= temp_data->HostBackupItemWidthStackSize,
"Too many PopItemWidth!");
1476 if (table->InstanceCurrent > 0)
1481 const ImVec2 backup_outer_max_pos = outer_window->DC.CursorMaxPos;
1482 inner_window->WorkRect = temp_data->HostBackupWorkRect;
1483 inner_window->ParentWorkRect = temp_data->HostBackupParentWorkRect;
1484 inner_window->SkipItems = table->HostSkipItems;
1485 outer_window->DC.CursorPos = table->OuterRect.Min;
1486 outer_window->DC.ItemWidth = temp_data->HostBackupItemWidth;
1487 outer_window->DC.ItemWidthStack.Size = temp_data->HostBackupItemWidthStackSize;
1488 outer_window->DC.ColumnsOffset = temp_data->HostBackupColumnsOffset;
1493 if (inner_window != outer_window)
1495 short backup_nav_layers_active_mask = inner_window->DC.NavLayersActiveMask;
1496 inner_window->DC.NavLayersActiveMask |= 1 << ImGuiNavLayer_Main;
1497 g.CurrentTable = NULL;
1499 g.CurrentTable = table;
1500 inner_window->DC.NavLayersActiveMask = backup_nav_layers_active_mask;
1504 ItemSize(table->OuterRect.GetSize());
1505 ItemAdd(table->OuterRect, 0);
1509 if (table->Flags & ImGuiTableFlags_NoHostExtendX)
1513 IM_ASSERT((table->Flags & ImGuiTableFlags_ScrollX) == 0);
1514 outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, table->OuterRect.Min.x + table->ColumnsAutoFitWidth);
1516 else if (temp_data->UserOuterSize.x <= 0.0f)
1521 const float inner_content_max_x = table->OuterRect.Min.x + table->ColumnsAutoFitWidth;
1522 const float decoration_size = table->TempData->AngledHeadersExtraWidth + ((table->Flags & ImGuiTableFlags_ScrollY) ? inner_window->ScrollbarSizes.x : 0.0f);
1523 outer_window->DC.IdealMaxPos.x = ImMax(outer_window->DC.IdealMaxPos.x, inner_content_max_x + decoration_size - temp_data->UserOuterSize.x);
1524 outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, ImMin(table->OuterRect.Max.x, inner_content_max_x + decoration_size));
1528 outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, table->OuterRect.Max.x);
1530 if (temp_data->UserOuterSize.y <= 0.0f)
1532 const float decoration_size = (table->Flags & ImGuiTableFlags_ScrollX) ? inner_window->ScrollbarSizes.y : 0.0f;
1533 outer_window->DC.IdealMaxPos.y = ImMax(outer_window->DC.IdealMaxPos.y, inner_content_max_y + decoration_size - temp_data->UserOuterSize.y);
1534 outer_window->DC.CursorMaxPos.y = ImMax(backup_outer_max_pos.y, ImMin(table->OuterRect.Max.y, inner_content_max_y + decoration_size));
1539 outer_window->DC.CursorMaxPos.y = ImMax(backup_outer_max_pos.y, table->OuterRect.Max.y);
1543 if (table->IsSettingsDirty)
1544 TableSaveSettings(table);
1545 table->IsInitializing =
false;
1548 IM_ASSERT(
g.CurrentWindow == outer_window &&
g.CurrentTable == table);
1549 IM_ASSERT(
g.TablesTempDataStacked > 0);
1550 temp_data = (--
g.TablesTempDataStacked > 0) ? &
g.TablesTempData[
g.TablesTempDataStacked - 1] : NULL;
1551 g.CurrentTable = temp_data ?
g.Tables.GetByIndex(temp_data->TableIndex) : NULL;
1554 g.CurrentTable->TempData = temp_data;
1555 g.CurrentTable->DrawSplitter = &temp_data->DrawSplitter;
1557 outer_window->DC.CurrentTableIdx =
g.CurrentTable ?
g.Tables.GetIndex(
g.CurrentTable) : -1;
1558 NavUpdateCurrentWindowIsScrollPushableX();
1563void ImGui::TableSetupColumn(
const char* label, ImGuiTableColumnFlags flags,
float init_width_or_weight, ImGuiID user_id)
1566 ImGuiTable* table =
g.CurrentTable;
1569 IM_ASSERT_USER_ERROR(table != NULL,
"Call should only be done while in BeginTable() scope!");
1572 IM_ASSERT(table->IsLayoutLocked ==
false &&
"Need to call TableSetupColumn() before first row!");
1573 IM_ASSERT((flags & ImGuiTableColumnFlags_StatusMask_) == 0 &&
"Illegal to pass StatusMask values to TableSetupColumn()");
1574 if (table->DeclColumnsCount >= table->ColumnsCount)
1576 IM_ASSERT_USER_ERROR(table->DeclColumnsCount < table->ColumnsCount,
"Called TableSetupColumn() too many times!");
1580 ImGuiTableColumn* column = &table->Columns[table->DeclColumnsCount];
1581 table->DeclColumnsCount++;
1585 if (table->IsDefaultSizingPolicy && (flags & ImGuiTableColumnFlags_WidthMask_) == 0 && (flags & ImGuiTableFlags_ScrollX) == 0)
1586 IM_ASSERT(init_width_or_weight <= 0.0f &&
"Can only specify width/weight if sizing policy is set explicitly in either Table or Column.");
1590 if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0 && init_width_or_weight > 0.0f)
1591 if ((table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedFit || (table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedSame)
1592 flags |= ImGuiTableColumnFlags_WidthFixed;
1593 if (flags & ImGuiTableColumnFlags_AngledHeader)
1595 flags |= ImGuiTableColumnFlags_NoHeaderLabel;
1596 table->AngledHeadersCount++;
1599 TableSetupColumnFlags(table, column, flags);
1600 column->UserID = user_id;
1601 flags = column->Flags;
1604 column->InitStretchWeightOrWidth = init_width_or_weight;
1605 if (table->IsInitializing)
1608 if (column->WidthRequest < 0.0f && column->StretchWeight < 0.0f)
1610 if ((flags & ImGuiTableColumnFlags_WidthFixed) && init_width_or_weight > 0.0f)
1611 column->WidthRequest = init_width_or_weight;
1612 if (flags & ImGuiTableColumnFlags_WidthStretch)
1613 column->StretchWeight = (init_width_or_weight > 0.0f) ? init_width_or_weight : -1.0f;
1616 if (init_width_or_weight > 0.0f)
1617 column->AutoFitQueue = 0x00;
1621 if ((flags & ImGuiTableColumnFlags_DefaultHide) && (table->SettingsLoadedFlags & ImGuiTableFlags_Hideable) == 0)
1622 column->IsUserEnabled = column->IsUserEnabledNextFrame =
false;
1623 if (flags & ImGuiTableColumnFlags_DefaultSort && (table->SettingsLoadedFlags & ImGuiTableFlags_Sortable) == 0)
1625 column->SortOrder = 0;
1626 column->SortDirection = (column->Flags & ImGuiTableColumnFlags_PreferSortDescending) ? (ImS8)ImGuiSortDirection_Descending : (ImU8)(ImGuiSortDirection_Ascending);
1632 column->NameOffset = -1;
1633 if (label != NULL && label[0] != 0)
1635 column->NameOffset = (ImS16)table->ColumnsNames.size();
1636 table->ColumnsNames.append(label, label + strlen(label) + 1);
1641void ImGui::TableSetupScrollFreeze(
int columns,
int rows)
1644 ImGuiTable* table =
g.CurrentTable;
1647 IM_ASSERT_USER_ERROR(table != NULL,
"Call should only be done while in BeginTable() scope!");
1650 IM_ASSERT(table->IsLayoutLocked ==
false &&
"Need to call TableSetupColumn() before first row!");
1651 IM_ASSERT(columns >= 0 && columns < IMGUI_TABLE_MAX_COLUMNS);
1652 IM_ASSERT(rows >= 0 && rows < 128);
1654 table->FreezeColumnsRequest = (table->Flags & ImGuiTableFlags_ScrollX) ? (ImGuiTableColumnIdx)ImMin(columns, table->ColumnsCount) : 0;
1655 table->FreezeColumnsCount = (table->InnerWindow->Scroll.x != 0.0f) ? table->FreezeColumnsRequest : 0;
1656 table->FreezeRowsRequest = (table->Flags & ImGuiTableFlags_ScrollY) ? (ImGuiTableColumnIdx)rows : 0;
1657 table->FreezeRowsCount = (table->InnerWindow->Scroll.y != 0.0f) ? table->FreezeRowsRequest : 0;
1658 table->IsUnfrozenRows = (table->FreezeRowsCount == 0);
1662 for (
int column_n = 0; column_n < table->FreezeColumnsRequest; column_n++)
1664 int order_n = table->DisplayOrderToIndex[column_n];
1665 if (order_n != column_n && order_n >= table->FreezeColumnsRequest)
1667 ImSwap(table->Columns[table->DisplayOrderToIndex[order_n]].DisplayOrder, table->Columns[table->DisplayOrderToIndex[column_n]].DisplayOrder);
1668 ImSwap(table->DisplayOrderToIndex[order_n], table->DisplayOrderToIndex[column_n]);
1688int ImGui::TableGetColumnCount()
1691 ImGuiTable* table =
g.CurrentTable;
1692 return table ? table->ColumnsCount : 0;
1695const char* ImGui::TableGetColumnName(
int column_n)
1698 ImGuiTable* table =
g.CurrentTable;
1702 column_n = table->CurrentColumn;
1703 return TableGetColumnName(table, column_n);
1706const char* ImGui::TableGetColumnName(
const ImGuiTable* table,
int column_n)
1708 if (table->IsLayoutLocked ==
false && column_n >= table->DeclColumnsCount)
1710 const ImGuiTableColumn* column = &table->Columns[column_n];
1711 if (column->NameOffset == -1)
1713 return &table->ColumnsNames.Buf[column->NameOffset];
1722void ImGui::TableSetColumnEnabled(
int column_n,
bool enabled)
1725 ImGuiTable* table =
g.CurrentTable;
1728 IM_ASSERT_USER_ERROR(table != NULL,
"Call should only be done while in BeginTable() scope!");
1731 IM_ASSERT(table->Flags & ImGuiTableFlags_Hideable);
1733 column_n = table->CurrentColumn;
1734 IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
1735 ImGuiTableColumn* column = &table->Columns[column_n];
1736 column->IsUserEnabledNextFrame = enabled;
1740ImGuiTableColumnFlags ImGui::TableGetColumnFlags(
int column_n)
1743 ImGuiTable* table =
g.CurrentTable;
1745 return ImGuiTableColumnFlags_None;
1747 column_n = table->CurrentColumn;
1748 if (column_n == table->ColumnsCount)
1749 return (table->HoveredColumnBody == column_n) ? ImGuiTableColumnFlags_IsHovered : ImGuiTableColumnFlags_None;
1750 return table->Columns[column_n].Flags;
1759ImRect ImGui::TableGetCellBgRect(
const ImGuiTable* table,
int column_n)
1761 const ImGuiTableColumn* column = &table->Columns[column_n];
1762 float x1 = column->MinX;
1763 float x2 = column->MaxX;
1768 x1 = ImMax(x1, table->WorkRect.Min.x);
1769 x2 = ImMin(x2, table->WorkRect.Max.x);
1770 return ImRect(x1, table->RowPosY1, x2, table->RowPosY2);
1774ImGuiID ImGui::TableGetColumnResizeID(ImGuiTable* table,
int column_n,
int instance_no)
1776 IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
1777 ImGuiID instance_id = TableGetInstanceID(table, instance_no);
1778 return instance_id + 1 + column_n;
1782int ImGui::TableGetHoveredColumn()
1785 ImGuiTable* table =
g.CurrentTable;
1788 return (
int)table->HoveredColumnBody;
1794int ImGui::TableGetHoveredRow()
1797 ImGuiTable* table =
g.CurrentTable;
1800 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
1801 return (
int)table_instance->HoveredRowLast;
1804void ImGui::TableSetBgColor(ImGuiTableBgTarget target, ImU32 color,
int column_n)
1807 ImGuiTable* table =
g.CurrentTable;
1808 IM_ASSERT(target != ImGuiTableBgTarget_None);
1810 if (color == IM_COL32_DISABLE)
1816 case ImGuiTableBgTarget_CellBg:
1818 if (table->RowPosY1 > table->InnerClipRect.Max.y)
1821 column_n = table->CurrentColumn;
1822 if (!IM_BITARRAY_TESTBIT(table->VisibleMaskByIndex, column_n))
1824 if (table->RowCellDataCurrent < 0 || table->RowCellData[table->RowCellDataCurrent].Column != column_n)
1825 table->RowCellDataCurrent++;
1826 ImGuiTableCellData* cell_data = &table->RowCellData[table->RowCellDataCurrent];
1827 cell_data->BgColor = color;
1828 cell_data->Column = (ImGuiTableColumnIdx)column_n;
1831 case ImGuiTableBgTarget_RowBg0:
1832 case ImGuiTableBgTarget_RowBg1:
1834 if (table->RowPosY1 > table->InnerClipRect.Max.y)
1836 IM_ASSERT(column_n == -1);
1837 int bg_idx = (target == ImGuiTableBgTarget_RowBg1) ? 1 : 0;
1838 table->RowBgColor[bg_idx] = color;
1856int ImGui::TableGetRowIndex()
1859 ImGuiTable* table =
g.CurrentTable;
1862 return table->CurrentRow;
1866void ImGui::TableNextRow(ImGuiTableRowFlags row_flags,
float row_min_height)
1869 ImGuiTable* table =
g.CurrentTable;
1871 if (!table->IsLayoutLocked)
1872 TableUpdateLayout(table);
1873 if (table->IsInsideRow)
1876 table->LastRowFlags = table->RowFlags;
1877 table->RowFlags = row_flags;
1878 table->RowCellPaddingY =
g.Style.CellPadding.y;
1879 table->RowMinHeight = row_min_height;
1880 TableBeginRow(table);
1884 table->RowPosY2 += table->RowCellPaddingY * 2.0f;
1885 table->RowPosY2 = ImMax(table->RowPosY2, table->RowPosY1 + row_min_height);
1888 table->InnerWindow->SkipItems =
true;
1892void ImGui::TableBeginRow(ImGuiTable* table)
1894 ImGuiWindow* window = table->InnerWindow;
1895 IM_ASSERT(!table->IsInsideRow);
1898 table->CurrentRow++;
1899 table->CurrentColumn = -1;
1900 table->RowBgColor[0] = table->RowBgColor[1] = IM_COL32_DISABLE;
1901 table->RowCellDataCurrent = -1;
1902 table->IsInsideRow =
true;
1905 float next_y1 = table->RowPosY2;
1906 if (table->CurrentRow == 0 && table->FreezeRowsCount > 0)
1907 next_y1 = window->DC.CursorPos.y = table->OuterRect.Min.y;
1909 table->RowPosY1 = table->RowPosY2 = next_y1;
1910 table->RowTextBaseline = 0.0f;
1911 table->RowIndentOffsetX = window->DC.Indent.x - table->HostIndentX;
1913 window->DC.PrevLineTextBaseOffset = 0.0f;
1914 window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x, window->DC.CursorPos.y + table->RowCellPaddingY);
1915 window->DC.PrevLineSize = window->DC.CurrLineSize = ImVec2(0.0f, 0.0f);
1916 window->DC.IsSameLine = window->DC.IsSetPos =
false;
1917 window->DC.CursorMaxPos.y = next_y1;
1920 if (table->RowFlags & ImGuiTableRowFlags_Headers)
1922 TableSetBgColor(ImGuiTableBgTarget_RowBg0, GetColorU32(ImGuiCol_TableHeaderBg));
1923 if (table->CurrentRow == 0)
1924 table->IsUsingHeaders =
true;
1929void ImGui::TableEndRow(ImGuiTable* table)
1932 ImGuiWindow* window =
g.CurrentWindow;
1933 IM_ASSERT(window == table->InnerWindow);
1934 IM_ASSERT(table->IsInsideRow);
1936 if (table->CurrentColumn != -1)
1937 TableEndCell(table);
1941 LogRenderedText(NULL,
"|");
1945 window->DC.CursorPos.y = table->RowPosY2;
1948 const float bg_y1 = table->RowPosY1;
1949 const float bg_y2 = table->RowPosY2;
1950 const bool unfreeze_rows_actual = (table->CurrentRow + 1 == table->FreezeRowsCount);
1951 const bool unfreeze_rows_request = (table->CurrentRow + 1 == table->FreezeRowsRequest);
1952 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
1953 if ((table->RowFlags & ImGuiTableRowFlags_Headers) && (table->CurrentRow == 0 || (table->LastRowFlags & ImGuiTableRowFlags_Headers)))
1954 table_instance->LastTopHeadersRowHeight += bg_y2 - bg_y1;
1956 const bool is_visible = (bg_y2 >= table->InnerClipRect.Min.y && bg_y1 <= table->InnerClipRect.Max.y);
1960 if (table->HoveredColumnBody != -1 &&
g.IO.MousePos.y >= bg_y1 &&
g.IO.MousePos.y < bg_y2 && table_instance->HoveredRowNext < 0)
1961 table_instance->HoveredRowNext = table->CurrentRow;
1966 if (table->RowBgColor[0] != IM_COL32_DISABLE)
1967 bg_col0 = table->RowBgColor[0];
1968 else if (table->Flags & ImGuiTableFlags_RowBg)
1969 bg_col0 = GetColorU32((table->RowBgColorCounter & 1) ? ImGuiCol_TableRowBgAlt : ImGuiCol_TableRowBg);
1970 if (table->RowBgColor[1] != IM_COL32_DISABLE)
1971 bg_col1 = table->RowBgColor[1];
1974 ImU32 top_border_col = 0;
1975 const float border_size = TABLE_BORDER_SIZE;
1976 if (table->CurrentRow > 0 && (table->Flags & ImGuiTableFlags_BordersInnerH))
1977 top_border_col = (table->LastRowFlags & ImGuiTableRowFlags_Headers) ? table->BorderColorStrong : table->BorderColorLight;
1979 const bool draw_cell_bg_color = table->RowCellDataCurrent >= 0;
1980 const bool draw_strong_bottom_border = unfreeze_rows_actual;
1981 if ((bg_col0 | bg_col1 | top_border_col) != 0 || draw_strong_bottom_border || draw_cell_bg_color)
1985 if ((table->Flags & ImGuiTableFlags_NoClip) == 0)
1986 window->DrawList->_CmdHeader.ClipRect = table->Bg0ClipRectForDrawCmd.ToVec4();
1987 table->DrawSplitter->SetCurrentChannel(window->DrawList, TABLE_DRAW_CHANNEL_BG0);
1992 if (bg_col0 || bg_col1)
1994 ImRect row_rect(table->WorkRect.Min.x, bg_y1, table->WorkRect.Max.x, bg_y2);
1995 row_rect.ClipWith(table->BgClipRect);
1996 if (bg_col0 != 0 && row_rect.Min.y < row_rect.Max.y)
1997 window->DrawList->AddRectFilled(row_rect.Min, row_rect.Max, bg_col0);
1998 if (bg_col1 != 0 && row_rect.Min.y < row_rect.Max.y)
1999 window->DrawList->AddRectFilled(row_rect.Min, row_rect.Max, bg_col1);
2003 if (draw_cell_bg_color)
2005 ImGuiTableCellData* cell_data_end = &table->RowCellData[table->RowCellDataCurrent];
2006 for (ImGuiTableCellData* cell_data = &table->RowCellData[0]; cell_data <= cell_data_end; cell_data++)
2010 const ImGuiTableColumn* column = &table->Columns[cell_data->Column];
2011 ImRect cell_bg_rect = TableGetCellBgRect(table, cell_data->Column);
2012 cell_bg_rect.ClipWith(table->BgClipRect);
2013 cell_bg_rect.Min.x = ImMax(cell_bg_rect.Min.x, column->ClipRect.Min.x);
2014 cell_bg_rect.Max.x = ImMin(cell_bg_rect.Max.x, column->MaxX);
2015 if (cell_bg_rect.Min.y < cell_bg_rect.Max.y)
2016 window->DrawList->AddRectFilled(cell_bg_rect.Min, cell_bg_rect.Max, cell_data->BgColor);
2021 if (top_border_col && bg_y1 >= table->BgClipRect.Min.y && bg_y1 < table->BgClipRect.Max.y)
2022 window->DrawList->AddLine(ImVec2(table->BorderX1, bg_y1), ImVec2(table->BorderX2, bg_y1), top_border_col, border_size);
2025 if (draw_strong_bottom_border && bg_y2 >= table->BgClipRect.Min.y && bg_y2 < table->BgClipRect.Max.y)
2026 window->DrawList->AddLine(ImVec2(table->BorderX1, bg_y2), ImVec2(table->BorderX2, bg_y2), table->BorderColorStrong, border_size);
2032 if (unfreeze_rows_request)
2034 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2035 table->Columns[column_n].NavLayerCurrent = ImGuiNavLayer_Main;
2036 const float y0 = ImMax(table->RowPosY2 + 1, table->InnerClipRect.Min.y);
2037 table_instance->LastFrozenHeight = y0 - table->OuterRect.Min.y;
2039 if (unfreeze_rows_actual)
2041 IM_ASSERT(table->IsUnfrozenRows ==
false);
2042 table->IsUnfrozenRows =
true;
2045 table->BgClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y = ImMin(y0, table->InnerClipRect.Max.y);
2046 table->BgClipRect.Max.y = table->Bg2ClipRectForDrawCmd.Max.y = table->InnerClipRect.Max.y;
2047 table->Bg2DrawChannelCurrent = table->Bg2DrawChannelUnfrozen;
2048 IM_ASSERT(table->Bg2ClipRectForDrawCmd.Min.y <= table->Bg2ClipRectForDrawCmd.Max.y);
2050 float row_height = table->RowPosY2 - table->RowPosY1;
2051 table->RowPosY2 = window->DC.CursorPos.y = table->WorkRect.Min.y + table->RowPosY2 - table->OuterRect.Min.y;
2052 table->RowPosY1 = table->RowPosY2 - row_height;
2053 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2055 ImGuiTableColumn* column = &table->Columns[column_n];
2056 column->DrawChannelCurrent = column->DrawChannelUnfrozen;
2057 column->ClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y;
2061 SetWindowClipRectBeforeSetChannel(window, table->Columns[0].ClipRect);
2062 table->DrawSplitter->SetCurrentChannel(window->DrawList, table->Columns[0].DrawChannelCurrent);
2066 if (!(table->RowFlags & ImGuiTableRowFlags_Headers))
2067 table->RowBgColorCounter++;
2068 table->IsInsideRow =
false;
2081int ImGui::TableGetColumnIndex()
2084 ImGuiTable* table =
g.CurrentTable;
2087 return table->CurrentColumn;
2091bool ImGui::TableSetColumnIndex(
int column_n)
2094 ImGuiTable* table =
g.CurrentTable;
2098 if (table->CurrentColumn != column_n)
2100 if (table->CurrentColumn != -1)
2101 TableEndCell(table);
2102 IM_ASSERT(column_n >= 0 && table->ColumnsCount);
2103 TableBeginCell(table, column_n);
2108 return table->Columns[column_n].IsRequestOutput;
2112bool ImGui::TableNextColumn()
2115 ImGuiTable* table =
g.CurrentTable;
2119 if (table->IsInsideRow && table->CurrentColumn + 1 < table->ColumnsCount)
2121 if (table->CurrentColumn != -1)
2122 TableEndCell(table);
2123 TableBeginCell(table, table->CurrentColumn + 1);
2128 TableBeginCell(table, 0);
2133 return table->Columns[table->CurrentColumn].IsRequestOutput;
2140void ImGui::TableBeginCell(ImGuiTable* table,
int column_n)
2143 ImGuiTableColumn* column = &table->Columns[column_n];
2144 ImGuiWindow* window = table->InnerWindow;
2145 table->CurrentColumn = column_n;
2148 float start_x = column->WorkMinX;
2149 if (column->Flags & ImGuiTableColumnFlags_IndentEnable)
2150 start_x += table->RowIndentOffsetX;
2152 window->DC.CursorPos.x = start_x;
2153 window->DC.CursorPos.y = table->RowPosY1 + table->RowCellPaddingY;
2154 window->DC.CursorMaxPos.x = window->DC.CursorPos.x;
2155 window->DC.ColumnsOffset.x = start_x - window->Pos.x - window->DC.Indent.x;
2156 window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x;
2157 window->DC.CurrLineTextBaseOffset = table->RowTextBaseline;
2158 window->DC.NavLayerCurrent = (ImGuiNavLayer)column->NavLayerCurrent;
2161 window->WorkRect.Min.y = window->DC.CursorPos.y;
2162 window->WorkRect.Min.x = column->WorkMinX;
2163 window->WorkRect.Max.x = column->WorkMaxX;
2164 window->DC.ItemWidth = column->ItemWidth;
2166 window->SkipItems = column->IsSkipItems;
2167 if (column->IsSkipItems)
2169 g.LastItemData.ID = 0;
2170 g.LastItemData.StatusFlags = 0;
2173 if (table->Flags & ImGuiTableFlags_NoClip)
2176 table->DrawSplitter->SetCurrentChannel(window->DrawList, TABLE_DRAW_CHANNEL_NOCLIP);
2182 SetWindowClipRectBeforeSetChannel(window, column->ClipRect);
2183 table->DrawSplitter->SetCurrentChannel(window->DrawList, column->DrawChannelCurrent);
2187 if (
g.LogEnabled && !column->IsSkipItems)
2189 LogRenderedText(&window->DC.CursorPos,
"|");
2190 g.LogLinePosY = FLT_MAX;
2195void ImGui::TableEndCell(ImGuiTable* table)
2197 ImGuiTableColumn* column = &table->Columns[table->CurrentColumn];
2198 ImGuiWindow* window = table->InnerWindow;
2200 if (window->DC.IsSetPos)
2201 ErrorCheckUsingSetCursorPosToExtendParentBoundaries();
2205 if (table->RowFlags & ImGuiTableRowFlags_Headers)
2206 p_max_pos_x = &column->ContentMaxXHeadersUsed;
2208 p_max_pos_x = table->IsUnfrozenRows ? &column->ContentMaxXUnfrozen : &column->ContentMaxXFrozen;
2209 *p_max_pos_x = ImMax(*p_max_pos_x, window->DC.CursorMaxPos.x);
2210 if (column->IsEnabled)
2211 table->RowPosY2 = ImMax(table->RowPosY2, window->DC.CursorMaxPos.y + table->RowCellPaddingY);
2212 column->ItemWidth = window->DC.ItemWidth;
2216 table->RowTextBaseline = ImMax(table->RowTextBaseline, window->DC.PrevLineTextBaseOffset);
2233float ImGui::TableCalcMaxColumnWidth(
const ImGuiTable* table,
int column_n)
2235 const ImGuiTableColumn* column = &table->Columns[column_n];
2236 float max_width = FLT_MAX;
2237 const float min_column_distance = table->MinColumnWidth + table->CellPaddingX * 2.0f + table->CellSpacingX1 + table->CellSpacingX2;
2238 if (table->Flags & ImGuiTableFlags_ScrollX)
2242 if (column->DisplayOrder < table->FreezeColumnsRequest)
2244 max_width = (table->InnerClipRect.Max.x - (table->FreezeColumnsRequest - column->DisplayOrder) * min_column_distance) - column->MinX;
2245 max_width = max_width - table->OuterPaddingX - table->CellPaddingX - table->CellSpacingX2;
2248 else if ((table->Flags & ImGuiTableFlags_NoKeepColumnsVisible) == 0)
2255 max_width = table->WorkRect.Max.x - (table->ColumnsEnabledCount - column->IndexWithinEnabledSet - 1) * min_column_distance - column->MinX;
2257 max_width -= table->CellSpacingX2;
2258 max_width -= table->CellPaddingX * 2.0f;
2259 max_width -= table->OuterPaddingX;
2265float ImGui::TableGetColumnWidthAuto(ImGuiTable* table, ImGuiTableColumn* column)
2267 const float content_width_body = ImMax(column->ContentMaxXFrozen, column->ContentMaxXUnfrozen) - column->WorkMinX;
2268 const float content_width_headers = column->ContentMaxXHeadersIdeal - column->WorkMinX;
2269 float width_auto = content_width_body;
2270 if (!(column->Flags & ImGuiTableColumnFlags_NoHeaderWidth))
2271 width_auto = ImMax(width_auto, content_width_headers);
2274 if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && column->InitStretchWeightOrWidth > 0.0f)
2275 if (!(table->Flags & ImGuiTableFlags_Resizable) || (column->Flags & ImGuiTableColumnFlags_NoResize))
2276 width_auto = column->InitStretchWeightOrWidth;
2278 return ImMax(width_auto, table->MinColumnWidth);
2282void ImGui::TableSetColumnWidth(
int column_n,
float width)
2285 ImGuiTable* table =
g.CurrentTable;
2286 IM_ASSERT(table != NULL && table->IsLayoutLocked ==
false);
2287 IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
2288 ImGuiTableColumn* column_0 = &table->Columns[column_n];
2289 float column_0_width = width;
2293 IM_ASSERT(table->MinColumnWidth > 0.0f);
2294 const float min_width = table->MinColumnWidth;
2295 const float max_width = ImMax(min_width, column_0->WidthMax);
2296 column_0_width = ImClamp(column_0_width, min_width, max_width);
2297 if (column_0->WidthGiven == column_0_width || column_0->WidthRequest == column_0_width)
2301 ImGuiTableColumn* column_1 = (column_0->NextEnabledColumn != -1) ? &table->Columns[column_0->NextEnabledColumn] : NULL;
2337 if (column_0->Flags & ImGuiTableColumnFlags_WidthFixed)
2338 if (!column_1 || table->LeftMostStretchedColumn == -1 || table->Columns[table->LeftMostStretchedColumn].DisplayOrder >= column_0->DisplayOrder)
2340 column_0->WidthRequest = column_0_width;
2341 table->IsSettingsDirty =
true;
2346 if (column_1 == NULL)
2347 column_1 = (column_0->PrevEnabledColumn != -1) ? &table->Columns[column_0->PrevEnabledColumn] : NULL;
2348 if (column_1 == NULL)
2353 float column_1_width = ImMax(column_1->WidthRequest - (column_0_width - column_0->WidthRequest), min_width);
2354 column_0_width = column_0->WidthRequest + column_1->WidthRequest - column_1_width;
2355 IM_ASSERT(column_0_width > 0.0f && column_1_width > 0.0f);
2356 column_0->WidthRequest = column_0_width;
2357 column_1->WidthRequest = column_1_width;
2358 if ((column_0->Flags | column_1->Flags) & ImGuiTableColumnFlags_WidthStretch)
2359 TableUpdateColumnsWeightFromWidth(table);
2360 table->IsSettingsDirty =
true;
2365void ImGui::TableSetColumnWidthAutoSingle(ImGuiTable* table,
int column_n)
2368 ImGuiTableColumn* column = &table->Columns[column_n];
2369 if (!column->IsEnabled)
2371 column->CannotSkipItemsQueue = (1 << 0);
2372 table->AutoFitSingleColumn = (ImGuiTableColumnIdx)column_n;
2375void ImGui::TableSetColumnWidthAutoAll(ImGuiTable* table)
2377 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2379 ImGuiTableColumn* column = &table->Columns[column_n];
2380 if (!column->IsEnabled && !(column->Flags & ImGuiTableColumnFlags_WidthStretch))
2382 column->CannotSkipItemsQueue = (1 << 0);
2383 column->AutoFitQueue = (1 << 1);
2387void ImGui::TableUpdateColumnsWeightFromWidth(ImGuiTable* table)
2389 IM_ASSERT(table->LeftMostStretchedColumn != -1 && table->RightMostStretchedColumn != -1);
2392 float visible_weight = 0.0f;
2393 float visible_width = 0.0f;
2394 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2396 ImGuiTableColumn* column = &table->Columns[column_n];
2397 if (!column->IsEnabled || !(column->Flags & ImGuiTableColumnFlags_WidthStretch))
2399 IM_ASSERT(column->StretchWeight > 0.0f);
2400 visible_weight += column->StretchWeight;
2401 visible_width += column->WidthRequest;
2403 IM_ASSERT(visible_weight > 0.0f && visible_width > 0.0f);
2406 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2408 ImGuiTableColumn* column = &table->Columns[column_n];
2409 if (!column->IsEnabled || !(column->Flags & ImGuiTableColumnFlags_WidthStretch))
2411 column->StretchWeight = (column->WidthRequest / visible_width) * visible_weight;
2412 IM_ASSERT(column->StretchWeight > 0.0f);
2429void ImGui::TablePushBackgroundChannel()
2432 ImGuiWindow* window =
g.CurrentWindow;
2433 ImGuiTable* table =
g.CurrentTable;
2436 table->HostBackupInnerClipRect = window->ClipRect;
2437 SetWindowClipRectBeforeSetChannel(window, table->Bg2ClipRectForDrawCmd);
2438 table->DrawSplitter->SetCurrentChannel(window->DrawList, table->Bg2DrawChannelCurrent);
2441void ImGui::TablePopBackgroundChannel()
2444 ImGuiWindow* window =
g.CurrentWindow;
2445 ImGuiTable* table =
g.CurrentTable;
2446 ImGuiTableColumn* column = &table->Columns[table->CurrentColumn];
2449 SetWindowClipRectBeforeSetChannel(window, table->HostBackupInnerClipRect);
2450 table->DrawSplitter->SetCurrentChannel(window->DrawList, column->DrawChannelCurrent);
2469void ImGui::TableSetupDrawChannels(ImGuiTable* table)
2471 const int freeze_row_multiplier = (table->FreezeRowsCount > 0) ? 2 : 1;
2472 const int channels_for_row = (table->Flags & ImGuiTableFlags_NoClip) ? 1 : table->ColumnsEnabledCount;
2473 const int channels_for_bg = 1 + 1 * freeze_row_multiplier;
2474 const int channels_for_dummy = (table->ColumnsEnabledCount < table->ColumnsCount || (memcmp(table->VisibleMaskByIndex, table->EnabledMaskByIndex, ImBitArrayGetStorageSizeInBytes(table->ColumnsCount)) != 0)) ? +1 : 0;
2475 const int channels_total = channels_for_bg + (channels_for_row * freeze_row_multiplier) + channels_for_dummy;
2476 table->DrawSplitter->Split(table->InnerWindow->DrawList, channels_total);
2477 table->DummyDrawChannel = (ImGuiTableDrawChannelIdx)((channels_for_dummy > 0) ? channels_total - 1 : -1);
2478 table->Bg2DrawChannelCurrent = TABLE_DRAW_CHANNEL_BG2_FROZEN;
2479 table->Bg2DrawChannelUnfrozen = (ImGuiTableDrawChannelIdx)((table->FreezeRowsCount > 0) ? 2 + channels_for_row : TABLE_DRAW_CHANNEL_BG2_FROZEN);
2481 int draw_channel_current = 2;
2482 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2484 ImGuiTableColumn* column = &table->Columns[column_n];
2485 if (column->IsVisibleX && column->IsVisibleY)
2487 column->DrawChannelFrozen = (ImGuiTableDrawChannelIdx)(draw_channel_current);
2488 column->DrawChannelUnfrozen = (ImGuiTableDrawChannelIdx)(draw_channel_current + (table->FreezeRowsCount > 0 ? channels_for_row + 1 : 0));
2489 if (!(table->Flags & ImGuiTableFlags_NoClip))
2490 draw_channel_current++;
2494 column->DrawChannelFrozen = column->DrawChannelUnfrozen = table->DummyDrawChannel;
2496 column->DrawChannelCurrent = column->DrawChannelFrozen;
2502 table->BgClipRect = table->InnerClipRect;
2503 table->Bg0ClipRectForDrawCmd = table->OuterWindow->ClipRect;
2504 table->Bg2ClipRectForDrawCmd = table->HostClipRect;
2505 IM_ASSERT(table->BgClipRect.Min.y <= table->BgClipRect.Max.y);
2537void ImGui::TableMergeDrawChannels(ImGuiTable* table)
2540 ImDrawListSplitter* splitter = table->DrawSplitter;
2541 const bool has_freeze_v = (table->FreezeRowsCount > 0);
2542 const bool has_freeze_h = (table->FreezeColumnsCount > 0);
2543 IM_ASSERT(splitter->_Current == 0);
2549 int ChannelsCount = 0;
2550 ImBitArrayPtr ChannelsMask = NULL;
2552 int merge_group_mask = 0x00;
2553 MergeGroup merge_groups[4];
2556 const int max_draw_channels = (4 + table->ColumnsCount * 2);
2557 const int size_for_masks_bitarrays_one = (int)ImBitArrayGetStorageSizeInBytes(max_draw_channels);
2558 g.TempBuffer.reserve(size_for_masks_bitarrays_one * 5);
2559 memset(
g.TempBuffer.Data, 0, size_for_masks_bitarrays_one * 5);
2560 for (
int n = 0; n < IM_ARRAYSIZE(merge_groups); n++)
2561 merge_groups[n].ChannelsMask = (ImBitArrayPtr)(
void*)(
g.TempBuffer.Data + (size_for_masks_bitarrays_one * n));
2562 ImBitArrayPtr remaining_mask = (ImBitArrayPtr)(
void*)(
g.TempBuffer.Data + (size_for_masks_bitarrays_one * 4));
2565 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2567 if (!IM_BITARRAY_TESTBIT(table->VisibleMaskByIndex, column_n))
2569 ImGuiTableColumn* column = &table->Columns[column_n];
2571 const int merge_group_sub_count = has_freeze_v ? 2 : 1;
2572 for (
int merge_group_sub_n = 0; merge_group_sub_n < merge_group_sub_count; merge_group_sub_n++)
2574 const int channel_no = (merge_group_sub_n == 0) ? column->DrawChannelFrozen : column->DrawChannelUnfrozen;
2577 ImDrawChannel* src_channel = &splitter->_Channels[channel_no];
2578 if (src_channel->_CmdBuffer.Size > 0 && src_channel->_CmdBuffer.back().ElemCount == 0 && src_channel->_CmdBuffer.back().UserCallback == NULL)
2579 src_channel->_CmdBuffer.pop_back();
2580 if (src_channel->_CmdBuffer.Size != 1)
2585 if (!(column->Flags & ImGuiTableColumnFlags_NoClip))
2587 float content_max_x;
2589 content_max_x = ImMax(column->ContentMaxXUnfrozen, column->ContentMaxXHeadersUsed);
2590 else if (merge_group_sub_n == 0)
2591 content_max_x = ImMax(column->ContentMaxXFrozen, column->ContentMaxXHeadersUsed);
2593 content_max_x = column->ContentMaxXUnfrozen;
2594 if (content_max_x > column->ClipRect.Max.x)
2598 const int merge_group_n = (has_freeze_h && column_n < table->FreezeColumnsCount ? 0 : 1) + (has_freeze_v && merge_group_sub_n == 0 ? 0 : 2);
2599 IM_ASSERT(channel_no < max_draw_channels);
2600 MergeGroup* merge_group = &merge_groups[merge_group_n];
2601 if (merge_group->ChannelsCount == 0)
2602 merge_group->ClipRect = ImRect(+FLT_MAX, +FLT_MAX, -FLT_MAX, -FLT_MAX);
2603 ImBitArraySetBit(merge_group->ChannelsMask, channel_no);
2604 merge_group->ChannelsCount++;
2605 merge_group->ClipRect.Add(src_channel->_CmdBuffer[0].ClipRect);
2606 merge_group_mask |= (1 << merge_group_n);
2611 column->DrawChannelCurrent = (ImGuiTableDrawChannelIdx)-1;
2617 for (
int merge_group_n = 0; merge_group_n < IM_ARRAYSIZE(merge_groups); merge_group_n++)
2619 MergeGroup* merge_group = &merge_groups[merge_group_n];
2620 if (merge_group->ChannelsCount == 0)
2623 ImFormatString(buf, 32,
"MG%d:%d", merge_group_n, merge_group->ChannelsCount);
2624 ImVec2 text_pos = merge_group->ClipRect.Min + ImVec2(4, 4);
2626 GetForegroundDrawList()->AddRectFilled(text_pos, text_pos + text_size, IM_COL32(0, 0, 0, 255));
2627 GetForegroundDrawList()->AddText(text_pos, IM_COL32(255, 255, 0, 255), buf, NULL);
2628 GetForegroundDrawList()->AddRect(merge_group->ClipRect.Min, merge_group->ClipRect.Max, IM_COL32(255, 255, 0, 255));
2633 if (merge_group_mask != 0)
2636 const int LEADING_DRAW_CHANNELS = 2;
2637 g.DrawChannelsTempMergeBuffer.resize(splitter->_Count - LEADING_DRAW_CHANNELS);
2638 ImDrawChannel* dst_tmp =
g.DrawChannelsTempMergeBuffer.Data;
2639 ImBitArraySetBitRange(remaining_mask, LEADING_DRAW_CHANNELS, splitter->_Count);
2640 ImBitArrayClearBit(remaining_mask, table->Bg2DrawChannelUnfrozen);
2641 IM_ASSERT(has_freeze_v ==
false || table->Bg2DrawChannelUnfrozen != TABLE_DRAW_CHANNEL_BG2_FROZEN);
2642 int remaining_count = splitter->_Count - (has_freeze_v ? LEADING_DRAW_CHANNELS + 1 : LEADING_DRAW_CHANNELS);
2644 ImRect host_rect = table->HostClipRect;
2645 for (
int merge_group_n = 0; merge_group_n < IM_ARRAYSIZE(merge_groups); merge_group_n++)
2647 if (
int merge_channels_count = merge_groups[merge_group_n].ChannelsCount)
2649 MergeGroup* merge_group = &merge_groups[merge_group_n];
2650 ImRect merge_clip_rect = merge_group->ClipRect;
2659 if ((merge_group_n & 1) == 0 || !has_freeze_h)
2660 merge_clip_rect.Min.x = ImMin(merge_clip_rect.Min.x, host_rect.Min.x);
2661 if ((merge_group_n & 2) == 0 || !has_freeze_v)
2662 merge_clip_rect.Min.y = ImMin(merge_clip_rect.Min.y, host_rect.Min.y);
2663 if ((merge_group_n & 1) != 0)
2664 merge_clip_rect.Max.x = ImMax(merge_clip_rect.Max.x, host_rect.Max.x);
2665 if ((merge_group_n & 2) != 0 && (table->Flags & ImGuiTableFlags_NoHostExtendY) == 0)
2666 merge_clip_rect.Max.y = ImMax(merge_clip_rect.Max.y, host_rect.Max.y);
2670 remaining_count -= merge_group->ChannelsCount;
2671 for (
int n = 0; n < (size_for_masks_bitarrays_one >> 2); n++)
2672 remaining_mask[n] &= ~merge_group->ChannelsMask[n];
2673 for (
int n = 0; n < splitter->_Count && merge_channels_count != 0; n++)
2676 if (!IM_BITARRAY_TESTBIT(merge_group->ChannelsMask, n))
2678 IM_BITARRAY_CLEARBIT(merge_group->ChannelsMask, n);
2679 merge_channels_count--;
2681 ImDrawChannel* channel = &splitter->_Channels[n];
2682 IM_ASSERT(channel->_CmdBuffer.Size == 1 && merge_clip_rect.Contains(ImRect(channel->_CmdBuffer[0].ClipRect)));
2683 channel->_CmdBuffer[0].ClipRect = merge_clip_rect.ToVec4();
2684 memcpy(dst_tmp++, channel,
sizeof(ImDrawChannel));
2689 if (merge_group_n == 1 && has_freeze_v)
2690 memcpy(dst_tmp++, &splitter->_Channels[table->Bg2DrawChannelUnfrozen],
sizeof(ImDrawChannel));
2694 for (
int n = 0; n < splitter->_Count && remaining_count != 0; n++)
2696 if (!IM_BITARRAY_TESTBIT(remaining_mask, n))
2698 ImDrawChannel* channel = &splitter->_Channels[n];
2699 memcpy(dst_tmp++, channel,
sizeof(ImDrawChannel));
2702 IM_ASSERT(dst_tmp ==
g.DrawChannelsTempMergeBuffer.Data +
g.DrawChannelsTempMergeBuffer.Size);
2703 memcpy(splitter->_Channels.Data + LEADING_DRAW_CHANNELS,
g.DrawChannelsTempMergeBuffer.Data, (splitter->_Count - LEADING_DRAW_CHANNELS) *
sizeof(ImDrawChannel));
2707static ImU32 TableGetColumnBorderCol(ImGuiTable* table,
int order_n,
int column_n)
2709 const bool is_hovered = (table->HoveredColumnBorder == column_n);
2710 const bool is_resized = (table->ResizedColumn == column_n) && (table->InstanceInteracted == table->InstanceCurrent);
2711 const bool is_frozen_separator = (table->FreezeColumnsCount == order_n + 1);
2712 if (is_resized || is_hovered)
2713 return ImGui::GetColorU32(is_resized ? ImGuiCol_SeparatorActive : ImGuiCol_SeparatorHovered);
2714 if (is_frozen_separator || (table->Flags & (ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_NoBordersInBodyUntilResize)))
2715 return table->BorderColorStrong;
2716 return table->BorderColorLight;
2720void ImGui::TableDrawBorders(ImGuiTable* table)
2722 ImGuiWindow* inner_window = table->InnerWindow;
2723 if (!table->OuterWindow->ClipRect.Overlaps(table->OuterRect))
2726 ImDrawList* inner_drawlist = inner_window->DrawList;
2727 table->DrawSplitter->SetCurrentChannel(inner_drawlist, TABLE_DRAW_CHANNEL_BG0);
2728 inner_drawlist->PushClipRect(table->Bg0ClipRectForDrawCmd.Min, table->Bg0ClipRectForDrawCmd.Max,
false);
2731 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
2732 const float border_size = TABLE_BORDER_SIZE;
2733 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);
2734 const float draw_y2_body = table->InnerRect.Max.y;
2735 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;
2736 if (table->Flags & ImGuiTableFlags_BordersInnerV)
2738 for (
int order_n = 0; order_n < table->ColumnsCount; order_n++)
2740 if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n))
2743 const int column_n = table->DisplayOrderToIndex[order_n];
2744 ImGuiTableColumn* column = &table->Columns[column_n];
2745 const bool is_hovered = (table->HoveredColumnBorder == column_n);
2746 const bool is_resized = (table->ResizedColumn == column_n) && (table->InstanceInteracted == table->InstanceCurrent);
2747 const bool is_resizable = (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_)) == 0;
2748 const bool is_frozen_separator = (table->FreezeColumnsCount == order_n + 1);
2749 if (column->MaxX > table->InnerClipRect.Max.x && !is_resized)
2753 if (column->NextEnabledColumn == -1 && !is_resizable)
2754 if ((table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame || (table->Flags & ImGuiTableFlags_NoHostExtendX))
2756 if (column->MaxX <= column->ClipRect.Min.x)
2761 float draw_y2 = (is_hovered || is_resized || is_frozen_separator || (table->Flags & (ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_NoBordersInBodyUntilResize)) == 0) ? draw_y2_body : draw_y2_head;
2762 if (draw_y2 > draw_y1)
2763 inner_drawlist->AddLine(ImVec2(column->MaxX, draw_y1), ImVec2(column->MaxX, draw_y2), TableGetColumnBorderCol(table, order_n, column_n), border_size);
2769 if (table->Flags & ImGuiTableFlags_BordersOuter)
2776 const ImRect outer_border = table->OuterRect;
2777 const ImU32 outer_col = table->BorderColorStrong;
2778 if ((table->Flags & ImGuiTableFlags_BordersOuter) == ImGuiTableFlags_BordersOuter)
2780 inner_drawlist->AddRect(outer_border.Min, outer_border.Max, outer_col, 0.0f, 0, border_size);
2782 else if (table->Flags & ImGuiTableFlags_BordersOuterV)
2784 inner_drawlist->AddLine(outer_border.Min, ImVec2(outer_border.Min.x, outer_border.Max.y), outer_col, border_size);
2785 inner_drawlist->AddLine(ImVec2(outer_border.Max.x, outer_border.Min.y), outer_border.Max, outer_col, border_size);
2787 else if (table->Flags & ImGuiTableFlags_BordersOuterH)
2789 inner_drawlist->AddLine(outer_border.Min, ImVec2(outer_border.Max.x, outer_border.Min.y), outer_col, border_size);
2790 inner_drawlist->AddLine(ImVec2(outer_border.Min.x, outer_border.Max.y), outer_border.Max, outer_col, border_size);
2793 if ((table->Flags & ImGuiTableFlags_BordersInnerH) && table->RowPosY2 < table->OuterRect.Max.y)
2796 const float border_y = table->RowPosY2;
2797 if (border_y >= table->BgClipRect.Min.y && border_y < table->BgClipRect.Max.y)
2798 inner_drawlist->AddLine(ImVec2(table->BorderX1, border_y), ImVec2(table->BorderX2, border_y), table->BorderColorLight, border_size);
2801 inner_drawlist->PopClipRect();
2820ImGuiTableSortSpecs* ImGui::TableGetSortSpecs()
2823 ImGuiTable* table =
g.CurrentTable;
2824 IM_ASSERT(table != NULL);
2826 if (!(table->Flags & ImGuiTableFlags_Sortable))
2830 if (!table->IsLayoutLocked)
2831 TableUpdateLayout(table);
2833 TableSortSpecsBuild(table);
2834 return &table->SortSpecs;
2837static inline ImGuiSortDirection TableGetColumnAvailSortDirection(ImGuiTableColumn* column,
int n)
2839 IM_ASSERT(n < column->SortDirectionsAvailCount);
2840 return (ImGuiSortDirection)((column->SortDirectionsAvailList >> (n << 1)) & 0x03);
2844void ImGui::TableFixColumnSortDirection(ImGuiTable* table, ImGuiTableColumn* column)
2846 if (column->SortOrder == -1 || (column->SortDirectionsAvailMask & (1 << column->SortDirection)) != 0)
2848 column->SortDirection = (ImU8)TableGetColumnAvailSortDirection(column, 0);
2849 table->IsSortSpecsDirty =
true;
2855IM_STATIC_ASSERT(ImGuiSortDirection_None == 0 && ImGuiSortDirection_Ascending == 1 && ImGuiSortDirection_Descending == 2);
2856ImGuiSortDirection ImGui::TableGetColumnNextSortDirection(ImGuiTableColumn* column)
2858 IM_ASSERT(column->SortDirectionsAvailCount > 0);
2859 if (column->SortOrder == -1)
2860 return TableGetColumnAvailSortDirection(column, 0);
2861 for (
int n = 0; n < 3; n++)
2862 if (column->SortDirection == TableGetColumnAvailSortDirection(column, n))
2863 return TableGetColumnAvailSortDirection(column, (n + 1) % column->SortDirectionsAvailCount);
2865 return ImGuiSortDirection_None;
2870void ImGui::TableSetColumnSortDirection(
int column_n, ImGuiSortDirection sort_direction,
bool append_to_sort_specs)
2873 ImGuiTable* table =
g.CurrentTable;
2875 if (!(table->Flags & ImGuiTableFlags_SortMulti))
2876 append_to_sort_specs =
false;
2877 if (!(table->Flags & ImGuiTableFlags_SortTristate))
2878 IM_ASSERT(sort_direction != ImGuiSortDirection_None);
2880 ImGuiTableColumnIdx sort_order_max = 0;
2881 if (append_to_sort_specs)
2882 for (
int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++)
2883 sort_order_max = ImMax(sort_order_max, table->Columns[other_column_n].SortOrder);
2885 ImGuiTableColumn* column = &table->Columns[column_n];
2886 column->SortDirection = (ImU8)sort_direction;
2887 if (column->SortDirection == ImGuiSortDirection_None)
2888 column->SortOrder = -1;
2889 else if (column->SortOrder == -1 || !append_to_sort_specs)
2890 column->SortOrder = append_to_sort_specs ? sort_order_max + 1 : 0;
2892 for (
int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++)
2894 ImGuiTableColumn* other_column = &table->Columns[other_column_n];
2895 if (other_column != column && !append_to_sort_specs)
2896 other_column->SortOrder = -1;
2897 TableFixColumnSortDirection(table, other_column);
2899 table->IsSettingsDirty =
true;
2900 table->IsSortSpecsDirty =
true;
2903void ImGui::TableSortSpecsSanitize(ImGuiTable* table)
2905 IM_ASSERT(table->Flags & ImGuiTableFlags_Sortable);
2908 int sort_order_count = 0;
2909 ImU64 sort_order_mask = 0x00;
2910 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2912 ImGuiTableColumn* column = &table->Columns[column_n];
2913 if (column->SortOrder != -1 && !column->IsEnabled)
2914 column->SortOrder = -1;
2915 if (column->SortOrder == -1)
2918 sort_order_mask |= ((ImU64)1 << column->SortOrder);
2919 IM_ASSERT(sort_order_count < (
int)
sizeof(sort_order_mask) * 8);
2922 const bool need_fix_linearize = ((ImU64)1 << sort_order_count) != (sort_order_mask + 1);
2923 const bool need_fix_single_sort_order = (sort_order_count > 1) && !(table->Flags & ImGuiTableFlags_SortMulti);
2924 if (need_fix_linearize || need_fix_single_sort_order)
2926 ImU64 fixed_mask = 0x00;
2927 for (
int sort_n = 0; sort_n < sort_order_count; sort_n++)
2931 int column_with_smallest_sort_order = -1;
2932 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2933 if ((fixed_mask & ((ImU64)1 << (ImU64)column_n)) == 0 && table->Columns[column_n].SortOrder != -1)
2934 if (column_with_smallest_sort_order == -1 || table->Columns[column_n].SortOrder < table->Columns[column_with_smallest_sort_order].SortOrder)
2935 column_with_smallest_sort_order = column_n;
2936 IM_ASSERT(column_with_smallest_sort_order != -1);
2937 fixed_mask |= ((ImU64)1 << column_with_smallest_sort_order);
2938 table->Columns[column_with_smallest_sort_order].SortOrder = (ImGuiTableColumnIdx)sort_n;
2941 if (need_fix_single_sort_order)
2943 sort_order_count = 1;
2944 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2945 if (column_n != column_with_smallest_sort_order)
2946 table->Columns[column_n].SortOrder = -1;
2953 if (sort_order_count == 0 && !(table->Flags & ImGuiTableFlags_SortTristate))
2954 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2956 ImGuiTableColumn* column = &table->Columns[column_n];
2957 if (column->IsEnabled && !(column->Flags & ImGuiTableColumnFlags_NoSort))
2959 sort_order_count = 1;
2960 column->SortOrder = 0;
2961 column->SortDirection = (ImU8)TableGetColumnAvailSortDirection(column, 0);
2966 table->SortSpecsCount = (ImGuiTableColumnIdx)sort_order_count;
2969void ImGui::TableSortSpecsBuild(ImGuiTable* table)
2971 bool dirty = table->IsSortSpecsDirty;
2974 TableSortSpecsSanitize(table);
2975 table->SortSpecsMulti.resize(table->SortSpecsCount <= 1 ? 0 : table->SortSpecsCount);
2976 table->SortSpecs.SpecsDirty =
true;
2977 table->IsSortSpecsDirty =
false;
2982 ImGuiTableColumnSortSpecs* sort_specs = (table->SortSpecsCount == 0) ? NULL : (table->SortSpecsCount == 1) ? &table->SortSpecsSingle : table->SortSpecsMulti.Data;
2983 if (dirty && sort_specs != NULL)
2984 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
2986 ImGuiTableColumn* column = &table->Columns[column_n];
2987 if (column->SortOrder == -1)
2989 IM_ASSERT(column->SortOrder < table->SortSpecsCount);
2990 ImGuiTableColumnSortSpecs* sort_spec = &sort_specs[column->SortOrder];
2991 sort_spec->ColumnUserID = column->UserID;
2992 sort_spec->ColumnIndex = (ImGuiTableColumnIdx)column_n;
2993 sort_spec->SortOrder = (ImGuiTableColumnIdx)column->SortOrder;
2994 sort_spec->SortDirection = (ImGuiSortDirection)column->SortDirection;
2997 table->SortSpecs.Specs = sort_specs;
2998 table->SortSpecs.SpecsCount = table->SortSpecsCount;
3012float ImGui::TableGetHeaderRowHeight()
3019 ImGuiTable* table =
g.CurrentTable;
3020 float row_height =
g.FontSize;
3021 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
3022 if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
3023 if ((table->Columns[column_n].Flags & ImGuiTableColumnFlags_NoHeaderLabel) == 0)
3024 row_height = ImMax(row_height,
CalcTextSize(TableGetColumnName(table, column_n)).y);
3025 return row_height +
g.Style.CellPadding.y * 2.0f;
3028float ImGui::TableGetHeaderAngledMaxLabelWidth()
3031 ImGuiTable* table =
g.CurrentTable;
3033 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
3034 if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
3035 if (table->Columns[column_n].Flags & ImGuiTableColumnFlags_AngledHeader)
3036 width = ImMax(width,
CalcTextSize(TableGetColumnName(table, column_n), NULL,
true).x);
3037 return width +
g.Style.CellPadding.y * 2.0f;
3047void ImGui::TableHeadersRow()
3050 ImGuiTable* table =
g.CurrentTable;
3053 IM_ASSERT_USER_ERROR(table != NULL,
"Call should only be done while in BeginTable() scope!");
3059 if (!table->IsLayoutLocked)
3060 TableUpdateLayout(table);
3063 const float row_height = TableGetHeaderRowHeight();
3064 TableNextRow(ImGuiTableRowFlags_Headers, row_height);
3065 const float row_y1 = GetCursorScreenPos().y;
3066 if (table->HostSkipItems)
3069 const int columns_count = TableGetColumnCount();
3070 for (
int column_n = 0; column_n < columns_count; column_n++)
3072 if (!TableSetColumnIndex(column_n))
3076 const char* name = (TableGetColumnFlags(column_n) & ImGuiTableColumnFlags_NoHeaderLabel) ?
"" : TableGetColumnName(column_n);
3083 ImVec2 mouse_pos = ImGui::GetMousePos();
3084 if (IsMouseReleased(1) && TableGetHoveredColumn() == columns_count)
3085 if (mouse_pos.y >= row_y1 && mouse_pos.y < row_y1 + row_height)
3086 TableOpenContextMenu(columns_count);
3092void ImGui::TableHeader(
const char* label)
3095 ImGuiWindow* window =
g.CurrentWindow;
3096 if (window->SkipItems)
3099 ImGuiTable* table =
g.CurrentTable;
3102 IM_ASSERT_USER_ERROR(table != NULL,
"Call should only be done while in BeginTable() scope!");
3106 IM_ASSERT(table->CurrentColumn != -1);
3107 const int column_n = table->CurrentColumn;
3108 ImGuiTableColumn* column = &table->Columns[column_n];
3113 const char* label_end = FindRenderedTextEnd(label);
3114 ImVec2 label_size =
CalcTextSize(label, label_end,
true);
3115 ImVec2 label_pos = window->DC.CursorPos;
3119 ImRect cell_r = TableGetCellBgRect(table, column_n);
3120 float label_height = ImMax(label_size.y, table->RowMinHeight - table->RowCellPaddingY * 2.0f);
3123 float w_arrow = 0.0f;
3124 float w_sort_text = 0.0f;
3125 bool sort_arrow =
false;
3126 char sort_order_suf[4] =
"";
3127 const float ARROW_SCALE = 0.65f;
3128 if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort))
3130 w_arrow = ImTrunc(
g.FontSize * ARROW_SCALE +
g.Style.FramePadding.x);
3131 if (column->SortOrder != -1)
3133 if (column->SortOrder > 0)
3135 ImFormatString(sort_order_suf, IM_ARRAYSIZE(sort_order_suf),
"%d", column->SortOrder + 1);
3136 w_sort_text =
g.Style.ItemInnerSpacing.x +
CalcTextSize(sort_order_suf).x;
3141 float max_pos_x = label_pos.x + label_size.x + w_sort_text + w_arrow;
3142 column->ContentMaxXHeadersUsed = ImMax(column->ContentMaxXHeadersUsed, sort_arrow ? cell_r.Max.x : ImMin(max_pos_x, cell_r.Max.x));
3143 column->ContentMaxXHeadersIdeal = ImMax(column->ContentMaxXHeadersIdeal, max_pos_x);
3146 ImGuiID
id = window->GetID(label);
3147 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));
3148 ItemSize(ImVec2(0.0f, label_height));
3149 if (!ItemAdd(bb,
id))
3156 const bool highlight = (table->HighlightColumnHeader == column_n);
3158 bool pressed = ButtonBehavior(bb,
id, &hovered, &held, ImGuiButtonFlags_AllowOverlap);
3159 if (held || hovered || highlight)
3161 const ImU32 col = GetColorU32(held ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
3163 TableSetBgColor(ImGuiTableBgTarget_CellBg, col, table->CurrentColumn);
3168 if ((table->RowFlags & ImGuiTableRowFlags_Headers) == 0)
3169 TableSetBgColor(ImGuiTableBgTarget_CellBg, GetColorU32(ImGuiCol_TableHeaderBg), table->CurrentColumn);
3171 RenderNavCursor(bb,
id, ImGuiNavRenderCursorFlags_Compact | ImGuiNavRenderCursorFlags_NoRounding);
3173 table->HeldHeaderColumn = (ImGuiTableColumnIdx)column_n;
3174 window->DC.CursorPos.y -=
g.Style.ItemSpacing.y * 0.5f;
3178 if (held && (table->Flags & ImGuiTableFlags_Reorderable) && IsMouseDragging(0) && !
g.DragDropActive)
3181 table->ReorderColumn = (ImGuiTableColumnIdx)column_n;
3182 table->InstanceInteracted = table->InstanceCurrent;
3185 if (
g.IO.MouseDelta.x < 0.0f &&
g.IO.MousePos.x < cell_r.Min.x)
3186 if (ImGuiTableColumn* prev_column = (column->PrevEnabledColumn != -1) ? &table->Columns[column->PrevEnabledColumn] : NULL)
3187 if (!((column->Flags | prev_column->Flags) & ImGuiTableColumnFlags_NoReorder))
3188 if ((column->IndexWithinEnabledSet < table->FreezeColumnsRequest) == (prev_column->IndexWithinEnabledSet < table->FreezeColumnsRequest))
3189 table->ReorderColumnDir = -1;
3190 if (
g.IO.MouseDelta.x > 0.0f &&
g.IO.MousePos.x > cell_r.Max.x)
3191 if (ImGuiTableColumn* next_column = (column->NextEnabledColumn != -1) ? &table->Columns[column->NextEnabledColumn] : NULL)
3192 if (!((column->Flags | next_column->Flags) & ImGuiTableColumnFlags_NoReorder))
3193 if ((column->IndexWithinEnabledSet < table->FreezeColumnsRequest) == (next_column->IndexWithinEnabledSet < table->FreezeColumnsRequest))
3194 table->ReorderColumnDir = +1;
3198 const float ellipsis_max = ImMax(cell_r.Max.x - w_arrow - w_sort_text, label_pos.x);
3199 if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort))
3201 if (column->SortOrder != -1)
3203 float x = ImMax(cell_r.Min.x, cell_r.Max.x - w_arrow - w_sort_text);
3204 float y = label_pos.y;
3205 if (column->SortOrder > 0)
3207 PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_Text, 0.70f));
3208 RenderText(ImVec2(x +
g.Style.ItemInnerSpacing.x, y), sort_order_suf);
3212 RenderArrow(window->DrawList, ImVec2(x, y), GetColorU32(ImGuiCol_Text), column->SortDirection == ImGuiSortDirection_Ascending ? ImGuiDir_Up : ImGuiDir_Down, ARROW_SCALE);
3216 if (pressed && table->ReorderColumn != column_n)
3218 ImGuiSortDirection sort_direction = TableGetColumnNextSortDirection(column);
3219 TableSetColumnSortDirection(column_n, sort_direction,
g.IO.KeyShift);
3226 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);
3228 const bool text_clipped = label_size.x > (ellipsis_max - label_pos.x);
3229 if (text_clipped && hovered &&
g.ActiveId == 0)
3230 SetItemTooltip(
"%.*s", (
int)(label_end - label), label);
3233 if (IsMouseReleased(1) && IsItemHovered())
3234 TableOpenContextMenu(column_n);
3239void ImGui::TableAngledHeadersRow()
3242 ImGuiTable* table =
g.CurrentTable;
3243 ImGuiTableTempData* temp_data = table->TempData;
3244 temp_data->AngledHeadersRequests.resize(0);
3245 temp_data->AngledHeadersRequests.reserve(table->ColumnsEnabledCount);
3248 const ImGuiID row_id = GetID(
"##AngledHeaders");
3249 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
3250 int highlight_column_n = table->HighlightColumnHeader;
3251 if (highlight_column_n == -1 && table->HoveredColumnBody != -1)
3252 if (table_instance->HoveredRowLast == 0 && table->HoveredColumnBorder == -1 && (
g.ActiveId == 0 ||
g.ActiveId == row_id || (table->IsActiveIdInTable ||
g.DragDropActive)))
3253 highlight_column_n = table->HoveredColumnBody;
3256 ImU32 col_header_bg = GetColorU32(ImGuiCol_TableHeaderBg);
3257 ImU32 col_text = GetColorU32(ImGuiCol_Text);
3258 for (
int order_n = 0; order_n < table->ColumnsCount; order_n++)
3259 if (IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n))
3261 const int column_n = table->DisplayOrderToIndex[order_n];
3262 ImGuiTableColumn* column = &table->Columns[column_n];
3263 if ((column->Flags & ImGuiTableColumnFlags_AngledHeader) == 0)
3265 ImGuiTableHeaderData request = { (ImGuiTableColumnIdx)column_n, col_text, col_header_bg, (column_n == highlight_column_n) ? GetColorU32(ImGuiCol_Header) : 0 };
3266 temp_data->AngledHeadersRequests.push_back(request);
3270 TableAngledHeadersRowEx(row_id,
g.Style.TableAngledHeadersAngle, 0.0f, temp_data->AngledHeadersRequests.Data, temp_data->AngledHeadersRequests.Size);
3274void ImGui::TableAngledHeadersRowEx(ImGuiID row_id,
float angle,
float max_label_width,
const ImGuiTableHeaderData* data,
int data_count)
3277 ImGuiTable* table =
g.CurrentTable;
3278 ImGuiWindow* window =
g.CurrentWindow;
3279 ImDrawList* draw_list = window->DrawList;
3282 IM_ASSERT_USER_ERROR(table != NULL,
"Call should only be done while in BeginTable() scope!");
3285 IM_ASSERT(table->CurrentRow == -1 &&
"Must be first row");
3287 if (max_label_width == 0.0f)
3288 max_label_width = TableGetHeaderAngledMaxLabelWidth();
3291 const bool flip_label = (angle < 0.0f);
3292 angle -= IM_PI * 0.5f;
3293 const float cos_a = ImCos(angle);
3294 const float sin_a = ImSin(angle);
3295 const float label_cos_a = flip_label ? ImCos(angle + IM_PI) : cos_a;
3296 const float label_sin_a = flip_label ? ImSin(angle + IM_PI) : sin_a;
3297 const ImVec2 unit_right = ImVec2(cos_a, sin_a);
3301 const float header_height =
g.FontSize +
g.Style.CellPadding.x * 2.0f;
3302 const float row_height = ImTrunc(ImFabs(ImRotate(ImVec2(max_label_width, flip_label ? +header_height : -header_height), cos_a, sin_a).y));
3303 table->AngledHeadersHeight = row_height;
3304 table->AngledHeadersSlope = (sin_a != 0.0f) ? (cos_a / sin_a) : 0.0f;
3305 const ImVec2 header_angled_vector = unit_right * (row_height / -sin_a);
3308 TableNextRow(ImGuiTableRowFlags_Headers, row_height);
3310 const ImRect row_r(table->WorkRect.Min.x, table->BgClipRect.Min.y, table->WorkRect.Max.x, table->RowPosY2);
3311 table->DrawSplitter->SetCurrentChannel(draw_list, TABLE_DRAW_CHANNEL_BG0);
3312 float clip_rect_min_x = table->BgClipRect.Min.x;
3313 if (table->FreezeColumnsCount > 0)
3314 clip_rect_min_x = ImMax(clip_rect_min_x, table->Columns[table->FreezeColumnsCount - 1].MaxX);
3315 TableSetBgColor(ImGuiTableBgTarget_RowBg0, 0);
3316 PushClipRect(table->BgClipRect.Min, table->BgClipRect.Max,
false);
3317 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));
3318 PushClipRect(ImVec2(clip_rect_min_x, table->BgClipRect.Min.y), table->BgClipRect.Max,
true);
3320 ButtonBehavior(row_r, row_id, NULL, NULL);
3321 KeepAliveID(row_id);
3323 const float ascent_scaled =
g.Font->Ascent *
g.FontScale;
3324 const float line_off_for_ascent_x = (ImMax((
g.FontSize - ascent_scaled) * 0.5f, 0.0f) / -sin_a) * (flip_label ? -1.0f : 1.0f);
3325 const ImVec2 padding =
g.Style.CellPadding;
3326 const ImVec2 align =
g.Style.TableAngledHeadersTextAlign;
3329 float max_x = -FLT_MAX;
3330 for (
int pass = 0; pass < 2; pass++)
3331 for (
int order_n = 0; order_n < data_count; order_n++)
3333 const ImGuiTableHeaderData* request = &data[order_n];
3334 const int column_n = request->Index;
3335 ImGuiTableColumn* column = &table->Columns[column_n];
3338 bg_shape[0] = ImVec2(column->MaxX, row_r.Max.y);
3339 bg_shape[1] = ImVec2(column->MinX, row_r.Max.y);
3340 bg_shape[2] = bg_shape[1] + header_angled_vector;
3341 bg_shape[3] = bg_shape[0] + header_angled_vector;
3345 draw_list->AddQuadFilled(bg_shape[0], bg_shape[1], bg_shape[2], bg_shape[3], request->BgColor0);
3346 draw_list->AddQuadFilled(bg_shape[0], bg_shape[1], bg_shape[2], bg_shape[3], request->BgColor1);
3347 max_x = ImMax(max_x, bg_shape[3].x);
3352 const char* label_name = TableGetColumnName(table, column_n);
3353 const char* label_name_end = FindRenderedTextEnd(label_name);
3354 const float line_off_step_x = (
g.FontSize / -sin_a);
3358 float line_off_curr_x = flip_label ? (label_lines - 1) * line_off_step_x : 0.0f;
3359 float line_off_for_align_x = ImMax((((column->MaxX - column->MinX) - padding.x * 2.0f) - (label_lines * line_off_step_x)), 0.0f) * align.x;
3360 line_off_curr_x += line_off_for_align_x - line_off_for_ascent_x;
3363 column->ContentMaxXHeadersUsed = column->ContentMaxXHeadersIdeal = column->WorkMinX + ImCeil(label_lines * line_off_step_x - line_off_for_align_x);
3365 while (label_name < label_name_end)
3367 const char* label_name_eol = strchr(label_name,
'\n');
3368 if (label_name_eol == NULL)
3369 label_name_eol = label_name_end;
3372 ImVec2 label_size =
CalcTextSize(label_name, label_name_eol);
3373 float clip_width = max_label_width - padding.y;
3374 float clip_height = ImMin(label_size.y, column->ClipRect.Max.x - column->WorkMinX - line_off_curr_x);
3375 ImRect clip_r(window->ClipRect.Min, window->ClipRect.Min + ImVec2(clip_width, clip_height));
3376 int vtx_idx_begin = draw_list->_VtxCurrentIdx;
3377 PushStyleColor(ImGuiCol_Text, request->TextColor);
3378 RenderTextEllipsis(draw_list, clip_r.Min, clip_r.Max, clip_r.Max.x, clip_r.Max.x, label_name, label_name_eol, &label_size);
3380 int vtx_idx_end = draw_list->_VtxCurrentIdx;
3383 const float available_space = ImMax(clip_width - label_size.x + ImAbs(padding.x * cos_a) * 2.0f - ImAbs(padding.y * sin_a) * 2.0f, 0.0f);
3384 const float vertical_offset = available_space * align.y * (flip_label ? -1.0f : 1.0f);
3387 ImVec2 pivot_in = ImVec2(window->ClipRect.Min.x - vertical_offset, window->ClipRect.Min.y + label_size.y);
3388 ImVec2 pivot_out = ImVec2(column->WorkMinX, row_r.Max.y);
3389 line_off_curr_x += flip_label ? -line_off_step_x : line_off_step_x;
3390 pivot_out += unit_right * padding.y;
3392 pivot_out += unit_right * (clip_width - ImMax(0.0f, clip_width - label_size.x));
3393 pivot_out.x += flip_label ? line_off_curr_x + line_off_step_x : line_off_curr_x;
3394 ShadeVertsTransformPos(draw_list, vtx_idx_begin, vtx_idx_end, pivot_in, label_cos_a, label_sin_a, pivot_out);
3397 label_name = label_name_eol + 1;
3403 draw_list->AddLine(bg_shape[0], bg_shape[3], TableGetColumnBorderCol(table, order_n, column_n));
3408 table->TempData->AngledHeadersExtraWidth = ImMax(0.0f, max_x - table->Columns[table->RightMostEnabledColumn].MaxX);
3420void ImGui::TableOpenContextMenu(
int column_n)
3423 ImGuiTable* table =
g.CurrentTable;
3424 if (column_n == -1 && table->CurrentColumn != -1)
3425 column_n = table->CurrentColumn;
3426 if (column_n == table->ColumnsCount)
3428 IM_ASSERT(column_n >= -1 && column_n < table->ColumnsCount);
3429 if (table->Flags & (ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable))
3431 table->IsContextPopupOpen =
true;
3432 table->ContextPopupColumn = (ImGuiTableColumnIdx)column_n;
3433 table->InstanceInteracted = table->InstanceCurrent;
3434 const ImGuiID context_menu_id =
ImHashStr(
"##ContextMenu", 0, table->ID);
3435 OpenPopupEx(context_menu_id, ImGuiPopupFlags_None);
3439bool ImGui::TableBeginContextMenuPopup(ImGuiTable* table)
3441 if (!table->IsContextPopupOpen || table->InstanceCurrent != table->InstanceInteracted)
3443 const ImGuiID context_menu_id =
ImHashStr(
"##ContextMenu", 0, table->ID);
3444 if (BeginPopupEx(context_menu_id, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings))
3446 table->IsContextPopupOpen =
false;
3458void ImGui::TableDrawDefaultContextMenu(ImGuiTable* table, ImGuiTableFlags flags_for_section_to_display)
3461 ImGuiWindow* window =
g.CurrentWindow;
3462 if (window->SkipItems)
3465 bool want_separator =
false;
3466 const int column_n = (table->ContextPopupColumn >= 0 && table->ContextPopupColumn < table->ColumnsCount) ? table->ContextPopupColumn : -1;
3467 ImGuiTableColumn* column = (column_n != -1) ? &table->Columns[column_n] : NULL;
3470 if (flags_for_section_to_display & ImGuiTableFlags_Resizable)
3474 const bool can_resize = !(column->Flags & ImGuiTableColumnFlags_NoResize) && column->IsEnabled;
3475 if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableSizeOne), NULL,
false, can_resize))
3476 TableSetColumnWidthAutoSingle(table, column_n);
3479 const char* size_all_desc;
3480 if (table->ColumnsEnabledFixedCount == table->ColumnsEnabledCount && (table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame)
3481 size_all_desc = LocalizeGetMsg(ImGuiLocKey_TableSizeAllFit);
3483 size_all_desc = LocalizeGetMsg(ImGuiLocKey_TableSizeAllDefault);
3484 if (MenuItem(size_all_desc, NULL))
3485 TableSetColumnWidthAutoAll(table);
3486 want_separator =
true;
3490 if (flags_for_section_to_display & ImGuiTableFlags_Reorderable)
3492 if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetOrder), NULL,
false, !table->IsDefaultDisplayOrder))
3493 table->IsResetDisplayOrderRequest =
true;
3494 want_separator =
true;
3504 if ((flags_for_section_to_display & ImGuiTableFlags_Sortable) && column != NULL && (column->Flags & ImGuiTableColumnFlags_NoSort) == 0)
3508 want_separator =
true;
3510 bool append_to_sort_specs =
g.IO.KeyShift;
3511 if (MenuItem(
"Sort in Ascending Order", NULL, column->SortOrder != -1 && column->SortDirection == ImGuiSortDirection_Ascending, (column->Flags & ImGuiTableColumnFlags_NoSortAscending) == 0))
3512 TableSetColumnSortDirection(table, column_n, ImGuiSortDirection_Ascending, append_to_sort_specs);
3513 if (MenuItem(
"Sort in Descending Order", NULL, column->SortOrder != -1 && column->SortDirection == ImGuiSortDirection_Descending, (column->Flags & ImGuiTableColumnFlags_NoSortDescending) == 0))
3514 TableSetColumnSortDirection(table, column_n, ImGuiSortDirection_Descending, append_to_sort_specs);
3519 if (flags_for_section_to_display & ImGuiTableFlags_Hideable)
3523 want_separator =
true;
3525 PushItemFlag(ImGuiItemFlags_AutoClosePopups,
false);
3526 for (
int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++)
3528 ImGuiTableColumn* other_column = &table->Columns[other_column_n];
3529 if (other_column->Flags & ImGuiTableColumnFlags_Disabled)
3532 const char* name = TableGetColumnName(table, other_column_n);
3533 if (name == NULL || name[0] == 0)
3537 bool menu_item_active = (other_column->Flags & ImGuiTableColumnFlags_NoHide) ?
false : true;
3538 if (other_column->IsUserEnabled && table->ColumnsEnabledCount <= 1)
3539 menu_item_active =
false;
3540 if (MenuItem(name, NULL, other_column->IsUserEnabled, menu_item_active))
3541 other_column->IsUserEnabledNextFrame = !other_column->IsUserEnabled;
3574static void TableSettingsInit(ImGuiTableSettings* settings, ImGuiID
id,
int columns_count,
int columns_count_max)
3576 IM_PLACEMENT_NEW(settings) ImGuiTableSettings();
3577 ImGuiTableColumnSettings* settings_column = settings->GetColumnSettings();
3578 for (
int n = 0; n < columns_count_max; n++, settings_column++)
3579 IM_PLACEMENT_NEW(settings_column) ImGuiTableColumnSettings();
3581 settings->ColumnsCount = (ImGuiTableColumnIdx)columns_count;
3582 settings->ColumnsCountMax = (ImGuiTableColumnIdx)columns_count_max;
3583 settings->WantApply =
true;
3586static size_t TableSettingsCalcChunkSize(
int columns_count)
3588 return sizeof(ImGuiTableSettings) + (
size_t)columns_count *
sizeof(ImGuiTableColumnSettings);
3591ImGuiTableSettings* ImGui::TableSettingsCreate(ImGuiID
id,
int columns_count)
3594 ImGuiTableSettings* settings =
g.SettingsTables.alloc_chunk(TableSettingsCalcChunkSize(columns_count));
3595 TableSettingsInit(settings,
id, columns_count, columns_count);
3600ImGuiTableSettings* ImGui::TableSettingsFindByID(ImGuiID
id)
3604 for (ImGuiTableSettings* settings =
g.SettingsTables.begin(); settings != NULL; settings =
g.SettingsTables.next_chunk(settings))
3605 if (settings->ID ==
id)
3611ImGuiTableSettings* ImGui::TableGetBoundSettings(ImGuiTable* table)
3613 if (table->SettingsOffset != -1)
3616 ImGuiTableSettings* settings =
g.SettingsTables.ptr_from_offset(table->SettingsOffset);
3617 IM_ASSERT(settings->ID == table->ID);
3618 if (settings->ColumnsCountMax >= table->ColumnsCount)
3626void ImGui::TableResetSettings(ImGuiTable* table)
3628 table->IsInitializing = table->IsSettingsDirty =
true;
3629 table->IsResetAllRequest =
false;
3630 table->IsSettingsRequestLoad =
false;
3631 table->SettingsLoadedFlags = ImGuiTableFlags_None;
3634void ImGui::TableSaveSettings(ImGuiTable* table)
3636 table->IsSettingsDirty =
false;
3637 if (table->Flags & ImGuiTableFlags_NoSavedSettings)
3642 ImGuiTableSettings* settings = TableGetBoundSettings(table);
3643 if (settings == NULL)
3645 settings = TableSettingsCreate(table->ID, table->ColumnsCount);
3646 table->SettingsOffset =
g.SettingsTables.offset_from_ptr(settings);
3648 settings->ColumnsCount = (ImGuiTableColumnIdx)table->ColumnsCount;
3651 IM_ASSERT(settings->ID == table->ID);
3652 IM_ASSERT(settings->ColumnsCount == table->ColumnsCount && settings->ColumnsCountMax >= settings->ColumnsCount);
3653 ImGuiTableColumn* column = table->Columns.Data;
3654 ImGuiTableColumnSettings* column_settings = settings->GetColumnSettings();
3656 bool save_ref_scale =
false;
3657 settings->SaveFlags = ImGuiTableFlags_None;
3658 for (
int n = 0; n < table->ColumnsCount; n++, column++, column_settings++)
3660 const float width_or_weight = (column->Flags & ImGuiTableColumnFlags_WidthStretch) ? column->StretchWeight : column->WidthRequest;
3661 column_settings->WidthOrWeight = width_or_weight;
3662 column_settings->Index = (ImGuiTableColumnIdx)n;
3663 column_settings->DisplayOrder = column->DisplayOrder;
3664 column_settings->SortOrder = column->SortOrder;
3665 column_settings->SortDirection = column->SortDirection;
3666 column_settings->IsEnabled = column->IsUserEnabled;
3667 column_settings->IsStretch = (column->Flags & ImGuiTableColumnFlags_WidthStretch) ? 1 : 0;
3668 if ((column->Flags & ImGuiTableColumnFlags_WidthStretch) == 0)
3669 save_ref_scale =
true;
3674 if (width_or_weight != column->InitStretchWeightOrWidth)
3675 settings->SaveFlags |= ImGuiTableFlags_Resizable;
3676 if (column->DisplayOrder != n)
3677 settings->SaveFlags |= ImGuiTableFlags_Reorderable;
3678 if (column->SortOrder != -1)
3679 settings->SaveFlags |= ImGuiTableFlags_Sortable;
3680 if (column->IsUserEnabled != ((column->Flags & ImGuiTableColumnFlags_DefaultHide) == 0))
3681 settings->SaveFlags |= ImGuiTableFlags_Hideable;
3683 settings->SaveFlags &= table->Flags;
3684 settings->RefScale = save_ref_scale ? table->RefScale : 0.0f;
3686 MarkIniSettingsDirty();
3689void ImGui::TableLoadSettings(ImGuiTable* table)
3692 table->IsSettingsRequestLoad =
false;
3693 if (table->Flags & ImGuiTableFlags_NoSavedSettings)
3697 ImGuiTableSettings* settings;
3698 if (table->SettingsOffset == -1)
3700 settings = TableSettingsFindByID(table->ID);
3701 if (settings == NULL)
3703 if (settings->ColumnsCount != table->ColumnsCount)
3704 table->IsSettingsDirty =
true;
3705 table->SettingsOffset =
g.SettingsTables.offset_from_ptr(settings);
3709 settings = TableGetBoundSettings(table);
3712 table->SettingsLoadedFlags = settings->SaveFlags;
3713 table->RefScale = settings->RefScale;
3716 ImGuiTableColumnSettings* column_settings = settings->GetColumnSettings();
3717 ImU64 display_order_mask = 0;
3718 for (
int data_n = 0; data_n < settings->ColumnsCount; data_n++, column_settings++)
3720 int column_n = column_settings->Index;
3721 if (column_n < 0 || column_n >= table->ColumnsCount)
3724 ImGuiTableColumn* column = &table->Columns[column_n];
3725 if (settings->SaveFlags & ImGuiTableFlags_Resizable)
3727 if (column_settings->IsStretch)
3728 column->StretchWeight = column_settings->WidthOrWeight;
3730 column->WidthRequest = column_settings->WidthOrWeight;
3731 column->AutoFitQueue = 0x00;
3733 if (settings->SaveFlags & ImGuiTableFlags_Reorderable)
3734 column->DisplayOrder = column_settings->DisplayOrder;
3736 column->DisplayOrder = (ImGuiTableColumnIdx)column_n;
3737 display_order_mask |= (ImU64)1 << column->DisplayOrder;
3738 column->IsUserEnabled = column->IsUserEnabledNextFrame = column_settings->IsEnabled;
3739 column->SortOrder = column_settings->SortOrder;
3740 column->SortDirection = column_settings->SortDirection;
3744 const ImU64 expected_display_order_mask = (settings->ColumnsCount == 64) ? ~0 : ((ImU64)1 << settings->ColumnsCount) - 1;
3745 if (display_order_mask != expected_display_order_mask)
3746 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
3747 table->Columns[column_n].DisplayOrder = (ImGuiTableColumnIdx)column_n;
3750 for (
int column_n = 0; column_n < table->ColumnsCount; column_n++)
3751 table->DisplayOrderToIndex[table->Columns[column_n].DisplayOrder] = (ImGuiTableColumnIdx)column_n;
3754static void TableSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
3756 ImGuiContext&
g = *ctx;
3757 for (
int i = 0; i !=
g.Tables.GetMapSize(); i++)
3758 if (ImGuiTable* table =
g.Tables.TryGetMapData(i))
3759 table->SettingsOffset = -1;
3760 g.SettingsTables.clear();
3764static void TableSettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
3766 ImGuiContext&
g = *ctx;
3767 for (
int i = 0; i !=
g.Tables.GetMapSize(); i++)
3768 if (ImGuiTable* table =
g.Tables.TryGetMapData(i))
3770 table->IsSettingsRequestLoad =
true;
3771 table->SettingsOffset = -1;
3775static void* TableSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*,
const char* name)
3778 int columns_count = 0;
3779 if (sscanf(name,
"0x%08X,%d", &
id, &columns_count) < 2)
3782 if (ImGuiTableSettings* settings = ImGui::TableSettingsFindByID(
id))
3784 if (settings->ColumnsCountMax >= columns_count)
3786 TableSettingsInit(settings,
id, columns_count, settings->ColumnsCountMax);
3791 return ImGui::TableSettingsCreate(
id, columns_count);
3794static void TableSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*,
void* entry,
const char* line)
3797 ImGuiTableSettings* settings = (ImGuiTableSettings*)entry;
3799 int column_n = 0, r = 0, n = 0;
3801 if (sscanf(line,
"RefScale=%f", &f) == 1) { settings->RefScale = f;
return; }
3803 if (sscanf(line,
"Column %d%n", &column_n, &r) == 1)
3805 if (column_n < 0 || column_n >= settings->ColumnsCount)
3809 ImGuiTableColumnSettings* column = settings->GetColumnSettings() + column_n;
3810 column->Index = (ImGuiTableColumnIdx)column_n;
3811 if (sscanf(line,
"UserID=0x%08X%n", (ImU32*)&n, &r)==1) { line =
ImStrSkipBlank(line + r); column->UserID = (ImGuiID)n; }
3812 if (sscanf(line,
"Width=%d%n", &n, &r) == 1) { line =
ImStrSkipBlank(line + r); column->WidthOrWeight = (float)n; column->IsStretch = 0; settings->SaveFlags |= ImGuiTableFlags_Resizable; }
3813 if (sscanf(line,
"Weight=%f%n", &f, &r) == 1) { line =
ImStrSkipBlank(line + r); column->WidthOrWeight = f; column->IsStretch = 1; settings->SaveFlags |= ImGuiTableFlags_Resizable; }
3814 if (sscanf(line,
"Visible=%d%n", &n, &r) == 1) { line =
ImStrSkipBlank(line + r); column->IsEnabled = (ImU8)n; settings->SaveFlags |= ImGuiTableFlags_Hideable; }
3815 if (sscanf(line,
"Order=%d%n", &n, &r) == 1) { line =
ImStrSkipBlank(line + r); column->DisplayOrder = (ImGuiTableColumnIdx)n; settings->SaveFlags |= ImGuiTableFlags_Reorderable; }
3816 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; }
3820static void TableSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf)
3822 ImGuiContext&
g = *ctx;
3823 for (ImGuiTableSettings* settings =
g.SettingsTables.begin(); settings != NULL; settings =
g.SettingsTables.next_chunk(settings))
3825 if (settings->ID == 0)
3830 const bool save_size = (settings->SaveFlags & ImGuiTableFlags_Resizable) != 0;
3831 const bool save_visible = (settings->SaveFlags & ImGuiTableFlags_Hideable) != 0;
3832 const bool save_order = (settings->SaveFlags & ImGuiTableFlags_Reorderable) != 0;
3833 const bool save_sort = (settings->SaveFlags & ImGuiTableFlags_Sortable) != 0;
3834 if (!save_size && !save_visible && !save_order && !save_sort)
3837 buf->reserve(buf->size() + 30 + settings->ColumnsCount * 50);
3838 buf->appendf(
"[%s][0x%08X,%d]\n", handler->TypeName, settings->ID, settings->ColumnsCount);
3839 if (settings->RefScale != 0.0f)
3840 buf->appendf(
"RefScale=%g\n", settings->RefScale);
3841 ImGuiTableColumnSettings* column = settings->GetColumnSettings();
3842 for (
int column_n = 0; column_n < settings->ColumnsCount; column_n++, column++)
3845 bool save_column = column->UserID != 0 || save_size || save_visible || save_order || (save_sort && column->SortOrder != -1);
3848 buf->appendf(
"Column %-2d", column_n);
3849 if (column->UserID != 0) { buf->appendf(
" UserID=%08X", column->UserID); }
3850 if (save_size && column->IsStretch) { buf->appendf(
" Weight=%.4f", column->WidthOrWeight); }
3851 if (save_size && !column->IsStretch) { buf->appendf(
" Width=%d", (
int)column->WidthOrWeight); }
3852 if (save_visible) { buf->appendf(
" Visible=%d", column->IsEnabled); }
3853 if (save_order) { buf->appendf(
" Order=%d", column->DisplayOrder); }
3854 if (save_sort && column->SortOrder != -1) { buf->appendf(
" Sort=%d%c", column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ?
'v' :
'^'); }
3861void ImGui::TableSettingsAddSettingsHandler()
3863 ImGuiSettingsHandler ini_handler;
3864 ini_handler.TypeName =
"Table";
3865 ini_handler.TypeHash =
ImHashStr(
"Table");
3866 ini_handler.ClearAllFn = TableSettingsHandler_ClearAll;
3867 ini_handler.ReadOpenFn = TableSettingsHandler_ReadOpen;
3868 ini_handler.ReadLineFn = TableSettingsHandler_ReadLine;
3869 ini_handler.ApplyAllFn = TableSettingsHandler_ApplyAll;
3870 ini_handler.WriteAllFn = TableSettingsHandler_WriteAll;
3871 AddSettingsHandler(&ini_handler);
3883void ImGui::TableRemove(ImGuiTable* table)
3887 int table_idx =
g.Tables.GetIndex(table);
3890 g.Tables.Remove(table->ID, table);
3891 g.TablesLastTimeActive[table_idx] = -1.0f;
3895void ImGui::TableGcCompactTransientBuffers(ImGuiTable* table)
3899 IM_ASSERT(table->MemoryCompacted ==
false);
3900 table->SortSpecs.Specs = NULL;
3901 table->SortSpecsMulti.clear();
3902 table->IsSortSpecsDirty =
true;
3903 table->ColumnsNames.clear();
3904 table->MemoryCompacted =
true;
3905 for (
int n = 0; n < table->ColumnsCount; n++)
3906 table->Columns[n].NameOffset = -1;
3907 g.TablesLastTimeActive[
g.Tables.GetIndex(table)] = -1.0f;
3910void ImGui::TableGcCompactTransientBuffers(ImGuiTableTempData* temp_data)
3912 temp_data->DrawSplitter.ClearFreeMemory();
3913 temp_data->LastTimeActive = -1.0f;
3917void ImGui::TableGcCompactSettings()
3920 int required_memory = 0;
3921 for (ImGuiTableSettings* settings =
g.SettingsTables.begin(); settings != NULL; settings =
g.SettingsTables.next_chunk(settings))
3922 if (settings->ID != 0)
3923 required_memory += (int)TableSettingsCalcChunkSize(settings->ColumnsCount);
3924 if (required_memory ==
g.SettingsTables.Buf.Size)
3926 ImChunkStream<ImGuiTableSettings> new_chunk_stream;
3927 new_chunk_stream.Buf.reserve(required_memory);
3928 for (ImGuiTableSettings* settings =
g.SettingsTables.begin(); settings != NULL; settings =
g.SettingsTables.next_chunk(settings))
3929 if (settings->ID != 0)
3930 memcpy(new_chunk_stream.alloc_chunk(TableSettingsCalcChunkSize(settings->ColumnsCount)), settings, TableSettingsCalcChunkSize(settings->ColumnsCount));
3931 g.SettingsTables.swap(new_chunk_stream);
3941#ifndef IMGUI_DISABLE_DEBUG_TOOLS
3943static const char* DebugNodeTableGetSizingPolicyDesc(ImGuiTableFlags sizing_policy)
3945 sizing_policy &= ImGuiTableFlags_SizingMask_;
3946 if (sizing_policy == ImGuiTableFlags_SizingFixedFit) {
return "FixedFit"; }
3947 if (sizing_policy == ImGuiTableFlags_SizingFixedSame) {
return "FixedSame"; }
3948 if (sizing_policy == ImGuiTableFlags_SizingStretchProp) {
return "StretchProp"; }
3949 if (sizing_policy == ImGuiTableFlags_SizingStretchSame) {
return "StretchSame"; }
3953void ImGui::DebugNodeTable(ImGuiTable* table)
3956 const bool is_active = (table->LastFrameActive >=
g.FrameCount - 2);
3957 if (!is_active) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); }
3958 bool open =
TreeNode(table,
"Table 0x%08X (%d columns, in '%s')%s", table->ID, table->ColumnsCount, table->OuterWindow->Name, is_active ?
"" :
" *Inactive*");
3959 if (!is_active) { PopStyleColor(); }
3960 if (IsItemHovered())
3961 GetForegroundDrawList()->AddRect(table->OuterRect.Min, table->OuterRect.Max, IM_COL32(255, 255, 0, 255));
3962 if (IsItemVisible() && table->HoveredColumnBody != -1)
3963 GetForegroundDrawList()->AddRect(GetItemRectMin(), GetItemRectMax(), IM_COL32(255, 255, 0, 255));
3966 if (table->InstanceCurrent > 0)
3967 Text(
"** %d instances of same table! Some data below will refer to last instance.", table->InstanceCurrent + 1);
3968 if (
g.IO.ConfigDebugIsDebuggerPresent)
3970 if (DebugBreakButton(
"**DebugBreak**",
"in BeginTable()"))
3971 g.DebugBreakInTable = table->ID;
3975 bool clear_settings = SmallButton(
"Clear settings");
3976 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));
3977 BulletText(
"ColumnsGivenWidth: %.1f, ColumnsAutoFitWidth: %.1f, InnerWidth: %.1f%s", table->ColumnsGivenWidth, table->ColumnsAutoFitWidth, table->InnerWidth, table->InnerWidth == 0.0f ?
" (auto)" :
"");
3978 BulletText(
"CellPaddingX: %.1f, CellSpacingX: %.1f/%.1f, OuterPaddingX: %.1f", table->CellPaddingX, table->CellSpacingX1, table->CellSpacingX2, table->OuterPaddingX);
3979 BulletText(
"HoveredColumnBody: %d, HoveredColumnBorder: %d", table->HoveredColumnBody, table->HoveredColumnBorder);
3980 BulletText(
"ResizedColumn: %d, ReorderColumn: %d, HeldHeaderColumn: %d", table->ResizedColumn, table->ReorderColumn, table->HeldHeaderColumn);
3981 for (
int n = 0; n < table->InstanceCurrent + 1; n++)
3983 ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, n);
3984 BulletText(
"Instance %d: HoveredRow: %d, LastOuterHeight: %.2f", n, table_instance->HoveredRowLast, table_instance->LastOuterHeight);
3987 float sum_weights = 0.0f;
3988 for (
int n = 0; n < table->ColumnsCount; n++)
3989 if (table->Columns[n].Flags & ImGuiTableColumnFlags_WidthStretch)
3990 sum_weights += table->Columns[n].StretchWeight;
3991 for (
int n = 0; n < table->ColumnsCount; n++)
3993 ImGuiTableColumn* column = &table->Columns[n];
3994 const char* name = TableGetColumnName(table, n);
3997 "Column %d order %d '%s': offset %+.2f to %+.2f%s\n"
3998 "Enabled: %d, VisibleX/Y: %d/%d, RequestOutput: %d, SkipItems: %d, DrawChannels: %d,%d\n"
3999 "WidthGiven: %.1f, Request/Auto: %.1f/%.1f, StretchWeight: %.3f (%.1f%%)\n"
4000 "MinX: %.1f, MaxX: %.1f (%+.1f), ClipRect: %.1f to %.1f (+%.1f)\n"
4001 "ContentWidth: %.1f,%.1f, HeadersUsed/Ideal %.1f/%.1f\n"
4002 "Sort: %d%s, UserID: 0x%08X, Flags: 0x%04X: %s%s%s..",
4003 n, column->DisplayOrder, name, column->MinX - table->WorkRect.Min.x, column->MaxX - table->WorkRect.Min.x, (n < table->FreezeColumnsRequest) ?
" (Frozen)" :
"",
4004 column->IsEnabled, column->IsVisibleX, column->IsVisibleY, column->IsRequestOutput, column->IsSkipItems, column->DrawChannelFrozen, column->DrawChannelUnfrozen,
4005 column->WidthGiven, column->WidthRequest, column->WidthAuto, column->StretchWeight, column->StretchWeight > 0.0f ? (column->StretchWeight / sum_weights) * 100.0f : 0.0f,
4006 column->MinX, column->MaxX, column->MaxX - column->MinX, column->ClipRect.Min.x, column->ClipRect.Max.x, column->ClipRect.Max.x - column->ClipRect.Min.x,
4007 column->ContentMaxXFrozen - column->WorkMinX, column->ContentMaxXUnfrozen - column->WorkMinX, column->ContentMaxXHeadersUsed - column->WorkMinX, column->ContentMaxXHeadersIdeal - column->WorkMinX,
4008 column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ?
" (Asc)" : (column->SortDirection == ImGuiSortDirection_Descending) ?
" (Des)" :
"", column->UserID, column->Flags,
4009 (column->Flags & ImGuiTableColumnFlags_WidthStretch) ?
"WidthStretch " :
"",
4010 (column->Flags & ImGuiTableColumnFlags_WidthFixed) ?
"WidthFixed " :
"",
4011 (column->Flags & ImGuiTableColumnFlags_NoResize) ?
"NoResize " :
"");
4014 if (IsItemHovered())
4016 ImRect r(column->MinX, table->OuterRect.Min.y, column->MaxX, table->OuterRect.Max.y);
4017 GetForegroundDrawList()->AddRect(r.Min, r.Max, IM_COL32(255, 255, 0, 255));
4020 if (ImGuiTableSettings* settings = TableGetBoundSettings(table))
4021 DebugNodeTableSettings(settings);
4023 table->IsResetAllRequest =
true;
4027void ImGui::DebugNodeTableSettings(ImGuiTableSettings* settings)
4029 if (!
TreeNode((
void*)(intptr_t)settings->ID,
"Settings 0x%08X (%d columns)", settings->ID, settings->ColumnsCount))
4031 BulletText(
"SaveFlags: 0x%08X", settings->SaveFlags);
4032 BulletText(
"ColumnsCount: %d (max %d)", settings->ColumnsCount, settings->ColumnsCountMax);
4033 for (
int n = 0; n < settings->ColumnsCount; n++)
4035 ImGuiTableColumnSettings* column_settings = &settings->GetColumnSettings()[n];
4036 ImGuiSortDirection sort_dir = (column_settings->SortOrder != -1) ? (ImGuiSortDirection)column_settings->SortDirection : ImGuiSortDirection_None;
4037 BulletText(
"Column %d Order %d SortOrder %d %s Vis %d %s %7.3f UserID 0x%08X",
4038 n, column_settings->DisplayOrder, column_settings->SortOrder,
4039 (sort_dir == ImGuiSortDirection_Ascending) ?
"Asc" : (sort_dir == ImGuiSortDirection_Descending) ?
"Des" :
"---",
4040 column_settings->IsEnabled, column_settings->IsStretch ?
"Weight" :
"Width ", column_settings->WidthOrWeight, column_settings->UserID);
4047void ImGui::DebugNodeTable(ImGuiTable*) {}
4048void ImGui::DebugNodeTableSettings(ImGuiTableSettings*) {}
4081void ImGui::SetWindowClipRectBeforeSetChannel(ImGuiWindow* window,
const ImRect& clip_rect)
4083 ImVec4 clip_rect_vec4 = clip_rect.ToVec4();
4084 window->ClipRect = clip_rect;
4085 window->DrawList->_CmdHeader.ClipRect = clip_rect_vec4;
4086 window->DrawList->_ClipRectStack.Data[window->DrawList->_ClipRectStack.Size - 1] = clip_rect_vec4;
4089int ImGui::GetColumnIndex()
4091 ImGuiWindow* window = GetCurrentWindowRead();
4092 return window->DC.CurrentColumns ? window->DC.CurrentColumns->Current : 0;
4095int ImGui::GetColumnsCount()
4097 ImGuiWindow* window = GetCurrentWindowRead();
4098 return window->DC.CurrentColumns ? window->DC.CurrentColumns->Count : 1;
4101float ImGui::GetColumnOffsetFromNorm(
const ImGuiOldColumns* columns,
float offset_norm)
4103 return offset_norm * (columns->OffMaxX - columns->OffMinX);
4106float ImGui::GetColumnNormFromOffset(
const ImGuiOldColumns* columns,
float offset)
4108 return offset / (columns->OffMaxX - columns->OffMinX);
4111static const float COLUMNS_HIT_RECT_HALF_THICKNESS = 4.0f;
4113static float GetDraggedColumnOffset(ImGuiOldColumns* columns,
int column_index)
4118 ImGuiWindow* window =
g.CurrentWindow;
4119 IM_ASSERT(column_index > 0);
4120 IM_ASSERT(
g.ActiveId == columns->ID + ImGuiID(column_index));
4122 float x =
g.IO.MousePos.x -
g.ActiveIdClickOffset.x + ImTrunc(COLUMNS_HIT_RECT_HALF_THICKNESS *
g.CurrentDpiScale) - window->Pos.x;
4123 x = ImMax(x, ImGui::GetColumnOffset(column_index - 1) +
g.Style.ColumnsMinSpacing);
4124 if ((columns->Flags & ImGuiOldColumnFlags_NoPreserveWidths))
4125 x = ImMin(x, ImGui::GetColumnOffset(column_index + 1) -
g.Style.ColumnsMinSpacing);
4130float ImGui::GetColumnOffset(
int column_index)
4132 ImGuiWindow* window = GetCurrentWindowRead();
4133 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4134 if (columns == NULL)
4137 if (column_index < 0)
4138 column_index = columns->Current;
4139 IM_ASSERT(column_index < columns->Columns.Size);
4141 const float t = columns->Columns[column_index].OffsetNorm;
4142 const float x_offset = ImLerp(columns->OffMinX, columns->OffMaxX,
t);
4146static float GetColumnWidthEx(ImGuiOldColumns* columns,
int column_index,
bool before_resize =
false)
4148 if (column_index < 0)
4149 column_index = columns->Current;
4153 offset_norm = columns->Columns[column_index + 1].OffsetNormBeforeResize - columns->Columns[column_index].OffsetNormBeforeResize;
4155 offset_norm = columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm;
4156 return ImGui::GetColumnOffsetFromNorm(columns, offset_norm);
4159float ImGui::GetColumnWidth(
int column_index)
4162 ImGuiWindow* window =
g.CurrentWindow;
4163 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4164 if (columns == NULL)
4165 return GetContentRegionAvail().x;
4167 if (column_index < 0)
4168 column_index = columns->Current;
4169 return GetColumnOffsetFromNorm(columns, columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm);
4172void ImGui::SetColumnOffset(
int column_index,
float offset)
4175 ImGuiWindow* window =
g.CurrentWindow;
4176 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4177 IM_ASSERT(columns != NULL);
4179 if (column_index < 0)
4180 column_index = columns->Current;
4181 IM_ASSERT(column_index < columns->Columns.Size);
4183 const bool preserve_width = !(columns->Flags & ImGuiOldColumnFlags_NoPreserveWidths) && (column_index < columns->Count - 1);
4184 const float width = preserve_width ? GetColumnWidthEx(columns, column_index, columns->IsBeingResized) : 0.0f;
4186 if (!(columns->Flags & ImGuiOldColumnFlags_NoForceWithinWindow))
4187 offset = ImMin(offset, columns->OffMaxX -
g.Style.ColumnsMinSpacing * (columns->Count - column_index));
4188 columns->Columns[column_index].OffsetNorm = GetColumnNormFromOffset(columns, offset - columns->OffMinX);
4191 SetColumnOffset(column_index + 1, offset + ImMax(
g.Style.ColumnsMinSpacing, width));
4194void ImGui::SetColumnWidth(
int column_index,
float width)
4196 ImGuiWindow* window = GetCurrentWindowRead();
4197 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4198 IM_ASSERT(columns != NULL);
4200 if (column_index < 0)
4201 column_index = columns->Current;
4202 SetColumnOffset(column_index + 1, GetColumnOffset(column_index) + width);
4205void ImGui::PushColumnClipRect(
int column_index)
4207 ImGuiWindow* window = GetCurrentWindowRead();
4208 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4209 if (column_index < 0)
4210 column_index = columns->Current;
4212 ImGuiOldColumnData* column = &columns->Columns[column_index];
4213 PushClipRect(column->ClipRect.Min, column->ClipRect.Max,
false);
4217void ImGui::PushColumnsBackground()
4219 ImGuiWindow* window = GetCurrentWindowRead();
4220 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4221 if (columns->Count == 1)
4225 columns->HostBackupClipRect = window->ClipRect;
4226 SetWindowClipRectBeforeSetChannel(window, columns->HostInitialClipRect);
4227 columns->Splitter.SetCurrentChannel(window->DrawList, 0);
4230void ImGui::PopColumnsBackground()
4232 ImGuiWindow* window = GetCurrentWindowRead();
4233 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4234 if (columns->Count == 1)
4238 SetWindowClipRectBeforeSetChannel(window, columns->HostBackupClipRect);
4239 columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1);
4242ImGuiOldColumns* ImGui::FindOrCreateColumns(ImGuiWindow* window, ImGuiID
id)
4245 for (
int n = 0; n < window->ColumnsStorage.Size; n++)
4246 if (window->ColumnsStorage[n].ID ==
id)
4247 return &window->ColumnsStorage[n];
4249 window->ColumnsStorage.push_back(ImGuiOldColumns());
4250 ImGuiOldColumns* columns = &window->ColumnsStorage.back();
4255ImGuiID ImGui::GetColumnsID(
const char* str_id,
int columns_count)
4257 ImGuiWindow* window = GetCurrentWindow();
4261 PushID(0x11223347 + (str_id ? 0 : columns_count));
4262 ImGuiID
id = window->GetID(str_id ? str_id :
"columns");
4268void ImGui::BeginColumns(
const char* str_id,
int columns_count, ImGuiOldColumnFlags flags)
4271 ImGuiWindow* window = GetCurrentWindow();
4273 IM_ASSERT(columns_count >= 1);
4274 IM_ASSERT(window->DC.CurrentColumns == NULL);
4277 ImGuiID
id = GetColumnsID(str_id, columns_count);
4278 ImGuiOldColumns* columns = FindOrCreateColumns(window,
id);
4279 IM_ASSERT(columns->ID ==
id);
4280 columns->Current = 0;
4281 columns->Count = columns_count;
4282 columns->Flags = flags;
4283 window->DC.CurrentColumns = columns;
4284 window->DC.NavIsScrollPushableX =
false;
4286 columns->HostCursorPosY = window->DC.CursorPos.y;
4287 columns->HostCursorMaxPosX = window->DC.CursorMaxPos.x;
4288 columns->HostInitialClipRect = window->ClipRect;
4289 columns->HostBackupParentWorkRect = window->ParentWorkRect;
4290 window->ParentWorkRect = window->WorkRect;
4294 const float column_padding =
g.Style.ItemSpacing.x;
4295 const float half_clip_extend_x = ImTrunc(ImMax(window->WindowPadding.x * 0.5f, window->WindowBorderSize));
4296 const float max_1 = window->WorkRect.Max.x + column_padding - ImMax(column_padding - window->WindowPadding.x, 0.0f);
4297 const float max_2 = window->WorkRect.Max.x + half_clip_extend_x;
4298 columns->OffMinX = window->DC.Indent.x - column_padding + ImMax(column_padding - window->WindowPadding.x, 0.0f);
4299 columns->OffMaxX = ImMax(ImMin(max_1, max_2) - window->Pos.x, columns->OffMinX + 1.0f);
4300 columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y;
4303 if (columns->Columns.Size != 0 && columns->Columns.Size != columns_count + 1)
4304 columns->Columns.resize(0);
4307 columns->IsFirstFrame = (columns->Columns.Size == 0);
4308 if (columns->Columns.Size == 0)
4310 columns->Columns.reserve(columns_count + 1);
4311 for (
int n = 0; n < columns_count + 1; n++)
4313 ImGuiOldColumnData column;
4314 column.OffsetNorm = n / (float)columns_count;
4315 columns->Columns.push_back(column);
4319 for (
int n = 0; n < columns_count; n++)
4322 ImGuiOldColumnData* column = &columns->Columns[n];
4323 float clip_x1 = IM_ROUND(window->Pos.x + GetColumnOffset(n));
4324 float clip_x2 = IM_ROUND(window->Pos.x + GetColumnOffset(n + 1) - 1.0f);
4325 column->ClipRect = ImRect(clip_x1, -FLT_MAX, clip_x2, +FLT_MAX);
4326 column->ClipRect.ClipWithFull(window->ClipRect);
4329 if (columns->Count > 1)
4331 columns->Splitter.Split(window->DrawList, 1 + columns->Count);
4332 columns->Splitter.SetCurrentChannel(window->DrawList, 1);
4333 PushColumnClipRect(0);
4337 float offset_0 = GetColumnOffset(columns->Current);
4338 float offset_1 = GetColumnOffset(columns->Current + 1);
4339 float width = offset_1 - offset_0;
4340 PushItemWidth(width * 0.65f);
4341 window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
4342 window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
4343 window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding;
4344 window->WorkRect.Max.y = window->ContentRegionRect.Max.y;
4347void ImGui::NextColumn()
4349 ImGuiWindow* window = GetCurrentWindow();
4350 if (window->SkipItems || window->DC.CurrentColumns == NULL)
4354 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4356 if (columns->Count == 1)
4358 window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
4359 IM_ASSERT(columns->Current == 0);
4364 if (++columns->Current == columns->Count)
4365 columns->Current = 0;
4371 ImGuiOldColumnData* column = &columns->Columns[columns->Current];
4372 SetWindowClipRectBeforeSetChannel(window, column->ClipRect);
4373 columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1);
4375 const float column_padding =
g.Style.ItemSpacing.x;
4376 columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y);
4377 if (columns->Current > 0)
4381 window->DC.ColumnsOffset.x = GetColumnOffset(columns->Current) - window->DC.Indent.x + column_padding;
4386 window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
4387 window->DC.IsSameLine =
false;
4388 columns->LineMinY = columns->LineMaxY;
4390 window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
4391 window->DC.CursorPos.y = columns->LineMinY;
4392 window->DC.CurrLineSize = ImVec2(0.0f, 0.0f);
4393 window->DC.CurrLineTextBaseOffset = 0.0f;
4396 float offset_0 = GetColumnOffset(columns->Current);
4397 float offset_1 = GetColumnOffset(columns->Current + 1);
4398 float width = offset_1 - offset_0;
4399 PushItemWidth(width * 0.65f);
4400 window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding;
4403void ImGui::EndColumns()
4406 ImGuiWindow* window = GetCurrentWindow();
4407 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4408 IM_ASSERT(columns != NULL);
4411 if (columns->Count > 1)
4414 columns->Splitter.Merge(window->DrawList);
4417 const ImGuiOldColumnFlags flags = columns->Flags;
4418 columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y);
4419 window->DC.CursorPos.y = columns->LineMaxY;
4420 if (!(flags & ImGuiOldColumnFlags_GrowParentContentsSize))
4421 window->DC.CursorMaxPos.x = columns->HostCursorMaxPosX;
4425 bool is_being_resized =
false;
4426 if (!(flags & ImGuiOldColumnFlags_NoBorder) && !window->SkipItems)
4429 const float y1 = ImMax(columns->HostCursorPosY, window->ClipRect.Min.y);
4430 const float y2 = ImMin(window->DC.CursorPos.y, window->ClipRect.Max.y);
4431 int dragging_column = -1;
4432 for (
int n = 1; n < columns->Count; n++)
4434 ImGuiOldColumnData* column = &columns->Columns[n];
4435 float x = window->Pos.x + GetColumnOffset(n);
4436 const ImGuiID column_id = columns->ID + ImGuiID(n);
4437 const float column_hit_hw = ImTrunc(COLUMNS_HIT_RECT_HALF_THICKNESS *
g.CurrentDpiScale);
4438 const ImRect column_hit_rect(ImVec2(x - column_hit_hw, y1), ImVec2(x + column_hit_hw, y2));
4439 if (!ItemAdd(column_hit_rect, column_id, NULL, ImGuiItemFlags_NoNav))
4442 bool hovered =
false, held =
false;
4443 if (!(flags & ImGuiOldColumnFlags_NoResize))
4445 ButtonBehavior(column_hit_rect, column_id, &hovered, &held);
4446 if (hovered || held)
4447 SetMouseCursor(ImGuiMouseCursor_ResizeEW);
4448 if (held && !(column->Flags & ImGuiOldColumnFlags_NoResize))
4449 dragging_column = n;
4453 const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator);
4454 const float xi = IM_TRUNC(x);
4455 window->DrawList->AddLine(ImVec2(xi, y1 + 1.0f), ImVec2(xi, y2), col);
4459 if (dragging_column != -1)
4461 if (!columns->IsBeingResized)
4462 for (
int n = 0; n < columns->Count + 1; n++)
4463 columns->Columns[n].OffsetNormBeforeResize = columns->Columns[n].OffsetNorm;
4464 columns->IsBeingResized = is_being_resized =
true;
4465 float x = GetDraggedColumnOffset(columns, dragging_column);
4466 SetColumnOffset(dragging_column, x);
4469 columns->IsBeingResized = is_being_resized;
4471 window->WorkRect = window->ParentWorkRect;
4472 window->ParentWorkRect = columns->HostBackupParentWorkRect;
4473 window->DC.CurrentColumns = NULL;
4474 window->DC.ColumnsOffset.x = 0.0f;
4475 window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
4476 NavUpdateCurrentWindowIsScrollPushableX();
4479void ImGui::Columns(
int columns_count,
const char*
id,
bool borders)
4481 ImGuiWindow* window = GetCurrentWindow();
4482 IM_ASSERT(columns_count >= 1);
4484 ImGuiOldColumnFlags flags = (borders ? 0 : ImGuiOldColumnFlags_NoBorder);
4486 ImGuiOldColumns* columns = window->DC.CurrentColumns;
4487 if (columns != NULL && columns->Count == columns_count && columns->Flags == flags)
4490 if (columns != NULL)
4493 if (columns_count != 1)
4494 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)
int ImTextCountLines(const char *in_text, const char *in_text_end)
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)
bool TreeNode(const char *label, ImGuiTreeNodeFlags flags, std::invocable<> auto next)
auto count(InputRange &&range, const T &value)