LkEngine 0.1.2
 
Loading...
Searching...
No Matches
UICore.h
Go to the documentation of this file.
1
5#pragma once
6
11#include <imgui/imgui.h>
12#include <imgui/imgui_internal.h>
13
14#include <glm/glm.hpp>
15
16#include "Font.h"
18#include "LkEngine/Scene/Components.h"
19
20#if defined(LK_ENGINE_OPENGL)
21# include "LkEngine/Renderer/Backend/OpenGL/OpenGLTexture.h"
22#endif
23
24#include "ImGuiFwd.h"
25
26#define LK_UI_DEBUG_DOCKNODES 0
27#define LK_UI_DEBUG_WINDOWS_ON_HOVER 0
28#include "UIDebug.h"
29
30#include "Style.h"
31
32namespace LkEngine
33{
34 class LWindow;
35 class LEntity;
36
43 namespace PanelID
44 {
45 static constexpr const char* CoreViewport = "##LkEngine-CoreViewport";
46 static constexpr const char* Dockspace = "##LkEngine-DockSpace";
47 static constexpr const char* EditorViewport = "##LkEngine-EditorViewport";
48 static constexpr const char* TopBar = "##LkEngine-TopBar";
49 static constexpr const char* BottomBar = "##LkEngine-BottomBar";
50 static constexpr const char* Sidebar1 = "Sidebar##1";
51 static constexpr const char* Sidebar2 = "Sidebar##2";
52 static constexpr const char* ApplicationSettings = "Application Settings";
53 static constexpr const char* EditorSettings = "Editor Settings";
54 static constexpr const char* EditorConsole = "Log##EditorConsole";
55 static constexpr const char* ContentBrowser = "Content Browser";
56 static constexpr const char* SceneManager = "Scene Manager";
57 static constexpr const char* ComponentEditor = "Component Editor";
58 static constexpr const char* Tools = "Tools";
59 static constexpr const char* MaterialEditor = "Material Editor";
60 static constexpr const char* ThemeManager = "Theme Manager";
61 static constexpr const char* NodeEditor = "Node Editor";
62 }
63
64 enum class EMessageBoxFlag : uint32_t
65 {
66 OkButton = LK_BIT(0),
67 CancelButton = LK_BIT(1),
68 UserFunction = LK_BIT(2),
69 AutoSize = LK_BIT(3),
70 };
71 LK_ENUM_CLASS(EMessageBoxFlag);
72 LK_ENUM_RANGE_FLAGS_BY_FIRST_AND_LAST(EMessageBoxFlag, EMessageBoxFlag::OkButton, EMessageBoxFlag::AutoSize);
73
78 LK_DECLARE_MULTICAST_DELEGATE(FOnSetPanelOpen, const char*, const bool);
79 extern FOnSetPanelOpen OnSetPanelOpen;
80
85 LK_DECLARE_DELEGATE_RET(FIsPanelOpen, bool, const char*);
86 extern FIsPanelOpen IsPanelOpen;
87
88}
89
90namespace LkEngine::UI {
91
92 LK_DECLARE_MULTICAST_DELEGATE(FOnMessageBoxCancelled, const char* /* UI Element Name */);
93 extern FOnMessageBoxCancelled OnMessageBoxCancelled;
94
100 {
101 std::string Title = "";
102 std::string Body = "";
103 uint32_t Flags = 0;
104 uint32_t Width = 0;
105 uint32_t Height = 0;
106 uint32_t MinWidth = 0;
107 uint32_t MinHeight = 0;
108 uint32_t MaxWidth = -1;
109 uint32_t MaxHeight = -1;
110 std::function<void()> UserRenderFunction;
111 bool bShouldOpen = true;
112 bool bIsOpen = false;
113 };
114
115 enum class EBorder
116 {
117 None = 0,
118 Horizontal = LK_BIT(1),
119 Vertical = LK_BIT(2),
120 All = LK_BIT(3),
121 };
122 LK_ENUM_CLASS(EBorder);
123 /* FIXME: Need to fix the namespace nesting issue for LK_ENUM_RANGE_FLAGS */
124 //LK_ENUM_RANGE_FLAGS_BY_FIRST_AND_LAST(EBorder, EBorder::None, EBorder::Horizontal)
125
139 template<typename T>
140 using TPropertyMapping = std::pair<const char*, T>;
141
143 namespace Slider
144 {
145 static constexpr float MIN_UNLIMITED = 0.0f;
146 static constexpr float MAX_UNLIMITED = 0.0f;
147 }
148
149 template<typename T>
151 {
152 static constexpr T Min{};
153 static constexpr T Max{};
154 };
155
156 template<>
157 struct SizeConstraint<ImVec2>
158 {
159 static constexpr ImVec2 Min{ 0.0f, 0.0f };
160 static constexpr ImVec2 Max{ 9999.0f, 9999.0f };
161 };
162
163 namespace Internal
164 {
165 enum class EDataType : uint32_t
166 {
167 None,
168 S32, /* int32_t */
169 U32, /* uint32_t */
170 Float, /* float */
171 Double, /* double */
172 Bool, /* bool */
173 COUNT
174 };
175
177 {
178 EDataType Type = EDataType::None;
179 uint32_t Count = 0;
180 uint32_t Offset = 0;
181
182 FORCEINLINE void* GetVariablePtr(void* Parent) const
183 {
184 return (void*)((unsigned char*)Parent + Offset);
185 }
186 };
187
188 static const FVariableInfo StyleVarInfo[] =
189 {
190 { EDataType::Float, 1, (uint32_t)offsetof(LStyle, AlignHorizontal) },
191 };
192
194 {
195 float Dist = 0.0f;
196 uint16_t PassedElements = 0;
197 };
198
199 FORCEINLINE const FVariableInfo* GetVariableInfo(const EStyle Idx)
200 {
201 using T = std::underlying_type_t<std::decay_t<decltype(Idx)>>;
202 LK_CORE_ASSERT(((T)Idx >= 0) && (Idx < (T)(EStyle::COUNT)));
203 static_assert(LK_ARRAYSIZE(Internal::StyleVarInfo) == (std::underlying_type_t<EStyle>)EStyle::COUNT);
204 return &Internal::StyleVarInfo[(T)Idx];
205 }
206
207 int GetContextID();
208 }
209
211 {
212 std::vector<FStyleMod> StyleStack{};
213 std::unordered_map<std::string, FMessageBox> MessageBoxes{};
214 bool bInGrid = false;
215
217 {
218 ImGuiComboFlags ComboFlags = ImGuiComboFlags_None;
219 } NextItemData{};
220
221 LStyle Style;
222 };
223
224 static LUIContext UIContext;
225
226 FORCEINLINE void PushStyle(const EStyle Style, const float Value)
227 {
228 const Internal::FVariableInfo* VarInfo = Internal::GetVariableInfo(Style);
229 if (VarInfo->Type != Internal::EDataType::Float)
230 {
231 }
232
233 float* VarPtr = (float*)VarInfo->GetVariablePtr(&UIContext.Style);
234 UIContext.StyleStack.push_back(FStyleMod(Style, *VarPtr));
235 *VarPtr = Value;
236 }
237
238 FORCEINLINE void PopStyle(const int StylesToPop = 1)
239 {
240 LK_CORE_ASSERT(false, "TODO");
241 }
242
243 FORCEINLINE void SetNextComboFlags(const ImGuiComboFlags Flags)
244 {
245 UIContext.NextItemData.ComboFlags = Flags;
246 }
247
248 FORCEINLINE bool InTable()
249 {
250 return (ImGui::GetCurrentTable() != nullptr);
251 }
252
253 void ShowMessageBox(const char* Title,
254 const std::function<void()>& RenderFunction,
255 uint32_t Flags = (uint32_t)EMessageBoxFlag::AutoSize,
256 const uint32_t Width = 600,
257 const uint32_t Height = 0,
258 const uint32_t MinWidth = 140,
259 const uint32_t MinHeight = 60,
260 const uint32_t MaxWidth = -1,
261 const uint32_t MaxHeight = -1);
262
263 void RenderMessageBoxes();
264
265 const char* GenerateID();
266 void PushID();
267 void PopID();
268
269 void Separator(const ImVec2& Size, const ImVec4& Color);
270
271 bool IsInputEnabled();
272 bool IsMouseEnabled();
273 bool IsKeyboardEnabled();
274 void SetInputEnabled(const bool Enabled);
275 void SetMouseEnabled(const bool Enabled);
276
277 bool Begin(const char* WindowTitle, bool* Open = nullptr, const ImGuiWindowFlags WindowFlags = ImGuiWindowFlags_None);
278 void End();
279
280 void BeginViewport(TObjectPtr<LWindow> Window);
281
282 ImTextureID GetTextureID(TObjectPtr<LTexture2D> Texture);
283 ImGuiDockNode* FindCentralNode(const ImGuiID DockspaceID);
284
289 enum class EFindType
290 {
291 ID,
292 Name,
293 };
294
298 template<EFindType FindType = EFindType::Name, typename T = const char*>
299 FORCEINLINE bool IsWindowFocused(T Identifier, const bool CheckRootWindow = true)
300 {
301 LK_CORE_ASSERT(false);
302 return false;
303 }
304
305 template<>
306 FORCEINLINE bool IsWindowFocused(const char* WindowName, const bool CheckRootWindow)
307 {
308 ImGuiWindow* CurrentNavWindow = GImGui->NavWindow;
309 if (CheckRootWindow)
310 {
311 /* Get the nav window and not something else (like a table). */
312 ImGuiWindow* LastWindow = nullptr;
313 while (LastWindow != CurrentNavWindow)
314 {
315 LastWindow = CurrentNavWindow;
316 CurrentNavWindow = CurrentNavWindow->RootWindow;
317 }
318 }
319
320 return (CurrentNavWindow == ImGui::FindWindowByName(WindowName));
321 }
322
323 template<>
324 FORCEINLINE bool IsWindowFocused(const ImGuiID ID, const bool CheckRootWindow)
325 {
326 ImGuiWindow* CurrentNavWindow = GImGui->NavWindow;
327 if (CheckRootWindow)
328 {
329 /* Get the nav window and not something else (like a table). */
330 ImGuiWindow* LastWindow = nullptr;
331 while (LastWindow != CurrentNavWindow)
332 {
333 LastWindow = CurrentNavWindow;
334 CurrentNavWindow = CurrentNavWindow->RootWindow;
335 }
336 }
337
338 return (CurrentNavWindow == ImGui::FindWindowByID(ID));
339 }
340
344 template<EFindType FindType = EFindType::Name, typename T = const char*>
345 FORCEINLINE bool IsWindowDocked(T Identifier)
346 {
347 LK_CORE_ASSERT(false);
348 return false;
349 }
350
351 template<>
352 FORCEINLINE bool IsWindowDocked<EFindType::ID>(const ImGuiID ID)
353 {
354 if (ImGuiWindow* Window = ImGui::FindWindowByID(ID); Window != nullptr)
355 {
356 return (Window->DockNode != nullptr);
357 }
358
359 return false;
360 }
361
362 template<>
363 FORCEINLINE bool IsWindowDocked<EFindType::Name>(const char* WindowName)
364 {
365 if (ImGuiWindow* Window = ImGui::FindWindowByName(WindowName); Window != nullptr)
366 {
367 return (Window->DockNode != nullptr);
368 }
369
370 return false;
371 }
372
373 template<EFindType FindType = EFindType::Name, typename T = const char*>
374 FORCEINLINE bool IsWindowHovered(T Identifier)
375 {
376 LK_CORE_ASSERT(false);
377 return false;
378 }
379
380 template<>
381 FORCEINLINE bool IsWindowHovered<EFindType::Name>(const char* WindowName)
382 {
383 if (ImGuiWindow* Window = ImGui::FindWindowByName(WindowName); Window != nullptr)
384 {
385 ImGuiContext& G = *ImGui::GetCurrentContext();
386 return Window == G.HoveredWindow;
387 }
388
389 return false;
390 }
391
392 template<>
393 FORCEINLINE bool IsWindowHovered<EFindType::ID>(const ImGuiID ID)
394 {
395 if (ImGuiWindow* Window = ImGui::FindWindowByID(ID); Window != nullptr)
396 {
397 ImGuiContext& G = *ImGui::GetCurrentContext();
398 return Window == G.HoveredWindow;
399 }
400
401 return false;
402 }
403
404 template<EFindType FindType = EFindType::Name, typename T = const char*>
405 FORCEINLINE bool IsWindowAbove(T Window1, T Window2)
406 {
407 LK_CORE_ASSERT(false);
408 return false;
409 }
410
411 template<>
412 FORCEINLINE bool IsWindowAbove<EFindType::Name>(const char* Window1Name, const char* Window2Name)
413 {
414 ImGuiWindow* Window1 = ImGui::FindWindowByName(Window1Name);
415 ImGuiWindow* Window2 = ImGui::FindWindowByName(Window2Name);
416 if (Window1 && !Window2)
417 {
418 return true;
419 }
420 if (!Window1 && Window2)
421 {
422 return false;
423 }
424
425 ImGuiWindow* CurrentWindow = nullptr;
426 ImGuiContext& G = *ImGui::GetCurrentContext();
427 for (int Idx = G.Windows.Size - 1; Idx >= 0; Idx)
428 {
429 CurrentWindow = G.Windows[Idx];
430 if (CurrentWindow == Window1)
431 {
432 return true;
433 }
434 if (CurrentWindow == Window2)
435 {
436 return false;
437 }
438 }
439
440 return false;
441 }
442
443 template<>
444 FORCEINLINE bool IsWindowAbove<EFindType::ID>(const ImGuiID Window1ID, const ImGuiID Window2ID)
445 {
446 ImGuiWindow* Window1 = ImGui::FindWindowByID(Window1ID);
447 ImGuiWindow* Window2 = ImGui::FindWindowByID(Window2ID);
448 if (Window1 && !Window2)
449 {
450 return true;
451 }
452 if (!Window1 && Window2)
453 {
454 return false;
455 }
456
457 ImGuiWindow* CurrentWindow = nullptr;
458 ImGuiContext& G = *ImGui::GetCurrentContext();
459 for (int Idx = G.Windows.Size - 1; Idx >= 0; Idx)
460 {
461 CurrentWindow = G.Windows[Idx];
462 if (CurrentWindow == Window1)
463 {
464 return true;
465 }
466 if (CurrentWindow == Window2)
467 {
468 return false;
469 }
470 }
471
472 return false;
473 }
474
475 template<EFindType FindType = EFindType::Name, typename T = const char*>
476 FORCEINLINE bool IsAnyWindowAbove(T Window)
477 {
478 LK_CORE_ASSERT(false);
479 return false;
480 }
481
482 template<>
483 FORCEINLINE bool IsAnyWindowAbove<EFindType::Name>(const char* WindowName)
484 {
485 ImGuiWindow* Window = ImGui::FindWindowByName(WindowName);
486 if (!Window)
487 {
488 return false;
489 }
490
491 ImGuiContext& G = *ImGui::GetCurrentContext();
492 return ((G.WindowsFocusOrder.Size > 0) && (G.WindowsFocusOrder[G.WindowsFocusOrder.Size - 1]));
493 }
494
495 template<>
496 FORCEINLINE bool IsAnyWindowAbove<EFindType::ID>(const ImGuiID WindowID)
497 {
498 ImGuiWindow* Window = ImGui::FindWindowByID(WindowID);
499 if (!Window)
500 {
501 return false;
502 }
503
504 ImGuiContext& G = *ImGui::GetCurrentContext();
505 return ((G.WindowsFocusOrder.Size > 0) && (G.WindowsFocusOrder[G.WindowsFocusOrder.Size - 1]));
506 }
507
508 template<EFindType FindType = EFindType::Name, typename T = const char*>
509 FORCEINLINE ImGuiWindow* GetWindowAbove(T Window1, T Window2)
510 {
511 LK_CORE_ASSERT(false);
512 return nullptr;
513 }
514
515 template<>
516 FORCEINLINE ImGuiWindow* GetWindowAbove<EFindType::Name>(const char* Window1Name, const char* Window2Name)
517 {
518 ImGuiWindow* Window1 = ImGui::FindWindowByName(Window1Name);
519 ImGuiWindow* Window2 = ImGui::FindWindowByName(Window2Name);
520 if (Window1 && !Window2)
521 {
522 return Window1;
523 }
524 if (!Window1 && Window2)
525 {
526 return Window2;
527 }
528
529 ImGuiWindow* CurrentWindow = nullptr;
530 ImGuiContext& G = *ImGui::GetCurrentContext();
531 for (int Idx = G.Windows.Size - 1; Idx >= 0; Idx)
532 {
533 CurrentWindow = G.Windows[Idx];
534 if (CurrentWindow == Window1)
535 {
536 return Window1;
537 }
538 if (CurrentWindow == Window2)
539 {
540 return Window2;
541 }
542 }
543
544 return nullptr;
545 }
546
547 template<>
548 FORCEINLINE ImGuiWindow* GetWindowAbove<EFindType::ID>(const ImGuiID Window1ID, const ImGuiID Window2ID)
549 {
550 ImGuiWindow* Window1 = ImGui::FindWindowByID(Window1ID);
551 ImGuiWindow* Window2 = ImGui::FindWindowByID(Window2ID);
552 if (Window1 && !Window2)
553 {
554 return Window1;
555 }
556 if (!Window1 && Window2)
557 {
558 return Window2;
559 }
560
561 ImGuiWindow* CurrentWindow = nullptr;
562 ImGuiContext& G = *ImGui::GetCurrentContext();
563 for (int Idx = G.Windows.Size - 1; Idx >= 0; Idx)
564 {
565 CurrentWindow = G.Windows[Idx];
566 if (CurrentWindow == Window1)
567 {
568 return Window1;
569 }
570 if (CurrentWindow == Window2)
571 {
572 return Window2;
573 }
574 }
575
576 return nullptr;
577 }
578
582 template<EFindType FindType = EFindType::Name, typename T = const char*>
583 FORCEINLINE ImVec2 GetWindowSize(T Identifier)
584 {
585 LK_CORE_ASSERT(false);
586 return ImVec2();
587 }
588
589 template<>
590 FORCEINLINE ImVec2 GetWindowSize<EFindType::ID>(const ImGuiID ID)
591 {
592 if (ImGuiWindow* Window = ImGui::FindWindowByID(ID); Window != nullptr)
593 {
594 return Window->Size;
595 }
596
597 return ImVec2();
598 }
599
600 template<>
601 FORCEINLINE ImVec2 GetWindowSize<EFindType::Name>(const char* WindowName)
602 {
603 if (ImGuiWindow* Window = ImGui::FindWindowByName(WindowName); Window != nullptr)
604 {
605 return Window->Size;
606 }
607
608 return ImVec2();
609 }
610
611 FORCEINLINE ImGuiID GetWindowID(const char* WindowName)
612 {
613 if (ImGuiWindow* Window = ImGui::FindWindowByName(WindowName); Window != nullptr)
614 {
615 return Window->ID;
616 }
617
618 return 0;
619 }
620
621 FORCEINLINE const char* GetWindowName(const ImGuiID ID)
622 {
623 if (ImGuiWindow* Window = ImGui::FindWindowByID(ID); Window != nullptr)
624 {
625 return Window->Name;
626 }
627
628 return "NULL";
629 }
630
631 FORCEINLINE bool IsItemDisabled()
632 {
633 return ImGui::GetItemFlags() & ImGuiItemFlags_Disabled;
634 }
635
636 FORCEINLINE bool IsItemHovered(const float DelayInSeconds = 0.10f, ImGuiHoveredFlags Flags = ImGuiHoveredFlags_None)
637 {
638 return ImGui::IsItemHovered() && (GImGui->HoveredIdTimer > DelayInSeconds); /* HoveredIdNotActiveTimer. */
639 }
640
641 FORCEINLINE ImRect GetItemRect()
642 {
643 return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
644 }
645
646 FORCEINLINE ImRect RectExpanded(const ImRect& Rect, const float x, const float y)
647 {
648 ImRect Result = Rect;
649 Result.Min.x -= x;
650 Result.Min.y -= y;
651 Result.Max.x += x;
652 Result.Max.y += y;
653 return Result;
654 }
655
656 FORCEINLINE ImRect RectOffset(const ImRect& Rect, const float x, const float y)
657 {
658 ImRect Result = Rect;
659 Result.Min.x += x;
660 Result.Min.y += y;
661 Result.Max.x += x;
662 Result.Max.y += y;
663 return Result;
664 }
665
666 FORCEINLINE void ShiftCursorX(const float Distance)
667 {
668 ImGui::SetCursorPosX(ImGui::GetCursorPosX() + Distance);
669 }
670
671 FORCEINLINE void ShiftCursorY(const float Distance)
672 {
673 ImGui::SetCursorPosY(ImGui::GetCursorPosY() + Distance);
674 }
675
676 FORCEINLINE void ShiftCursor(const float InX, const float InY)
677 {
678 const ImVec2 Cursor = ImGui::GetCursorPos();
679 ImGui::SetCursorPos(ImVec2(Cursor.x + InX, Cursor.y + InY));
680 }
681
682 FORCEINLINE void DrawItemActivityOutline()
683 {
684 /* TODO */
685 }
686
687 FORCEINLINE void HelpMarker(const char* HelpDesc, const char* HelpSymbol = "(?)")
688 {
689 static constexpr float WrapPosOffset = 35.0f;
690 ImGui::TextDisabled(HelpSymbol);
691 if (ImGui::IsItemHovered())
692 {
693 ImGui::BeginTooltip();
694 ImGui::PushTextWrapPos(ImGui::GetFontSize() * WrapPosOffset);
695 ImGui::TextUnformatted(HelpDesc);
696 ImGui::PopTextWrapPos();
697 ImGui::EndTooltip();
698 }
699 }
700
701 FORCEINLINE void SetTooltip(std::string_view Text,
702 const float DelayInSeconds = 0.10f,
703 const bool AllowWhenDisabled = true,
704 const ImVec2 Padding = ImVec2(5, 5))
705 {
706 if (IsItemHovered(DelayInSeconds, AllowWhenDisabled ? ImGuiHoveredFlags_AllowWhenDisabled : ImGuiHoveredFlags_None))
707 {
708 UI::FScopedStyle WindowPadding(ImGuiStyleVar_WindowPadding, Padding);
709 UI::FScopedColor TextColor(ImGuiCol_Text, RGBA32::Text::Brighter);
710 ImGui::SetTooltip(Text.data());
711 }
712 }
713
714 FORCEINLINE void PopupMenuHeader(const std::string& Text,
715 const bool IndentAfter = true,
716 const bool UnindentBefore = false)
717 {
718 if (UnindentBefore)
719 {
720 ImGui::Unindent();
721 }
722
723 static constexpr ImColor TextColor = ImColor(170, 170, 170);
724 ImGui::TextColored(TextColor.Value, Text.c_str());
725 ImGui::Separator();
726 if (IndentAfter)
727 {
728 ImGui::Indent();
729 }
730 };
731
732 FORCEINLINE void Separator(const ImVec2& Size, const ImVec4& Color)
733 {
734 ImGui::PushStyleColor(ImGuiCol_ChildBg, Color);
735 ImGui::BeginChild("##Separator", Size);
736 ImGui::EndChild();
737 ImGui::PopStyleColor();
738 }
739
740 FORCEINLINE void VSeparator(const float Height = 10.0f)
741 {
742 ImGui::Dummy(ImVec2(0, Height));
743 ImGui::Separator();
744 ImGui::Dummy(ImVec2(0, Height));
745 }
746
747 void Image(const TObjectPtr<LTexture2D>& texture,
748 const ImVec2& Size,
749 const ImVec2& UV0 = ImVec2(0, 0),
750 const ImVec2& UV1 = ImVec2(1, 1),
751 const ImVec4& TintColor = ImVec4(1, 1, 1, 1),
752 const ImVec4& BorderColor = ImVec4(0, 0, 0, 0));
753
754 void Image(const TObjectPtr<LTexture2D>& Image,
755 const glm::vec2& Size,
756 const glm::vec2& UV0 = glm::vec2(0, 0),
757 const glm::vec2& UV1 = glm::vec2(1, 1),
758 const glm::vec4& TintColor = glm::vec4(1, 1, 1, 1),
759 const glm::vec4& BorderColor = glm::vec4(0, 0, 0, 0));
760
761 void Image(const TObjectPtr<LImage2D>& Image,
762 const ImVec2& Size,
763 const ImVec2& UV0 = ImVec2(0, 0),
764 const ImVec2& UV1 = ImVec2(1, 1),
765 const ImVec4& TintColor = ImVec4(1, 1, 1, 1),
766 const ImVec4& BorderColor = ImVec4(0, 0, 0, 0));
767
768 void Image(const TObjectPtr<LImage2D>& Image,
769 const glm::vec2& Size,
770 const glm::vec2& UV0 = glm::vec2(0, 0),
771 const glm::vec2& UV1 = glm::vec2(1, 1),
772 const glm::vec4& TintColor = glm::vec4(1, 1, 1, 1),
773 const glm::vec4& BorderColor = glm::vec4(0, 0, 0, 0));
774
775
776 /****************************
777 * Flags *
778 ****************************/
779 inline static constexpr ImGuiDockNodeFlags DockspaceFlags = ImGuiDockNodeFlags_PassthruCentralNode
780 | ImGuiDockNodeFlags_NoDockingInCentralNode;
781
782 inline static ImGuiWindowFlags CoreViewportFlags = ImGuiWindowFlags_NoTitleBar
783 | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize
784 | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar
785 | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus
786 | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoInputs
787 | ImGuiWindowFlags_NoDocking;
788
789 inline static ImGuiWindowFlags HostWindowFlags = ImGuiWindowFlags_NoTitleBar
790 | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize
791 | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus
792 | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoInputs;
793
794 inline static constexpr ImGuiWindowFlags MenuBarFlags = ImGuiWindowFlags_MenuBar
795 | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoTitleBar
796 | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoCollapse;
797
798 inline static constexpr ImGuiWindowFlags SidebarFlags = ImGuiWindowFlags_NoTitleBar
799 | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus
800 | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoMove;
801
802 inline static constexpr ImGuiWindowFlags TabBarFlags = ImGuiWindowFlags_NoTitleBar
803 | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDocking
804 | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
805
806 inline static constexpr ImGuiWindowFlags EditorViewportFlags = ImGuiWindowFlags_NoTitleBar
807 | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar
808 | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoResize;
809
810 namespace Draw
811 {
812 FORCEINLINE void Underline(bool FullWidth = false, const float OffsetX = 0.0f, const float OffsetY = -1.0f)
813 {
814 if (FullWidth)
815 {
816 if (ImGui::GetCurrentWindow()->DC.CurrentColumns != nullptr)
817 {
818 ImGui::PushColumnsBackground();
819 }
820 else if (ImGui::GetCurrentTable() != nullptr)
821 {
822 ImGui::TablePushBackgroundChannel();
823 }
824 }
825
826 const float Width = FullWidth ? ImGui::GetWindowWidth() : ImGui::GetContentRegionAvail().x;
827 const ImVec2 Cursor = ImGui::GetCursorScreenPos();
828 ImGui::GetWindowDrawList()->AddLine(
829 ImVec2(Cursor.x + OffsetX, Cursor.y + OffsetY),
830 ImVec2(Cursor.x + Width, Cursor.y + OffsetY),
831 RGBA32::BackgroundDark,
832 1.0f
833 );
834
835 if (FullWidth)
836 {
837 if (ImGui::GetCurrentWindow()->DC.CurrentColumns != nullptr)
838 {
839 ImGui::PopColumnsBackground();
840 }
841 else if (ImGui::GetCurrentTable() != nullptr)
842 {
843 ImGui::TablePopBackgroundChannel();
844 }
845 }
846 }
847 }
848
849 FORCEINLINE void Spring(const float Weight = 1.0f)
850 {
851 const ImVec2 AvailableSpace = ImGui::GetContentRegionAvail();
852 const float SpringSize = AvailableSpace.x * Weight;
853 ImGui::Dummy(ImVec2(SpringSize, 0.0f));
854 }
855
856 FORCEINLINE void AlignHorizontalCenter(const float ItemWidth)
857 {
858 const ImVec2 AvailableSpace = ImGui::GetContentRegionAvail();
859 const float Offset = (AvailableSpace.x - ItemWidth) / 2.0f;
860 if (Offset > 0.0f)
861 {
862 ImGui::SetCursorPosX(ImGui::GetCursorPosX() + Offset);
863 }
864 }
865
866 FORCEINLINE bool ColoredButton(const char* Label, const ImVec4& BgColor, const ImVec2& ButtonSize)
867 {
868 FScopedColor ButtonCol(ImGuiCol_Button, BgColor);
869 return ImGui::Button(Label, ButtonSize);
870 }
871
872 FORCEINLINE bool ColoredButton(const char* Label, const ImVec4& BgColor, const ImVec4& FgColor, const ImVec2& ButtonSize)
873 {
874 FScopedColor TextColor(ImGuiCol_Text, FgColor);
875 FScopedColor ButtonColor(ImGuiCol_Button, BgColor);
876 return ImGui::Button(Label, ButtonSize);
877 }
878
879 FORCEINLINE void DrawButtonImage(const TObjectPtr<LTexture2D>& ImageNormal,
880 const TObjectPtr<LTexture2D>& ImageHovered,
881 const TObjectPtr<LTexture2D>& ImagePressed,
882 const ImU32 TintNormal,
883 const ImU32 TintHovered,
884 const ImU32 TintPressed,
885 const ImVec2& RectMin,
886 const ImVec2& RectMax)
887 {
888 ImDrawList* DrawList = ImGui::GetWindowDrawList();
889 if (ImGui::IsItemActive())
890 {
891 DrawList->AddImage(GetTextureID(ImagePressed), RectMin, RectMax, ImVec2(0, 0), ImVec2(1, 1), TintPressed);
892 }
893 else if (ImGui::IsItemHovered())
894 {
895 DrawList->AddImage(GetTextureID(ImageHovered), RectMin, RectMax, ImVec2(0, 0), ImVec2(1, 1), TintHovered);
896 }
897 else
898 {
899 DrawList->AddImage(GetTextureID(ImageNormal), RectMin, RectMax, ImVec2(0, 0), ImVec2(1, 1), TintNormal);
900 }
901 };
902
903 FORCEINLINE void DrawButtonImage(const TObjectPtr<LTexture2D>& Image,
904 const ImU32 TintNormal,
905 const ImU32 TintHovered,
906 const ImU32 TintPressed,
907 const ImRect& Rectangle)
908 {
909 DrawButtonImage(Image, Image, Image, TintNormal, TintHovered, TintPressed, Rectangle.Min, Rectangle.Max);
910 };
911
914}
Mathematical vectors.
void BeginViewport(TObjectPtr< LWindow > Window)
Definition UICore.cpp:118
EFindType
Definition UICore.h:290
FORCEINLINE bool IsWindowFocused(T Identifier, const bool CheckRootWindow=true)
Check if a window is focused, defaults to use the window name.
Definition UICore.h:299
FORCEINLINE bool IsWindowDocked(T Identifier)
Check if a window is docked, defaults to use the window name.
Definition UICore.h:345
std::pair< const char *, T > TPropertyMapping
Definition UICore.h:140
FORCEINLINE ImVec2 GetWindowSize(T Identifier)
Check if a window is docked, defaults to use the window name.
Definition UICore.h:583
Definition Asset.h:11
Data container for a message box instance.
Definition UICore.h:100
Definition UICore.h:194
Definition Style.h:170
Definition UICore.h:211
Definition UICore.h:151