MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / TableSetupDrawChannels

Method TableSetupDrawChannels

KBotExt/imgui/imgui_tables.cpp:2330–2367  ·  view source on GitHub ↗

Allocate draw channels. Called by TableUpdateLayout() - We allocate them following storage order instead of display order so reordering columns won't needlessly increase overall dormant memory cost. - We isolate headers draw commands in their own channels instead of just altering clip rects. This is in order to facilitate merging of draw commands. - After crossing FreezeRowsCount, all columns see

Source from the content-addressed store, hash-verified

2328// - FreezeRows || FreezeColunns --> 3+D+N*2 (unless scrolling value is zero)
2329// Where D is 1 if any column is clipped or hidden (dummy channel) otherwise 0.
2330void ImGui::TableSetupDrawChannels(ImGuiTable* table)
2331{
2332 const int freeze_row_multiplier = (table->FreezeRowsCount > 0) ? 2 : 1;
2333 const int channels_for_row = (table->Flags & ImGuiTableFlags_NoClip) ? 1 : table->ColumnsEnabledCount;
2334 const int channels_for_bg = 1 + 1 * freeze_row_multiplier;
2335 const int channels_for_dummy = (table->ColumnsEnabledCount < table->ColumnsCount || (memcmp(table->VisibleMaskByIndex, table->EnabledMaskByIndex, ImBitArrayGetStorageSizeInBytes(table->ColumnsCount)) != 0)) ? +1 : 0;
2336 const int channels_total = channels_for_bg + (channels_for_row * freeze_row_multiplier) + channels_for_dummy;
2337 table->DrawSplitter->Split(table->InnerWindow->DrawList, channels_total);
2338 table->DummyDrawChannel = (ImGuiTableDrawChannelIdx)((channels_for_dummy > 0) ? channels_total - 1 : -1);
2339 table->Bg2DrawChannelCurrent = TABLE_DRAW_CHANNEL_BG2_FROZEN;
2340 table->Bg2DrawChannelUnfrozen = (ImGuiTableDrawChannelIdx)((table->FreezeRowsCount > 0) ? 2 + channels_for_row : TABLE_DRAW_CHANNEL_BG2_FROZEN);
2341
2342 int draw_channel_current = 2;
2343 for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
2344 {
2345 ImGuiTableColumn* column = &table->Columns[column_n];
2346 if (column->IsVisibleX && column->IsVisibleY)
2347 {
2348 column->DrawChannelFrozen = (ImGuiTableDrawChannelIdx)(draw_channel_current);
2349 column->DrawChannelUnfrozen = (ImGuiTableDrawChannelIdx)(draw_channel_current + (table->FreezeRowsCount > 0 ? channels_for_row + 1 : 0));
2350 if (!(table->Flags & ImGuiTableFlags_NoClip))
2351 draw_channel_current++;
2352 }
2353 else
2354 {
2355 column->DrawChannelFrozen = column->DrawChannelUnfrozen = table->DummyDrawChannel;
2356 }
2357 column->DrawChannelCurrent = column->DrawChannelFrozen;
2358 }
2359
2360 // Initial draw cmd starts with a BgClipRect that matches the one of its host, to facilitate merge draw commands by default.
2361 // All our cell highlight are manually clipped with BgClipRect. When unfreezing it will be made smaller to fit scrolling rect.
2362 // (This technically isn't part of setting up draw channels, but is reasonably related to be done here)
2363 table->BgClipRect = table->InnerClipRect;
2364 table->Bg0ClipRectForDrawCmd = table->OuterWindow->ClipRect;
2365 table->Bg2ClipRectForDrawCmd = table->HostClipRect;
2366 IM_ASSERT(table->BgClipRect.Min.y <= table->BgClipRect.Max.y);
2367}
2368
2369// This function reorder draw channels based on matching clip rectangle, to facilitate merging them. Called by EndTable().
2370// For simplicity we call it TableMergeDrawChannels() but in fact it only reorder channels + overwrite ClipRect,

Callers

nothing calls this directly

Calls 2

SplitMethod · 0.80

Tested by

no test coverage detected