@ -1316,20 +1316,23 @@ void ImGui::TableSetColumnWidth(ImGuiTable* table, ImGuiTableColumn* column_0, f
// - After crossing FreezeRowsCount, all columns see their current draw channel changed to a second set of channels.
// - After crossing FreezeRowsCount, all columns see their current draw channel changed to a second set of channels.
// - We only use the dummy draw channel so we can push a null clipping rectangle into it without affecting other
// - We only use the dummy draw channel so we can push a null clipping rectangle into it without affecting other
// channels, while simplifying per-row/per-cell overhead. It will be empty and discarded when merged.
// channels, while simplifying per-row/per-cell overhead. It will be empty and discarded when merged.
// - We allocate 1 or 2 background draw channels. This is because we know PushTableBackground() is only used for
// horizontal spanning. If we allowed vertical spanning we'd need one background draw channel per merge group (1-4).
// Draw channel allocation (before merging):
// Draw channel allocation (before merging):
// - NoClip --> 1+1 channels: background + foreground (same clip rect == 1 draw call)
// - NoClip --> 1+1 channels: background + foreground (same clip rect == 1 draw call)
// - Clip --> 1+N channels
// - Clip --> 1+N channels
// - FreezeRows || FreezeColumns --> 1+N*2 (unless scrolling value is zero)
// - FreezeRows --> 1+N*2 (unless scrolling value is zero)
// - FreezeRows && FreezeColunns --> 2+N*2 (unless scrolling value is zero)
// - FreezeRows || FreezeColunns --> 2+N*2 (unless scrolling value is zero)
void ImGui : : TableUpdateDrawChannels ( ImGuiTable * table )
void ImGui : : TableUpdateDrawChannels ( ImGuiTable * table )
{
{
const int freeze_row_multiplier = ( table - > FreezeRowsCount > 0 ) ? 2 : 1 ;
const int freeze_row_multiplier = ( table - > FreezeRowsCount > 0 ) ? 2 : 1 ;
const int channels_for_row = ( table - > Flags & ImGuiTableFlags_NoClip ) ? 1 : table - > ColumnsVisibleCount ;
const int channels_for_row = ( table - > Flags & ImGuiTableFlags_NoClip ) ? 1 : table - > ColumnsVisibleCount ;
const int channels_for_b ack ground = 1 ;
const int channels_for_b g = 1 * freeze_row_multiplier ;
const int channels_for_dummy = ( table - > ColumnsVisibleCount < table - > ColumnsCount | | table - > VisibleUnclippedMaskByIndex ! = table - > VisibleMaskByIndex ) ? + 1 : 0 ;
const int channels_for_dummy = ( table - > ColumnsVisibleCount < table - > ColumnsCount | | table - > VisibleUnclippedMaskByIndex ! = table - > VisibleMaskByIndex ) ? + 1 : 0 ;
const int channels_total = channels_for_b ack ground + ( channels_for_row * freeze_row_multiplier ) + channels_for_dummy ;
const int channels_total = channels_for_b g + ( channels_for_row * freeze_row_multiplier ) + channels_for_dummy ;
table - > DrawSplitter . Split ( table - > InnerWindow - > DrawList , channels_total ) ;
table - > DrawSplitter . Split ( table - > InnerWindow - > DrawList , channels_total ) ;
table - > DummyDrawChannel = channels_for_dummy ? ( ImS8 ) ( channels_total - 1 ) : - 1 ;
table - > DummyDrawChannel = ( channels_for_dummy > 0 ) ? ( ImS8 ) ( channels_total - 1 ) : - 1 ;
table - > BgDrawChannelUnfrozen = ( ImS8 ) ( ( table - > FreezeRowsCount > 0 ) ? channels_for_row + 1 : 0 ) ;
int draw_channel_current = 1 ;
int draw_channel_current = 1 ;
for ( int column_n = 0 ; column_n < table - > ColumnsCount ; column_n + + )
for ( int column_n = 0 ; column_n < table - > ColumnsCount ; column_n + + )
@ -1338,7 +1341,7 @@ void ImGui::TableUpdateDrawChannels(ImGuiTable* table)
if ( ! column - > IsClipped )
if ( ! column - > IsClipped )
{
{
column - > DrawChannelFrozen = ( ImS8 ) ( draw_channel_current ) ;
column - > DrawChannelFrozen = ( ImS8 ) ( draw_channel_current ) ;
column - > DrawChannelUnfrozen = ( ImS8 ) ( draw_channel_current + ( table - > FreezeRowsCount > 0 ? channels_for_row : 0 ) ) ;
column - > DrawChannelUnfrozen = ( ImS8 ) ( draw_channel_current + ( table - > FreezeRowsCount > 0 ? channels_for_row + 1 : 0 ) ) ;
if ( ! ( table - > Flags & ImGuiTableFlags_NoClip ) )
if ( ! ( table - > Flags & ImGuiTableFlags_NoClip ) )
draw_channel_current + + ;
draw_channel_current + + ;
}
}
@ -1474,9 +1477,11 @@ void ImGui::TableReorderDrawChannelsForMerge(ImGuiTable* table)
ImDrawChannel * dst_tmp = g . DrawChannelsTempMergeBuffer . Data ;
ImDrawChannel * dst_tmp = g . DrawChannelsTempMergeBuffer . Data ;
ImBitArray < IMGUI_TABLE_MAX_DRAW_CHANNELS > remaining_mask ; // We need 130-bit of storage
ImBitArray < IMGUI_TABLE_MAX_DRAW_CHANNELS > remaining_mask ; // We need 130-bit of storage
remaining_mask . ClearBits ( ) ;
remaining_mask . ClearBits ( ) ;
remaining_mask . SetBitRange ( 1 , splitter - > _Count - 1 ) ; // Background channel 0 not part of the merge (see channel allocation in TableUpdateDrawChannels)
remaining_mask . SetBitRange ( 1 , splitter - > _Count - 1 ) ; // Background channel 0 == table->BgDrawChannlFrozen, not part of the merge (see channel allocation in TableUpdateDrawChannels)
int remaining_count = splitter - > _Count - 1 ;
remaining_mask . ClearBit ( table - > BgDrawChannelUnfrozen ) ;
int remaining_count = splitter - > _Count - ( ( table - > BgDrawChannelUnfrozen = = 0 ) ? 1 : 2 ) ;
for ( int merge_group_n = 0 ; merge_group_n < IM_ARRAYSIZE ( merge_groups ) ; merge_group_n + + )
for ( int merge_group_n = 0 ; merge_group_n < IM_ARRAYSIZE ( merge_groups ) ; merge_group_n + + )
{
if ( int merge_channels_count = merge_groups [ merge_group_n ] . ChannelsCount )
if ( int merge_channels_count = merge_groups [ merge_group_n ] . ChannelsCount )
{
{
MergeGroup * merge_group = & merge_groups [ merge_group_n ] ;
MergeGroup * merge_group = & merge_groups [ merge_group_n ] ;
@ -1520,6 +1525,11 @@ void ImGui::TableReorderDrawChannelsForMerge(ImGuiTable* table)
}
}
}
}
// BgDrawChannelFrozen is always channel 0, but make sure BgDrawChannelUnfrozen appears in the middle of our groups
if ( merge_group_n = = 1 & & table - > BgDrawChannelUnfrozen ! = 0 )
memcpy ( dst_tmp + + , & splitter - > _Channels [ table - > BgDrawChannelUnfrozen ] , sizeof ( ImDrawChannel ) ) ;
}
// Append unmergeable channels that we didn't reorder at the end of the list
// Append unmergeable channels that we didn't reorder at the end of the list
for ( int n = 0 ; n < splitter - > _Count & & remaining_count ! = 0 ; n + + )
for ( int n = 0 ; n < splitter - > _Count & & remaining_count ! = 0 ; n + + )
{
{
@ -1731,8 +1741,9 @@ void ImGui::TableEndRow(ImGuiTable* table)
{
{
// In theory we could call SetWindowClipRectBeforeSetChannel() but since we know TableEndRow() is
// In theory we could call SetWindowClipRectBeforeSetChannel() but since we know TableEndRow() is
// always followed by a change of clipping rectangle we perform the smallest overwrite possible here.
// always followed by a change of clipping rectangle we perform the smallest overwrite possible here.
window - > DrawList - > _CmdHeader . ClipRect = table - > HostClipRect . ToVec4 ( ) ;
if ( ( table - > Flags & ImGuiTableFlags_NoClip ) = = 0 )
table - > DrawSplitter . SetCurrentChannel ( window - > DrawList , 0 ) ;
window - > DrawList - > _CmdHeader . ClipRect = ( ( table - > IsUnfrozen & & table - > BgDrawChannelUnfrozen ! = 0 ) ? table - > BackgroundClipRect : table - > HostClipRect ) . ToVec4 ( ) ;
table - > DrawSplitter . SetCurrentChannel ( window - > DrawList , table - > IsUnfrozen ? table - > BgDrawChannelUnfrozen : 0 ) ;
}
}
// Draw row background
// Draw row background
@ -1784,7 +1795,7 @@ void ImGui::TableEndRow(ImGuiTable* table)
{
{
IM_ASSERT ( table - > IsUnfrozen = = false ) ;
IM_ASSERT ( table - > IsUnfrozen = = false ) ;
table - > IsUnfrozen = true ;
table - > IsUnfrozen = true ;
table - > DrawSplitter . SetCurrentChannel ( window - > DrawList , 0 ) ;
table - > DrawSplitter . SetCurrentChannel ( window - > DrawList , table - > BgDrawChannelUnfrozen ) ;
// BackgroundClipRect starts as table->InnerClipRect, reduce it now
// BackgroundClipRect starts as table->InnerClipRect, reduce it now
float y0 = ImMax ( table - > RowPosY2 + 1 , window - > InnerClipRect . Min . y ) ;
float y0 = ImMax ( table - > RowPosY2 + 1 , window - > InnerClipRect . Min . y ) ;
@ -2007,8 +2018,9 @@ void ImGui::PushTableBackground()
// Optimization: avoid SetCurrentChannel() + PushClipRect()
// Optimization: avoid SetCurrentChannel() + PushClipRect()
table - > HostBackupClipRect = window - > ClipRect ;
table - > HostBackupClipRect = window - > ClipRect ;
SetWindowClipRectBeforeSetChannel ( window , table - > HostClipRect ) ;
SetWindowClipRectBeforeSetChannel ( window , table - > BackgroundClipRect ) ;
table - > DrawSplitter . SetCurrentChannel ( window - > DrawList , 0 ) ;
//SetWindowClipRectBeforeSetChannel(window, table->HostClipRect);
table - > DrawSplitter . SetCurrentChannel ( window - > DrawList , table - > IsUnfrozen ? table - > BgDrawChannelUnfrozen : 0 ) ;
}
}
void ImGui : : PopTableBackground ( )
void ImGui : : PopTableBackground ( )
@ -2855,6 +2867,7 @@ void ImGui::DebugNodeTable(ImGuiTable* table)
BulletText ( " CellPaddingX: %.1f, CellSpacingX: %.1f/%.1f, OuterPaddingX: %.1f " , table - > CellPaddingX , table - > CellSpacingX1 , table - > CellSpacingX2 , table - > OuterPaddingX ) ;
BulletText ( " CellPaddingX: %.1f, CellSpacingX: %.1f/%.1f, OuterPaddingX: %.1f " , table - > CellPaddingX , table - > CellSpacingX1 , table - > CellSpacingX2 , table - > OuterPaddingX ) ;
BulletText ( " HoveredColumnBody: %d, HoveredColumnBorder: %d " , table - > HoveredColumnBody , table - > HoveredColumnBorder ) ;
BulletText ( " HoveredColumnBody: %d, HoveredColumnBorder: %d " , table - > HoveredColumnBody , table - > HoveredColumnBorder ) ;
BulletText ( " ResizedColumn: %d, ReorderColumn: %d, HeldHeaderColumn: %d " , table - > ResizedColumn , table - > ReorderColumn , table - > HeldHeaderColumn ) ;
BulletText ( " ResizedColumn: %d, ReorderColumn: %d, HeldHeaderColumn: %d " , table - > ResizedColumn , table - > ReorderColumn , table - > HeldHeaderColumn ) ;
BulletText ( " BgDrawChannels: %d/%d " , 0 , table - > BgDrawChannelUnfrozen ) ;
for ( int n = 0 ; n < table - > ColumnsCount ; n + + )
for ( int n = 0 ; n < table - > ColumnsCount ; n + + )
{
{
ImGuiTableColumn * column = & table - > Columns [ n ] ;
ImGuiTableColumn * column = & table - > Columns [ n ] ;