6#include "LkEngine/Editor/EditorGlobals.h"
8namespace LkEngine::UI {
10 FORCEINLINE
void BeginPropertyGrid(
const char* Label =
nullptr,
11 const ImVec2& Size = ImVec2(0.0f, 0.0f),
12 ImGuiTableFlags Flags = ImGuiTableFlags_SizingStretchProp,
13 const bool UseHeaderLabels =
false)
17 UIContext.bInGrid =
true;
19 if (UI::Debug::GridBorders & EBorder::Horizontal) Flags |= ImGuiTableFlags_BordersH;
20 if (UI::Debug::GridBorders & EBorder::Vertical) Flags |= ImGuiTableFlags_BordersV;
21 if (UI::Debug::GridBorders & EBorder::All) Flags |= ImGuiTableFlags_Borders;
23 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8.0f, 8.0f));
24 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4.0f, 4.0f));
25 if (!ImGui::BeginTable(Label ? Label : GenerateID(), 2, Flags, Size))
30 static constexpr ImGuiTableColumnFlags ColumnFlags = ImGuiTableColumnFlags_None;
31 for (uint32_t ColumnIdx = 0; ColumnIdx < 2; ColumnIdx++)
35 ImGui::TableSetupColumn(LK_FMT_LIB::format(
"Column-{}", ColumnIdx).c_str(), ColumnFlags);
39 ImGui::TableSetupColumn(LK_FMT_LIB::format(
"##Column-{}", ColumnIdx).c_str(), ColumnFlags);
45 ImGui::TableHeadersRow();
47 ImGui::TableNextRow();
50 FORCEINLINE
void EndPropertyGrid()
53 ImGui::PopStyleVar(2);
55 UIContext.bInGrid =
false;
60 FORCEINLINE
bool PropertyGridHeader(
const std::string& Name,
bool OpenByDefault =
true)
62 ImGuiTreeNodeFlags TreeNodeFlags = ImGuiTreeNodeFlags_Framed
63 | ImGuiTreeNodeFlags_SpanAvailWidth
64 | ImGuiTreeNodeFlags_AllowItemOverlap
65 | ImGuiTreeNodeFlags_FramePadding;
69 TreeNodeFlags |= ImGuiTreeNodeFlags_DefaultOpen;
72 static constexpr float FramePaddingX = 6.0f;
73 static constexpr float FramePaddingY = 6.0f;
75 UI::FScopedStyle HeaderRounding(ImGuiStyleVar_FrameRounding, 0.0f);
76 UI::FScopedStyle HeaderPaddingAndHeight(ImGuiStyleVar_FramePadding, ImVec2(FramePaddingX, FramePaddingY));
78 ImGui::PushID(Name.c_str());
79 UI::Font::Push(
"Bold");
80 const bool IsOpen = ImGui::TreeNodeEx(
"##DummyID", TreeNodeFlags, Name.c_str());
87 FORCEINLINE
void EndPropertyGridHeader()
93 static void Table(
const char* TableName,
95 const uint32_t ColumnCount,
99 if ((Size.x <= 0.0f) || (Size.y <= 0.0f))
104 static constexpr float EdgeOffset = 4.0f;
106 FScopedStyle CellPadding(ImGuiStyleVar_CellPadding, ImVec2(4.0f, 0.0f));
107 const ImColor BgColor = ImColor(RGBA32::Background);
108 const ImColor ColRowAlt = ColorWithMultipliedValue(BgColor, 1.29f);
110 FScopedColor RowColor(ImGuiCol_TableRowBg, BgColor);
111 FScopedColor RowAltColor(ImGuiCol_TableRowBgAlt, ColRowAlt);
112 FScopedColor TableColor(ImGuiCol_ChildBg, BgColor);
114 static constexpr ImGuiTableFlags TableFlags = ImGuiTableFlags_NoPadInnerX
115 | ImGuiTableFlags_Resizable
116 | ImGuiTableFlags_Reorderable
117 | ImGuiTableFlags_ScrollY
118 | ImGuiTableFlags_RowBg;
120 if (!ImGui::BeginTable(TableName, ColumnCount, TableFlags, Size))
126 const float CursorX = ImGui::GetCursorScreenPos().x;
128 for (uint32_t Idx = 0; Idx < ColumnCount; Idx++)
130 ImGui::TableSetupColumn(Columns[Idx]);
135 const ImColor ActiveColor = ColorWithMultipliedValue(BgColor, 1.35f);
136 FScopedColorStack HeaderCol(ImGuiCol_HeaderHovered, ActiveColor,
137 ImGuiCol_HeaderActive, ActiveColor);
139 ImGui::TableSetupScrollFreeze(ImGui::TableGetColumnCount(), 1);
140 ImGui::TableNextRow(ImGuiTableRowFlags_Headers, 24.0f);
142 for (uint32_t Idx = 0; Idx < ColumnCount; Idx++)
144 ImGui::TableSetColumnIndex(Idx);
145 const char* ColumnName = ImGui::TableGetColumnName(Idx);
146 ImGui::PushID(ColumnName);
153 UI::ShiftCursor(EdgeOffset * 3.0f, EdgeOffset * 1.0f);
154 ImGui::TableHeader(ColumnName);
155 UI::ShiftCursor(-EdgeOffset * 3.0f, -EdgeOffset * 1.0f);
160 ImGui::SetCursorScreenPos(ImVec2(CursorX, ImGui::GetCursorScreenPos().y));
168 template<
typename T, std::
size_t N>
169 static void Table(
const char* TableName,
170 const std::array<const char*, N>& Columns,
174 if ((Size.x <= 0.0f) || (Size.y <= 0.0f))
179 static constexpr float EdgeOffset = 4.0f;
181 FScopedStyle CellPadding(ImGuiStyleVar_CellPadding, ImVec2(4.0f, 0.0f));
182 const ImColor BgColor = ImColor(RGBA32::Background);
183 const ImColor ColRowAlt = ColorWithMultipliedValue(BgColor, 1.29f);
185 FScopedColor TableColor(ImGuiCol_ChildBg, BgColor);
186 FScopedColor RowColor(ImGuiCol_TableRowBg, BgColor);
187 FScopedColor RowAltColor(ImGuiCol_TableRowBgAlt, ColRowAlt);
189 static constexpr ImGuiTableFlags TableFlags = ImGuiTableFlags_NoPadInnerX
190 | ImGuiTableFlags_Resizable
191 | ImGuiTableFlags_Reorderable
192 | ImGuiTableFlags_ScrollY
193 | ImGuiTableFlags_RowBg;
195 if (!ImGui::BeginTable(TableName, N, TableFlags, Size))
201 const float CursorX = ImGui::GetCursorScreenPos().x;
203 for (uint32_t Idx = 0; Idx < N; Idx++)
205 ImGui::TableSetupColumn(Columns[Idx]);
210 const ImColor ActiveColor = ColorWithMultipliedValue(BgColor, 1.35f);
211 FScopedColorStack HeaderCol(
212 ImGuiCol_HeaderHovered, ActiveColor,
213 ImGuiCol_HeaderActive, ActiveColor
216 ImGui::TableSetupScrollFreeze(ImGui::TableGetColumnCount(), 1);
217 ImGui::TableNextRow(ImGuiTableRowFlags_Headers, 24.0f);
219 for (uint32_t Idx = 0; Idx < N; Idx++)
221 ImGui::TableSetColumnIndex(Idx);
222 const char* ColumnName = ImGui::TableGetColumnName(Idx);
223 ImGui::PushID(ColumnName);
230 UI::ShiftCursor(EdgeOffset * 3.0f, EdgeOffset * 1.0f);
231 ImGui::TableHeader(ColumnName);
232 UI::ShiftCursor(-EdgeOffset * 3.0f, -EdgeOffset * 1.0f);
237 ImGui::SetCursorScreenPos(ImVec2(CursorX, ImGui::GetCursorScreenPos().y));
246 bool TableRowClickable(
const char* RowID,
const float RowHeight);