7namespace LkEngine::UI {
9 FORCEINLINE
bool Property(
const char* Label,
bool& Value,
const char* HelpText =
"")
11 bool Modified =
false;
13 const bool IsCurrentlyInTable = InTable();
14 if (IsCurrentlyInTable)
16 ImGui::TableSetColumnIndex(0);
17 ShiftCursor(10.0f, 9.0f);
21 if (Label && Label[0] !=
'#')
24 if (std::strlen(HelpText) != 0)
31 if (IsCurrentlyInTable)
33 ImGui::TableSetColumnIndex(1);
42 ImGui::PushItemWidth(-1);
43 Modified = ImGui::Checkbox(LK_FMT_LIB::format(
"##{0}", Label).c_str(), &Value);
44 ImGui::PopItemWidth();
46 if (IsCurrentlyInTable)
48 ImGui::TableNextRow();
54 FORCEINLINE
bool Property(
const char* Label,
59 const char* HelpText =
"",
60 const char* HelpSymbol =
"(?)")
62 const bool IsCurrentlyInTable = InTable();
63 if (IsCurrentlyInTable)
65 ImGui::TableSetColumnIndex(0);
66 ShiftCursor(10.0f, 9.0f);
70 if (Label && Label[0] !=
'#')
73 if (std::strlen(HelpText) != 0)
76 HelpMarker(HelpText, HelpSymbol);
80 if (IsCurrentlyInTable)
82 ImGui::TableSetColumnIndex(1);
86 ImGui::PushItemWidth(-1);
87 const bool Modified = UI::Draw::DragFloat(LK_FMT_LIB::format(
"##{}", Label).c_str(), &Value, Delta, Min, Max);
88 ImGui::PopItemWidth();
90 if (IsCurrentlyInTable)
92 ImGui::TableNextRow();
101 FORCEINLINE
bool Property(
const char* Label,
106 const char* HelpText =
"")
108 ImGui::TableSetColumnIndex(0);
110 ShiftCursor(10.0f, 9.0f);
113 if (std::strlen(HelpText) != 0)
116 HelpMarker(HelpText);
119 ImGui::TableSetColumnIndex(1);
122 ImGui::PushItemWidth(-1);
123 const bool Modified = UI::Draw::DragFloat3(LK_FMT_LIB::format(
"##{0}", Label).c_str(), glm::value_ptr(Value), Delta, Min, Max);
124 ImGui::PopItemWidth();
126 ImGui::TableNextRow();
135 FORCEINLINE
bool PropertyLabel(
const char* Label,
const T Value,
const char* HelpText =
"")
142 const ImVec2 LabelSize = ImGui::CalcTextSize(Label);
143 const ImVec2 ValueSize = ImGui::CalcTextSize(LK_FMT_LIB::format(
"{}", Value).c_str());
145 ImGuiContext& G = *GImGui;
146 ImGuiTable* CurrentTable = ImGui::GetCurrentTable();
147 const bool IsInTable = (CurrentTable !=
nullptr);
151 ImGui::TableSetColumnIndex(0);
153 const float CenterPosX = (ImGui::GetContentRegionAvail().x * 0.50f);
154 ShiftCursorX(CenterPosX - (LabelSize.x * 0.50f));
159 ShiftCursor(10.0f, 0.0f);
163 if (std::strlen(HelpText) != 0)
166 HelpMarker(HelpText);
171 ImGui::TableSetColumnIndex(1);
174 if (CurrentTable->Flags & ImGuiTableFlags_SizingStretchProp)
176 ShiftCursorX(G.Style.FramePadding.x * 2.0f);
180 const float CenterPosX = (ImGui::GetContentRegionAvail().x * 0.50f);
181 ShiftCursorX(CenterPosX - (ValueSize.x * 0.50f));
184 ImGui::PushItemWidth(-1);
185 ImGui::Text(
"%s", LK_FMT_LIB::format(
"{}", Value).c_str());
186 ImGui::PopItemWidth();
188 ImGui::TableNextRow();
192 ShiftCursor(10.0f, 0.0f);
193 ImGui::PushItemWidth(-1);
194 ImGui::Text(
"%s", LK_FMT_LIB::format(
"{}", Value).c_str());
195 ImGui::PopItemWidth();
201 FORCEINLINE
bool BeginCombo(
const char* Label,
const char* PreviewValue, ImGuiComboFlags Flags = ImGuiComboFlags_None)
203 const bool Opened = ImGui::BeginCombo(Label, PreviewValue, Flags);
204 DrawItemActivityOutline();
209 FORCEINLINE
void EndCombo()
212 UIContext.NextItemData.ComboFlags = ImGuiComboFlags_None;
215 template<
typename TEnum>
216 FORCEINLINE
bool PropertyDropdown(
const char* Label,
217 const char** Options,
218 const uint16_t ArrSize,
220 const char* HelpText =
"")
222 using T = std::underlying_type_t<TEnum>;
223 const T SelectedIndex =
static_cast<std::underlying_type_t<TEnum>
>(Selected);
225 const char* CurrentOption = Options[SelectedIndex];
226 ShiftCursor(10.0f, 9.0f);
229 if (std::strlen(HelpText) != 0)
232 HelpMarker(HelpText);
237 ImGui::PushItemWidth(-1);
239 bool Modified =
false;
241 const std::string ID = LK_FMT_LIB::format(
"##{}", Label);
242 if (UI::BeginCombo(ID.c_str(), CurrentOption))
244 for (uint16_t Idx = 0; Idx < ArrSize; Idx++)
246 const bool IsSelected = (CurrentOption == Options[Idx]);
247 if (ImGui::Selectable(Options[Idx], IsSelected))
249 CurrentOption = Options[Idx];
250 Selected =
static_cast<TEnum
>(Idx);
256 ImGui::SetItemDefaultFocus();
263 ImGui::PopItemWidth();
270 template<std::
size_t ArrSize,
typename T,
typename TEnum>
271 FORCEINLINE
bool PropertyDropdown(
const char* Label,
272 const std::array<T, ArrSize>& Options,
274 const char* HelpText =
"",
275 const int ComboWidth = -1)
277 using ValueType = std::remove_cvref_t<T>;
278 static_assert((std::is_same_v<ValueType, const char*> || Core::IsPair<ValueType>),
"Unsupported type");
280 using PrimitiveType = std::underlying_type_t<TEnum>;
281 const PrimitiveType SelectedIndex =
static_cast<PrimitiveType
>(Selected);
283 const char* CurrentOption =
nullptr;
284 if constexpr (std::is_same_v<ValueType, const char*>)
286 CurrentOption = Options.at(SelectedIndex);
288 else if constexpr (Core::IsPair<ValueType>)
290 static_assert(Core::IsPairWithFirstArgConstChar<ValueType>,
"The first pair argument (the label) is not const char*, which is required");
292 CurrentOption = Options.at(SelectedIndex).first;
295 ImGuiContext& G = *GImGui;
296 const float NextItemWidth = G.NextItemData.Width;
298 ImGuiTable* CurrentTable = ImGui::GetCurrentTable();
299 const bool IsInTable = (CurrentTable !=
nullptr);
301 if (UIContext.bInGrid)
303 ImGui::TableSetColumnIndex(0);
305 if (std::strlen(HelpText) != 0)
308 HelpMarker(HelpText);
314 if (std::strlen(HelpText) != 0)
317 HelpMarker(HelpText);
322 ShiftCursor((2.0f + G.Style.FramePadding.x), (G.Style.FramePadding.y * 1.0f));
324 if (std::strlen(HelpText) != 0)
327 HelpMarker(HelpText);
331 if (UIContext.bInGrid)
333 ImGui::TableSetColumnIndex(1);
341 ShiftCursorY(-G.Style.FramePadding.y * 0.50f);
344 if (NextItemWidth > 0.0f)
346 ImGui::PushItemWidth(NextItemWidth);
350 ImGui::PushItemWidth(ComboWidth);
354 bool Modified =
false;
356 ImGuiComboFlags ComboFlags = ImGuiComboFlags_None;
357 if (Options.size() > 30)
359 ComboFlags |= ImGuiComboFlags_HeightLarge;
361 ComboFlags |= UIContext.NextItemData.ComboFlags;
363 const std::string ID = LK_FMT_LIB::format(
"##{}", Label);
364 if (UI::BeginCombo(ID.c_str(), CurrentOption, ComboFlags))
366 for (uint16_t Idx = 0; Idx < ArrSize; Idx++)
368 const char* Option =
nullptr;
369 if constexpr (std::is_same_v<ValueType, const char*>)
371 Option = Options[Idx];
373 else if constexpr (Core::IsPair<ValueType>)
375 Option = Options.at(Idx).first;
378 const bool IsSelected = (Option == CurrentOption);
379 if (ImGui::Selectable(Option, IsSelected))
381 CurrentOption = Options[Idx];
382 Selected =
static_cast<TEnum
>(Idx);
388 ImGui::SetItemDefaultFocus();
395 ImGui::PopItemWidth();
400 FORCEINLINE
bool PropertyDropdown(
const char* Label,
401 const char*
const* Options,
402 const uint16_t ArrSize,
404 const char* HelpText =
"",
405 const int ComboWidth = -1)
407 ImGuiContext& G = *GImGui;
408 const float NextItemWidth = G.NextItemData.Width;
410 ImGuiTable* CurrentTable = ImGui::GetCurrentTable();
411 const bool IsInTable = (CurrentTable !=
nullptr);
413 if (UIContext.bInGrid)
415 ImGui::TableSetColumnIndex(0);
425 const char* CurrentOption = Options[*Selected];
428 if (Label && Label[0] !=
'#')
431 if (std::strlen(HelpText) != 0)
434 HelpMarker(HelpText);
438 if (UIContext.bInGrid)
440 ImGui::TableSetColumnIndex(1);
447 ImGui::SameLine(0.0f, 4.0f);
450 if (NextItemWidth > 0.0f)
452 ImGui::PushItemWidth(NextItemWidth);
456 ImGui::PushItemWidth(ComboWidth);
459 bool Modified =
false;
461 ImGuiComboFlags ComboFlags = ImGuiComboFlags_None;
464 ComboFlags |= ImGuiComboFlags_HeightLarge;
466 ComboFlags |= UIContext.NextItemData.ComboFlags;
468 const std::string ID = LK_FMT_LIB::format(
"##{}", Label);
469 if (UI::BeginCombo(ID.c_str(), CurrentOption, ComboFlags))
471 for (uint16_t Idx = 0; Idx < ArrSize; Idx++)
473 const bool IsSelected = (CurrentOption == Options[Idx]);
474 if (ImGui::Selectable(Options[Idx], IsSelected))
476 CurrentOption = Options[Idx];
483 ImGui::SetItemDefaultFocus();
490 ImGui::PopItemWidth();
492 if (UIContext.bInGrid)
494 ImGui::TableNextRow();
507 template<std::
size_t ArrSize,
typename T>
508 FORCEINLINE
bool PropertyDropdown(
const char* Label,
509 const std::array<T, ArrSize>& Options,
511 const char* HelpText =
"",
512 const int ComboWidth = -1)
514 using ValueType = std::remove_cvref_t<T>;
515 static_assert((std::is_same_v<ValueType, const char*> || Core::IsPair<ValueType>),
"The type used in the array is not supported");
517 ImGuiContext& G = *GImGui;
518 const float NextItemWidth = G.NextItemData.Width;
520 ImGuiTable* CurrentTable = ImGui::GetCurrentTable();
521 const bool IsInTable = (CurrentTable !=
nullptr);
523 if (UIContext.bInGrid)
525 ImGui::TableSetColumnIndex(0);
526 UI::ShiftCursorX(Slider::TablePaddingX);
535 const char* CurrentOption =
nullptr;
536 if constexpr (std::is_same_v<ValueType, const char*>)
538 CurrentOption = Options.at(*Selected);
540 else if constexpr (Core::IsPair<ValueType>)
542 static_assert(Core::IsPairWithFirstArgConstChar<ValueType>,
"The first pair argument (the label) is not const char*, which is required");
544 CurrentOption = Options.at(*Selected).first;
548 if (Label && Label[0] !=
'#')
551 if (std::strlen(HelpText) != 0)
554 HelpMarker(HelpText);
558 if (UIContext.bInGrid)
560 ImGui::TableSetColumnIndex(1);
567 ImGui::SameLine(0.0f, 4.0f);
570 if (NextItemWidth > 0.0f)
572 ImGui::PushItemWidth(NextItemWidth);
576 ImGui::PushItemWidth(ComboWidth);
579 bool Modified =
false;
581 ImGuiComboFlags ComboFlags = ImGuiComboFlags_None;
582 if (Options.size() > 30)
584 ComboFlags |= ImGuiComboFlags_HeightLarge;
586 ComboFlags |= UIContext.NextItemData.ComboFlags;
588 const std::string ID = LK_FMT_LIB::format(
"##{}", Label);
589 if (UI::BeginCombo(ID.c_str(), CurrentOption, ComboFlags))
591 for (uint16_t Idx = 0; Idx < ArrSize; Idx++)
593 const char* Option =
nullptr;
594 if constexpr (std::is_same_v<ValueType, const char*>)
596 Option = Options[Idx];
598 else if constexpr (Core::IsPair<ValueType>)
600 Option = Options.at(Idx).first;
603 const ImVec2 LabelSize = ImGui::CalcTextSize(Option);
605 const bool IsSelected = (Option == CurrentOption);
606 if (ImGui::Selectable(Option, IsSelected, ImGuiSelectableFlags_None, ImVec2(0.0f, LabelSize.y + G.Style.FramePadding.y * 1.50f)))
608 CurrentOption = Option;
615 ImGui::SetItemDefaultFocus();
622 ImGui::PopItemWidth();
624 if (UIContext.bInGrid)
626 ImGui::TableNextRow();