1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-09-24 03:28:33 +02:00

Tables: Fix for calling TableSetBgColor(ImGuiTableBgTarget_CellBg) multiple times on the same cell.

This commit is contained in:
omar 2020-08-24 15:34:43 +02:00 committed by ocornut
parent 45a80716b1
commit 8e97cdf8e8
4 changed files with 10 additions and 8 deletions

View File

@ -1022,8 +1022,8 @@ enum ImGuiTabItemFlags_
// When ScrollX is on: // When ScrollX is on:
// - Table defaults to ImGuiTableFlags_SizingPolicyFixedX -> all Columns defaults to ImGuiTableColumnFlags_WidthFixed. // - Table defaults to ImGuiTableFlags_SizingPolicyFixedX -> all Columns defaults to ImGuiTableColumnFlags_WidthFixed.
// - Columns sizing policy allowed: Fixed/Auto mostly! Using Stretch columns OFTEN DOES NOT MAKE SENSE if ScrollX is on, UNLESS you have specified a value for 'inner_width' in BeginTable(). // - Columns sizing policy allowed: Fixed/Auto mostly! Using Stretch columns OFTEN DOES NOT MAKE SENSE if ScrollX is on, UNLESS you have specified a value for 'inner_width' in BeginTable().
// - Fixed Columns can be enlarged as needed. Table will show an horizontal scrollbar if needed. // - Fixed Columns can be enlarged as needed. Table will show an horizontal scrollbar if needed.
// - Stretch Columns, if any, will calculate their width using inner_width, assuming no scrolling (it really doesn't make sense to do otherwise). // - Stretch Columns, if any, will calculate their width using inner_width, assuming no scrolling (it really doesn't make sense to do otherwise).
// - Mixing up columns with different sizing policy is possible BUT can be tricky and has some side-effects and restrictions. // - Mixing up columns with different sizing policy is possible BUT can be tricky and has some side-effects and restrictions.
// (their visible order and the scrolling state have subtle but necessary effects on how they can be manually resized). // (their visible order and the scrolling state have subtle but necessary effects on how they can be manually resized).
// The typical use of mixing sizing policies is to have ScrollX disabled, one or two Stretch Column and many Fixed Columns. // The typical use of mixing sizing policies is to have ScrollX disabled, one or two Stretch Column and many Fixed Columns.

View File

@ -2028,7 +2028,7 @@ struct ImGuiTable
ImS8 FreezeRowsCount; // Actual frozen row count (== FreezeRowsRequest, or == 0 when no scrolling offset) ImS8 FreezeRowsCount; // Actual frozen row count (== FreezeRowsRequest, or == 0 when no scrolling offset)
ImS8 FreezeColumnsRequest; // Requested frozen columns count ImS8 FreezeColumnsRequest; // Requested frozen columns count
ImS8 FreezeColumnsCount; // Actual frozen columns count (== FreezeColumnsRequest, or == 0 when no scrolling offset) ImS8 FreezeColumnsCount; // Actual frozen columns count (== FreezeColumnsRequest, or == 0 when no scrolling offset)
ImS8 RowCellDataCount; // Number of RowCellData[] entries in current row ImS8 RowCellDataCurrent; // Index of current RowCellData[] entry in current row
bool IsLayoutLocked; // Set by TableUpdateLayout() which is called when beginning the first row. bool IsLayoutLocked; // Set by TableUpdateLayout() which is called when beginning the first row.
bool IsInsideRow; // Set when inside TableBeginRow()/TableEndRow(). bool IsInsideRow; // Set when inside TableBeginRow()/TableEndRow().
bool IsInitializing; bool IsInitializing;

View File

@ -1623,7 +1623,7 @@ void ImGui::TableBeginRow(ImGuiTable* table)
table->CurrentRow++; table->CurrentRow++;
table->CurrentColumn = -1; table->CurrentColumn = -1;
table->RowBgColor[0] = table->RowBgColor[1] = IM_COL32_DISABLE; table->RowBgColor[0] = table->RowBgColor[1] = IM_COL32_DISABLE;
table->RowCellDataCount = 0; table->RowCellDataCurrent = -1;
table->IsInsideRow = true; table->IsInsideRow = true;
// Begin frozen rows // Begin frozen rows
@ -1702,7 +1702,7 @@ void ImGui::TableEndRow(ImGuiTable* table)
} }
} }
const bool draw_cell_bg_color = table->RowCellDataCount > 0; const bool draw_cell_bg_color = table->RowCellDataCurrent >= 0;
const bool draw_strong_bottom_border = unfreeze_rows;// || (table->RowFlags & ImGuiTableRowFlags_Headers); const bool draw_strong_bottom_border = unfreeze_rows;// || (table->RowFlags & ImGuiTableRowFlags_Headers);
if ((bg_col0 | bg_col1 | border_col) != 0 || draw_strong_bottom_border || draw_cell_bg_color) if ((bg_col0 | bg_col1 | border_col) != 0 || draw_strong_bottom_border || draw_cell_bg_color)
{ {
@ -1727,7 +1727,7 @@ void ImGui::TableEndRow(ImGuiTable* table)
// Draw cell background color // Draw cell background color
if (draw_cell_bg_color) if (draw_cell_bg_color)
{ {
ImGuiTableCellData* cell_data_end = &table->RowCellData[table->RowCellDataCount - 1]; ImGuiTableCellData* cell_data_end = &table->RowCellData[table->RowCellDataCurrent];
for (ImGuiTableCellData* cell_data = &table->RowCellData[0]; cell_data <= cell_data_end; cell_data++) for (ImGuiTableCellData* cell_data = &table->RowCellData[0]; cell_data <= cell_data_end; cell_data++)
{ {
ImGuiTableColumn* column = &table->Columns[cell_data->Column]; ImGuiTableColumn* column = &table->Columns[cell_data->Column];
@ -2359,7 +2359,9 @@ void ImGui::TableSetBgColor(ImGuiTableBgTarget bg_target, ImU32 color, int colum
column_n = table->CurrentColumn; column_n = table->CurrentColumn;
if ((table->VisibleUnclippedMaskByIndex & ((ImU64)1 << column_n)) == 0) if ((table->VisibleUnclippedMaskByIndex & ((ImU64)1 << column_n)) == 0)
return; return;
ImGuiTableCellData* cell_data = &table->RowCellData[table->RowCellDataCount++]; if (table->RowCellDataCurrent < 0 || table->RowCellData[table->RowCellDataCurrent].Column != column_n)
table->RowCellDataCurrent++;
ImGuiTableCellData* cell_data = &table->RowCellData[table->RowCellDataCurrent];
cell_data->BgColor = color; cell_data->BgColor = color;
cell_data->Column = (ImS8)column_n; cell_data->Column = (ImS8)column_n;
break; break;

View File

@ -5999,7 +5999,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
// which would be advantageous since most selectable are not selected. // which would be advantageous since most selectable are not selected.
if (span_all_columns && window->DC.CurrentColumns) if (span_all_columns && window->DC.CurrentColumns)
PushColumnsBackground(); PushColumnsBackground();
else if ((flags & ImGuiSelectableFlags_SpanAllColumns) && g.CurrentTable) else if (span_all_columns && g.CurrentTable)
PushTableBackground(); PushTableBackground();
// We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries // We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries