mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 07:01:04 +01:00 
			
		
		
		
	Tables: Added TableSetBgColor() api with color for RowBg and CellBg colors.
This commit is contained in:
		@@ -3902,14 +3902,11 @@ static void ShowDemoWindowTables()
 | 
			
		||||
    if (ImGui::TreeNode("Row height"))
 | 
			
		||||
    {
 | 
			
		||||
        HelpMarker("You can pass a 'min_row_height' to TableNextRow().\n\nRows are padded with 'style.CellPadding.y' on top and bottom, so effectively the minimum row height will always be >= 'style.CellPadding.y * 2.0f'.\n\nWe cannot honor a _maximum_ row height as that would requires a unique clipping rectangle per row.");
 | 
			
		||||
        if (ImGui::BeginTable("##2ways", 2, ImGuiTableFlags_Borders))
 | 
			
		||||
        if (ImGui::BeginTable("##Table", 1, ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersInnerV))
 | 
			
		||||
        {
 | 
			
		||||
            float min_row_height = ImGui::GetFontSize() + ImGui::GetStyle().CellPadding.y * 2.0f;
 | 
			
		||||
            ImGui::TableNextRow(ImGuiTableRowFlags_None, min_row_height);
 | 
			
		||||
            ImGui::Text("min_row_height = %.2f", min_row_height);
 | 
			
		||||
            for (int row = 0; row < 10; row++)
 | 
			
		||||
            {
 | 
			
		||||
                min_row_height = (float)(int)(ImGui::GetFontSize() * 0.30f * row);
 | 
			
		||||
                float min_row_height = (float)(int)(ImGui::GetFontSize() * 0.30f * row);
 | 
			
		||||
                ImGui::TableNextRow(ImGuiTableRowFlags_None, min_row_height);
 | 
			
		||||
                ImGui::Text("min_row_height = %.2f", min_row_height);
 | 
			
		||||
            }
 | 
			
		||||
@@ -3918,6 +3915,61 @@ static void ShowDemoWindowTables()
 | 
			
		||||
        ImGui::TreePop();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (open_action != -1)
 | 
			
		||||
        ImGui::SetNextItemOpen(open_action != 0);
 | 
			
		||||
    if (ImGui::TreeNode("Background color"))
 | 
			
		||||
    {
 | 
			
		||||
        static ImGuiTableFlags table_flags = ImGuiTableFlags_RowBg;
 | 
			
		||||
        ImGui::CheckboxFlags("ImGuiTableFlags_Borders", (unsigned int*)&table_flags, ImGuiTableFlags_Borders);
 | 
			
		||||
        ImGui::CheckboxFlags("ImGuiTableFlags_RowBg", (unsigned int*)&table_flags, ImGuiTableFlags_RowBg);
 | 
			
		||||
        ImGui::SameLine(); HelpMarker("ImGuiTableFlags_RowBg automatically sets RowBg0 to alternative colors pulled from the Style.");
 | 
			
		||||
 | 
			
		||||
        static int row_bg_type = 1;
 | 
			
		||||
        static int row_bg_target = 1;
 | 
			
		||||
        static int cell_bg_type = 1;
 | 
			
		||||
        ImGui::Combo("row bg type", (int*)&row_bg_type, "None\0Red\0Gradient\0");
 | 
			
		||||
        ImGui::Combo("row bg target", (int*)&row_bg_target, "RowBg0\0RowBg1\0"); ImGui::SameLine(); HelpMarker("Target RowBg0 to override the alternating odd/even colors,\nTarget RowBg1 to blend with them.");
 | 
			
		||||
        ImGui::Combo("cell bg type", (int*)&cell_bg_type, "None\0Blue\0"); ImGui::SameLine(); HelpMarker("We are colorizing cells to B1->C2 here.");
 | 
			
		||||
        IM_ASSERT(row_bg_type >= 0 && row_bg_type <= 2);
 | 
			
		||||
        IM_ASSERT(row_bg_target >= 0 && row_bg_target <= 1);
 | 
			
		||||
        IM_ASSERT(cell_bg_type >= 0 && cell_bg_type <= 1);
 | 
			
		||||
 | 
			
		||||
        if (ImGui::BeginTable("##Table", 5, table_flags))
 | 
			
		||||
        {
 | 
			
		||||
            for (int row = 0; row < 6; row++)
 | 
			
		||||
            {
 | 
			
		||||
                ImGui::TableNextRow();
 | 
			
		||||
 | 
			
		||||
                // Demonstrate setting a row background color with 'ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBgX, ...)'
 | 
			
		||||
                // We use a transparent color so we can see the one behind in case our target is RowBg1 and RowBg0 was already targeted by the ImGuiTableFlags_RowBg flag.
 | 
			
		||||
                if (row_bg_type != 0)
 | 
			
		||||
                {
 | 
			
		||||
                    ImU32 row_bg_color = ImGui::GetColorU32(row_bg_type == 1 ? ImVec4(0.7f, 0.3f, 0.3f, 0.65f) : ImVec4(0.2f + row * 0.1f, 0.2f, 0.2f, 0.65f)); // Flat or Gradient?
 | 
			
		||||
                    ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0 + row_bg_target, row_bg_color);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Fill cells
 | 
			
		||||
                for (int column = 0; column < 5; column++)
 | 
			
		||||
                {
 | 
			
		||||
                    ImGui::TableSetColumnIndex(column);
 | 
			
		||||
                    ImGui::Text("%c%c", 'A' + row, '0' + column);
 | 
			
		||||
 | 
			
		||||
                    // Change background of Cells B1->C2
 | 
			
		||||
                    // Demonstrate setting a cell background color with 'ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ...)'
 | 
			
		||||
                    // (the CellBg color will be blended over the RowBg and ColumnBg colors)
 | 
			
		||||
                    // We can also pass a column number as a third parameter to TableSetBgColor() and do this outside the column loop.
 | 
			
		||||
                    if (row >= 1 && row <= 2 && column >= 1 && column <= 2 && cell_bg_type == 1)
 | 
			
		||||
                    {
 | 
			
		||||
                        ImU32 cell_bg_color = ImGui::GetColorU32(ImVec4(0.3f, 0.3f, 0.7f, 0.65f));
 | 
			
		||||
                        ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, cell_bg_color);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            ImGui::EndTable();
 | 
			
		||||
        }
 | 
			
		||||
        ImGui::TreePop();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (open_action != -1)
 | 
			
		||||
        ImGui::SetNextItemOpen(open_action != 0);
 | 
			
		||||
    if (ImGui::TreeNode("Tree view"))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user