| 1 | #pragma once |
| 2 | #include <imgui.h> |
| 3 | #include <cstdint> |
| 4 | #include <cctype> |
| 5 | #include <utility> |
| 6 | #include <vector> |
| 7 | #include <string> |
| 8 | #include <algorithm> |
| 9 | |
| 10 | |
| 11 | |
| 12 | namespace ImGui |
| 13 | { |
| 14 | |
| 15 | void ItemRowsBackground(float lineHeight = -1.0f, const ImColor &color = ImColor(20, 20, 20, 64)) |
| 16 | { |
| 17 | auto *drawList = ImGui::GetWindowDrawList(); |
| 18 | const auto &style = ImGui::GetStyle(); |
| 19 | |
| 20 | if (lineHeight < 0) |
| 21 | { |
| 22 | lineHeight = ImGui::GetTextLineHeight(); |
| 23 | } |
| 24 | lineHeight += style.ItemSpacing.y; |
| 25 | |
| 26 | float scrollOffsetH = ImGui::GetScrollX(); |
| 27 | float scrollOffsetV = ImGui::GetScrollY(); |
| 28 | float scrolledOutLines = floorf(scrollOffsetV / lineHeight); |
| 29 | scrollOffsetV -= lineHeight * scrolledOutLines; |
| 30 | |
| 31 | ImVec2 clipRectMin(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y); |
| 32 | ImVec2 clipRectMax(clipRectMin.x + ImGui::GetWindowWidth(), clipRectMin.y + ImGui::GetWindowHeight()); |
| 33 | |
| 34 | if (ImGui::GetScrollMaxX() > 0) |
| 35 | { |
| 36 | clipRectMax.y -= style.ScrollbarSize; |
| 37 | } |
| 38 | |
| 39 | drawList->PushClipRect(clipRectMin, clipRectMax); |
| 40 | |
| 41 | bool isOdd = (static_cast<int>(scrolledOutLines) % 2) == 0; |
| 42 | |
| 43 | float yMin = clipRectMin.y - scrollOffsetV + ImGui::GetCursorPosY(); |
| 44 | float yMax = clipRectMax.y - scrollOffsetV + lineHeight; |
| 45 | float xMin = clipRectMin.x + scrollOffsetH + ImGui::GetWindowContentRegionMin().x; |
| 46 | float xMax = clipRectMin.x + scrollOffsetH + ImGui::GetWindowContentRegionMax().x; |
| 47 | |
| 48 | for (float y = yMin; y < yMax; y += lineHeight, isOdd = !isOdd) |
| 49 | { |
| 50 | if (isOdd) |
| 51 | { |
| 52 | drawList->AddRectFilled({xMin, y - style.ItemSpacing.y}, {xMax, y + lineHeight}, color); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | drawList->PopClipRect(); |
| 57 | } |
| 58 | |
| 59 | } |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |