LkEngine 0.1.2
 
Loading...
Searching...
No Matches
Style.h
1#pragma once
2
3#include "LkEngine/Renderer/UI/Font.h"
4
5
6namespace LkEngine::UI {
7
13 enum class EStyle : uint32_t
14 {
15 AlignHorizontal,
16 COUNT
17 };
18 LK_ENUM_CLASS(EStyle);
19
20
22 {
23 public:
24 template<typename T>
25 FORCEINLINE FScopedStyle(const ImGuiStyleVar StyleVar, const T Value) { ImGui::PushStyleVar(StyleVar, Value); }
26 ~FScopedStyle() { ImGui::PopStyleVar(); }
27 FScopedStyle(const FScopedStyle&) = delete;
28 FScopedStyle& operator=(const FScopedStyle&) = delete;
29 };
30
32 {
33 public:
34 template<typename T>
35 FORCEINLINE FScopedColor(const ImGuiCol ColorID, const T Color) { ImGui::PushStyleColor(ColorID, ImColor(Color).Value); }
36 ~FScopedColor() { ImGui::PopStyleColor(); }
37 FScopedColor(const FScopedColor&) = delete;
38 FScopedColor& operator=(const FScopedColor&) = delete;
39 };
40
42 {
43 public:
44 template<typename T>
45 FORCEINLINE FScopedID(const T ID) { ImGui::PushID(ID); }
46 ~FScopedID() { ImGui::PopID(); }
47 FScopedID(const FScopedID&) = delete;
48 FScopedID& operator=(const FScopedID&) = delete;
49 };
50
52 {
53 public:
54 template <typename ColorType, typename... OtherColors>
55 FORCEINLINE FScopedColorStack(const ImGuiCol FirstColorID,
56 const ColorType FirstColor,
57 OtherColors&&... OtherColorPairs)
58 : Count((sizeof... (OtherColorPairs) / 2) + 1)
59 {
60 static_assert((sizeof... (OtherColorPairs) & 1u) == 0, "FScopedColorStack expects a list of pairs of color IDs and colors");
61 PushColor(FirstColorID, FirstColor, std::forward<OtherColors>(OtherColorPairs)...);
62 }
63
64 ~FScopedColorStack() { ImGui::PopStyleColor(Count); }
65 FScopedColorStack(const FScopedColorStack&) = delete;
66 FScopedColorStack& operator=(const FScopedColorStack&) = delete;
67
68 private:
69 int Count = 0;
70
71 template <typename ColorType, typename... OtherColors>
72 FORCEINLINE void PushColor(const ImGuiCol ColorID,
73 const ColorType Color,
74 OtherColors&& ... OtherColorPairs)
75 {
76 if constexpr (sizeof... (OtherColorPairs) == 0)
77 {
78 ImGui::PushStyleColor(ColorID, ImColor(Color).Value);
79 }
80 else
81 {
82 ImGui::PushStyleColor(ColorID, ImColor(Color).Value);
83 PushColor(std::forward<OtherColors>(OtherColorPairs)...);
84 }
85 }
86 };
87
89 {
90 public:
91 template<typename ValueType, typename... OtherStylePairs>
92 FORCEINLINE FScopedStyleStack(const ImGuiStyleVar FirstStyleVar,
93 const ValueType FirstValue,
94 OtherStylePairs&& ... OtherPairs)
95 : StackCount((sizeof...(OtherPairs) / 2) + 1)
96 {
97 static_assert((sizeof...(OtherPairs) & 1u) == 0);
98 PushStyle(FirstStyleVar, FirstValue, std::forward<OtherStylePairs>(OtherPairs)...);
99 }
100
101 ~FScopedStyleStack() { ImGui::PopStyleVar(StackCount); }
102 FScopedStyleStack(const FScopedStyleStack&) = delete;
103 FScopedStyleStack& operator=(const FScopedStyleStack&) = delete;
104
105 private:
106 int StackCount = 0;
107
108 template<typename ValueType, typename... OtherStylePairs>
109 FORCEINLINE void PushStyle(const ImGuiStyleVar StyleVar,
110 const ValueType Value,
111 OtherStylePairs&& ... OtherPairs)
112 {
113 if constexpr (sizeof...(OtherPairs) == 0)
114 {
115 ImGui::PushStyleVar(StyleVar, Value);
116 }
117 else
118 {
119 ImGui::PushStyleVar(StyleVar, Value);
120 PushStyle(std::forward<OtherStylePairs>(OtherPairs)...);
121 }
122 }
123 };
124
126 {
127 public:
128 FORCEINLINE FScopedFont(ImFont* Font) { ImGui::PushFont(Font); }
129 ~FScopedFont() { ImGui::PopFont(); }
130 FScopedFont(const FScopedFont&) = delete;
131 FScopedFont& operator=(const FScopedFont&) = delete;
132 };
133
135 {
136 private:
137 using T = std::underlying_type_t<EStyle>;
138 public:
139 T VarIdx;
140 union
141 {
142 int ArrInt[2];
143 float ArrFloat[2];
144 };
145
146 FStyleMod(const EStyle Style, const int Value)
147 : VarIdx((T)Style)
148 {
149 ArrInt[0] = Value;
150 }
151
152 FStyleMod(const EStyle Style, const float Value)
153 : VarIdx((T)Style)
154 {
155 ArrFloat[0] = Value;
156 }
157
158 FStyleMod(const EStyle Style, const LVector2& Value)
159 : VarIdx((T)Style)
160 {
161 ArrFloat[0] = Value.X;
162 ArrFloat[1] = Value.Y;
163 }
164 };
165
169 struct LStyle
170 {
171 float AlignHorizontal = -1.0f; /* Disabled when -1.0 */
172 };
173
174 FORCEINLINE ImColor ColorWithMultipliedValue(const ImColor& Color, const float Multiplier)
175 {
176 const ImVec4& ColorRaw = Color.Value;
177 float Hue, Saturation, Value;
178 ImGui::ColorConvertRGBtoHSV(ColorRaw.x, ColorRaw.y, ColorRaw.z, Hue, Saturation, Value);
179 return ImColor::HSV(Hue, Saturation, std::min(Value * Multiplier, 1.0f));
180 }
181
182 FORCEINLINE ImColor ColorWithMultipliedSaturation(const ImColor& Color, const float Multiplier)
183 {
184 const ImVec4& ColorRaw = Color.Value;
185 float Hue, Saturation, Value;
186 ImGui::ColorConvertRGBtoHSV(ColorRaw.x, ColorRaw.y, ColorRaw.z, Hue, Saturation, Value);
187 return ImColor::HSV(Hue, std::min(Saturation * Multiplier, 1.0f), Value);
188 }
189
190 FORCEINLINE ImColor ColorWithMultipliedHue(const ImColor& Color, const float Multiplier)
191 {
192 const ImVec4& ColorRaw = Color.Value;
193 float Hue, Saturation, Value;
194 ImGui::ColorConvertRGBtoHSV(ColorRaw.x, ColorRaw.y, ColorRaw.z, Hue, Saturation, Value);
195 return ImColor::HSV(std::min(Hue * Multiplier, 1.0f), Saturation, Value);
196 }
197
198}
Definition Style.h:52
Definition Style.h:32
Definition Style.h:126
Definition Style.h:42
Definition Style.h:89
Definition Style.h:22
Definition Style.h:135
Definition Style.h:170