- added imgui
[laserbrain_demo] / src / imgui / imgui_internal.h
1 // dear imgui, v1.53 WIP
2 // (internals)
3
4 // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility!
5 // Set:
6 //   #define IMGUI_DEFINE_MATH_OPERATORS
7 // To implement maths operators for ImVec2 (disabled by default to not collide with using IM_VEC2_CLASS_EXTRA along with your own math types+operators)
8
9 #pragma once
10
11 #ifndef IMGUI_VERSION
12 #error Must include imgui.h before imgui_internal.h
13 #endif
14
15 #include <stdio.h>      // FILE*
16 #include <math.h>       // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf
17
18 #ifdef _MSC_VER
19 #pragma warning (push)
20 #pragma warning (disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of struct 'xxx' // when IMGUI_API is set to__declspec(dllexport)
21 #endif
22
23 #ifdef __clang__
24 #pragma clang diagnostic push
25 #pragma clang diagnostic ignored "-Wunused-function"        // for stb_textedit.h
26 #pragma clang diagnostic ignored "-Wmissing-prototypes"     // for stb_textedit.h
27 #pragma clang diagnostic ignored "-Wold-style-cast"
28 #endif
29
30 //-----------------------------------------------------------------------------
31 // Forward Declarations
32 //-----------------------------------------------------------------------------
33
34 struct ImRect;
35 struct ImGuiColMod;
36 struct ImGuiStyleMod;
37 struct ImGuiGroupData;
38 struct ImGuiSimpleColumns;
39 struct ImGuiDrawContext;
40 struct ImGuiTextEditState;
41 struct ImGuiIniData;
42 struct ImGuiMouseCursorData;
43 struct ImGuiPopupRef;
44 struct ImGuiWindow;
45
46 typedef int ImGuiLayoutType;        // enum: horizontal or vertical             // enum ImGuiLayoutType_
47 typedef int ImGuiButtonFlags;       // flags: for ButtonEx(), ButtonBehavior()  // enum ImGuiButtonFlags_
48 typedef int ImGuiItemFlags;         // flags: for PushItemFlag()                // enum ImGuiItemFlags_
49 typedef int ImGuiSeparatorFlags;    // flags: for Separator() - internal        // enum ImGuiSeparatorFlags_
50 typedef int ImGuiSliderFlags;       // flags: for SliderBehavior()              // enum ImGuiSliderFlags_
51
52 //-------------------------------------------------------------------------
53 // STB libraries
54 //-------------------------------------------------------------------------
55
56 namespace ImGuiStb
57 {
58
59 #undef STB_TEXTEDIT_STRING
60 #undef STB_TEXTEDIT_CHARTYPE
61 #define STB_TEXTEDIT_STRING             ImGuiTextEditState
62 #define STB_TEXTEDIT_CHARTYPE           ImWchar
63 #define STB_TEXTEDIT_GETWIDTH_NEWLINE   -1.0f
64 #include "stb_textedit.h"
65
66 } // namespace ImGuiStb
67
68 //-----------------------------------------------------------------------------
69 // Context
70 //-----------------------------------------------------------------------------
71
72 #ifndef GImGui
73 extern IMGUI_API ImGuiContext* GImGui;  // Current implicit ImGui context pointer
74 #endif
75
76 //-----------------------------------------------------------------------------
77 // Helpers
78 //-----------------------------------------------------------------------------
79
80 #define IM_PI                       3.14159265358979323846f
81 #define IM_OFFSETOF(_TYPE,_ELM)     ((size_t)&(((_TYPE*)0)->_ELM))
82
83 // Helpers: UTF-8 <> wchar
84 IMGUI_API int           ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end);      // return output UTF-8 bytes count
85 IMGUI_API int           ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end);          // return input UTF-8 bytes count
86 IMGUI_API int           ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL);   // return input UTF-8 bytes count
87 IMGUI_API int           ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end);                            // return number of UTF-8 code-points (NOT bytes count)
88 IMGUI_API int           ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end);                   // return number of bytes to express string as UTF-8 code-points
89
90 // Helpers: Misc
91 IMGUI_API ImU32         ImHash(const void* data, int data_size, ImU32 seed = 0);    // Pass data_size==0 for zero-terminated strings
92 IMGUI_API void*         ImFileLoadToMemory(const char* filename, const char* file_open_mode, int* out_file_size = NULL, int padding_bytes = 0);
93 IMGUI_API FILE*         ImFileOpen(const char* filename, const char* file_open_mode);
94 static inline bool      ImCharIsSpace(int c)            { return c == ' ' || c == '\t' || c == 0x3000; }
95 static inline bool      ImIsPowerOfTwo(int v)           { return v != 0 && (v & (v - 1)) == 0; }
96 static inline int       ImUpperPowerOfTwo(int v)        { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
97
98 // Helpers: Geometry
99 IMGUI_API ImVec2        ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p);
100 IMGUI_API bool          ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p);
101 IMGUI_API ImVec2        ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p);
102 IMGUI_API void          ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w);
103
104 // Helpers: String
105 IMGUI_API int           ImStricmp(const char* str1, const char* str2);
106 IMGUI_API int           ImStrnicmp(const char* str1, const char* str2, int count);
107 IMGUI_API void          ImStrncpy(char* dst, const char* src, int count);
108 IMGUI_API char*         ImStrdup(const char* str);
109 IMGUI_API int           ImStrlenW(const ImWchar* str);
110 IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line
111 IMGUI_API const char*   ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end);
112 IMGUI_API int           ImFormatString(char* buf, int buf_size, const char* fmt, ...) IM_FMTARGS(3);
113 IMGUI_API int           ImFormatStringV(char* buf, int buf_size, const char* fmt, va_list args) IM_FMTLIST(3);
114
115 // Helpers: Math
116 // We are keeping those not leaking to the user by default, in the case the user has implicit cast operators between ImVec2 and its own types (when IM_VEC2_CLASS_EXTRA is defined)
117 #ifdef IMGUI_DEFINE_MATH_OPERATORS
118 static inline ImVec2 operator*(const ImVec2& lhs, const float rhs)              { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
119 static inline ImVec2 operator/(const ImVec2& lhs, const float rhs)              { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
120 static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs)            { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
121 static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs)            { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
122 static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs)            { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
123 static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs)            { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
124 static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs)                { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
125 static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs)                { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
126 static inline ImVec2& operator*=(ImVec2& lhs, const float rhs)                  { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
127 static inline ImVec2& operator/=(ImVec2& lhs, const float rhs)                  { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
128 static inline ImVec4 operator+(const ImVec4& lhs, const ImVec4& rhs)            { return ImVec4(lhs.x+rhs.x, lhs.y+rhs.y, lhs.z+rhs.z, lhs.w+rhs.w); }
129 static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs)            { return ImVec4(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z, lhs.w-rhs.w); }
130 static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs)            { return ImVec4(lhs.x*rhs.x, lhs.y*rhs.y, lhs.z*rhs.z, lhs.w*rhs.w); }
131 #endif
132
133 static inline int    ImMin(int lhs, int rhs)                                    { return lhs < rhs ? lhs : rhs; }
134 static inline int    ImMax(int lhs, int rhs)                                    { return lhs >= rhs ? lhs : rhs; }
135 static inline float  ImMin(float lhs, float rhs)                                { return lhs < rhs ? lhs : rhs; }
136 static inline float  ImMax(float lhs, float rhs)                                { return lhs >= rhs ? lhs : rhs; }
137 static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs)                { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); }
138 static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs)                { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); }
139 static inline int    ImClamp(int v, int mn, int mx)                             { return (v < mn) ? mn : (v > mx) ? mx : v; }
140 static inline float  ImClamp(float v, float mn, float mx)                       { return (v < mn) ? mn : (v > mx) ? mx : v; }
141 static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx)      { return ImVec2(ImClamp(f.x,mn.x,mx.x), ImClamp(f.y,mn.y,mx.y)); }
142 static inline float  ImSaturate(float f)                                        { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
143 static inline void   ImSwap(int& a, int& b)                                     { int tmp = a; a = b; b = tmp; }
144 static inline void   ImSwap(float& a, float& b)                                 { float tmp = a; a = b; b = tmp; }
145 static inline int    ImLerp(int a, int b, float t)                              { return (int)(a + (b - a) * t); }
146 static inline float  ImLerp(float a, float b, float t)                          { return a + (b - a) * t; }
147 static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, float t)          { return ImVec2(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t); }
148 static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t)  { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); }
149 static inline ImVec4 ImLerp(const ImVec4& a, const ImVec4& b, float t)          { return ImVec4(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t); }
150 static inline float  ImLengthSqr(const ImVec2& lhs)                             { return lhs.x*lhs.x + lhs.y*lhs.y; }
151 static inline float  ImLengthSqr(const ImVec4& lhs)                             { return lhs.x*lhs.x + lhs.y*lhs.y + lhs.z*lhs.z + lhs.w*lhs.w; }
152 static inline float  ImInvLength(const ImVec2& lhs, float fail_value)           { float d = lhs.x*lhs.x + lhs.y*lhs.y; if (d > 0.0f) return 1.0f / sqrtf(d); return fail_value; }
153 static inline float  ImFloor(float f)                                           { return (float)(int)f; }
154 static inline ImVec2 ImFloor(const ImVec2& v)                                   { return ImVec2((float)(int)v.x, (float)(int)v.y); }
155 static inline float  ImDot(const ImVec2& a, const ImVec2& b)                    { return a.x * b.x + a.y * b.y; }
156 static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a)        { return ImVec2(v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a); }
157 static inline float  ImLinearSweep(float current, float target, float speed)    { if (current < target) return ImMin(current + speed, target); if (current > target) return ImMax(current - speed, target); return current; }
158 static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs)                { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); }
159
160 // We call C++ constructor on own allocated memory via the placement "new(ptr) Type()" syntax.
161 // Defining a custom placement new() with a dummy parameter allows us to bypass including <new> which on some platforms complains when user has disabled exceptions.
162 struct ImPlacementNewDummy {};
163 inline void* operator new(size_t, ImPlacementNewDummy, void* ptr) { return ptr; }
164 inline void operator delete(void*, ImPlacementNewDummy, void*) {}
165 #define IM_PLACEMENT_NEW(_PTR)  new(ImPlacementNewDummy(), _PTR)
166
167 //-----------------------------------------------------------------------------
168 // Types
169 //-----------------------------------------------------------------------------
170
171 enum ImGuiButtonFlags_
172 {
173     ImGuiButtonFlags_Repeat                 = 1 << 0,   // hold to repeat
174     ImGuiButtonFlags_PressedOnClickRelease  = 1 << 1,   // return true on click + release on same item [DEFAULT if no PressedOn* flag is set]
175     ImGuiButtonFlags_PressedOnClick         = 1 << 2,   // return true on click (default requires click+release)
176     ImGuiButtonFlags_PressedOnRelease       = 1 << 3,   // return true on release (default requires click+release)
177     ImGuiButtonFlags_PressedOnDoubleClick   = 1 << 4,   // return true on double-click (default requires click+release)
178     ImGuiButtonFlags_FlattenChilds          = 1 << 5,   // allow interactions even if a child window is overlapping
179     ImGuiButtonFlags_DontClosePopups        = 1 << 6,   // disable automatically closing parent popup on press // [UNUSED]
180     ImGuiButtonFlags_Disabled               = 1 << 7,   // disable interactions
181     ImGuiButtonFlags_AlignTextBaseLine      = 1 << 8,   // vertically align button to match text baseline (ButtonEx() only)
182     ImGuiButtonFlags_NoKeyModifiers         = 1 << 9,   // disable interaction if a key modifier is held
183     ImGuiButtonFlags_AllowOverlapMode       = 1 << 10,  // require previous frame HoveredId to either match id or be null before being usable
184     ImGuiButtonFlags_NoHoldingActiveID      = 1 << 11   // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only)
185 };
186
187 enum ImGuiSliderFlags_
188 {
189     ImGuiSliderFlags_Vertical               = 1 << 0
190 };
191
192 enum ImGuiColumnsFlags_
193 {
194     // Default: 0
195     ImGuiColumnsFlags_NoBorder              = 1 << 0,   // Disable column dividers
196     ImGuiColumnsFlags_NoResize              = 1 << 1,   // Disable resizing columns when clicking on the dividers
197     ImGuiColumnsFlags_NoPreserveWidths      = 1 << 2,   // Disable column width preservation when adjusting columns
198     ImGuiColumnsFlags_NoForceWithinWindow   = 1 << 3,   // Disable forcing columns to fit within window
199     ImGuiColumnsFlags_GrowParentContentsSize= 1 << 4,   // (WIP) Restore pre-1.51 behavior of extending the parent window contents size but _without affecting the columns width at all_. Will eventually remove.
200 };
201
202 enum ImGuiSelectableFlagsPrivate_
203 {
204     // NB: need to be in sync with last value of ImGuiSelectableFlags_
205     ImGuiSelectableFlags_Menu               = 1 << 3,
206     ImGuiSelectableFlags_MenuItem           = 1 << 4,
207     ImGuiSelectableFlags_Disabled           = 1 << 5,
208     ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 6
209 };
210
211 enum ImGuiSeparatorFlags_
212 {
213     ImGuiSeparatorFlags_Horizontal          = 1 << 0,   // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar
214     ImGuiSeparatorFlags_Vertical            = 1 << 1
215 };
216
217 // FIXME: this is in development, not exposed/functional as a generic feature yet.
218 enum ImGuiLayoutType_
219 {
220     ImGuiLayoutType_Vertical,
221     ImGuiLayoutType_Horizontal
222 };
223
224 enum ImGuiAxis
225 {
226     ImGuiAxis_None = -1,
227     ImGuiAxis_X = 0,
228     ImGuiAxis_Y = 1,
229 };
230
231 enum ImGuiPlotType
232 {
233     ImGuiPlotType_Lines,
234     ImGuiPlotType_Histogram
235 };
236
237 enum ImGuiDataType
238 {
239     ImGuiDataType_Int,
240     ImGuiDataType_Float,
241     ImGuiDataType_Float2
242 };
243
244 enum ImGuiDir
245 {
246     ImGuiDir_None    = -1,
247     ImGuiDir_Left    = 0,
248     ImGuiDir_Right   = 1,
249     ImGuiDir_Up      = 2,
250     ImGuiDir_Down    = 3
251 };
252
253 // 2D axis aligned bounding-box
254 // NB: we can't rely on ImVec2 math operators being available here
255 struct IMGUI_API ImRect
256 {
257     ImVec2      Min;    // Upper-left
258     ImVec2      Max;    // Lower-right
259
260     ImRect()                                        : Min(FLT_MAX,FLT_MAX), Max(-FLT_MAX,-FLT_MAX)  {}
261     ImRect(const ImVec2& min, const ImVec2& max)    : Min(min), Max(max)                            {}
262     ImRect(const ImVec4& v)                         : Min(v.x, v.y), Max(v.z, v.w)                  {}
263     ImRect(float x1, float y1, float x2, float y2)  : Min(x1, y1), Max(x2, y2)                      {}
264
265     ImVec2      GetCenter() const               { return ImVec2((Min.x+Max.x)*0.5f, (Min.y+Max.y)*0.5f); }
266     ImVec2      GetSize() const                 { return ImVec2(Max.x-Min.x, Max.y-Min.y); }
267     float       GetWidth() const                { return Max.x-Min.x; }
268     float       GetHeight() const               { return Max.y-Min.y; }
269     ImVec2      GetTL() const                   { return Min; }                   // Top-left
270     ImVec2      GetTR() const                   { return ImVec2(Max.x, Min.y); }  // Top-right
271     ImVec2      GetBL() const                   { return ImVec2(Min.x, Max.y); }  // Bottom-left
272     ImVec2      GetBR() const                   { return Max; }                   // Bottom-right
273     bool        Contains(const ImVec2& p) const { return p.x >= Min.x     && p.y >= Min.y     && p.x < Max.x     && p.y < Max.y; }
274     bool        Contains(const ImRect& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x < Max.x && r.Max.y < Max.y; }
275     bool        Overlaps(const ImRect& r) const { return r.Min.y < Max.y  && r.Max.y > Min.y  && r.Min.x < Max.x && r.Max.x > Min.x; }
276     void        Add(const ImVec2& rhs)          { if (Min.x > rhs.x)     Min.x = rhs.x;     if (Min.y > rhs.y) Min.y = rhs.y;         if (Max.x < rhs.x) Max.x = rhs.x;         if (Max.y < rhs.y) Max.y = rhs.y; }
277     void        Add(const ImRect& rhs)          { if (Min.x > rhs.Min.x) Min.x = rhs.Min.x; if (Min.y > rhs.Min.y) Min.y = rhs.Min.y; if (Max.x < rhs.Max.x) Max.x = rhs.Max.x; if (Max.y < rhs.Max.y) Max.y = rhs.Max.y; }
278     void        Expand(const float amount)      { Min.x -= amount;   Min.y -= amount;   Max.x += amount;   Max.y += amount; }
279     void        Expand(const ImVec2& amount)    { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; }
280     void        Translate(const ImVec2& v)      { Min.x += v.x; Min.y += v.y; Max.x += v.x; Max.y += v.y; }
281     void        ClipWith(const ImRect& clip)    { if (Min.x < clip.Min.x) Min.x = clip.Min.x; if (Min.y < clip.Min.y) Min.y = clip.Min.y; if (Max.x > clip.Max.x) Max.x = clip.Max.x; if (Max.y > clip.Max.y) Max.y = clip.Max.y; }
282     void        Floor()                         { Min.x = (float)(int)Min.x; Min.y = (float)(int)Min.y; Max.x = (float)(int)Max.x; Max.y = (float)(int)Max.y; }
283     ImVec2      GetClosestPoint(ImVec2 p, bool on_edge) const
284     {
285         if (!on_edge && Contains(p))
286             return p;
287         if (p.x > Max.x) p.x = Max.x;
288         else if (p.x < Min.x) p.x = Min.x;
289         if (p.y > Max.y) p.y = Max.y;
290         else if (p.y < Min.y) p.y = Min.y;
291         return p;
292     }
293 };
294
295 // Stacked color modifier, backup of modified data so we can restore it
296 struct ImGuiColMod
297 {
298     ImGuiCol    Col;
299     ImVec4      BackupValue;
300 };
301
302 // Stacked style modifier, backup of modified data so we can restore it. Data type inferred from the variable.
303 struct ImGuiStyleMod
304 {
305     ImGuiStyleVar   VarIdx;
306     union           { int BackupInt[2]; float BackupFloat[2]; };
307     ImGuiStyleMod(ImGuiStyleVar idx, int v)     { VarIdx = idx; BackupInt[0] = v; }
308     ImGuiStyleMod(ImGuiStyleVar idx, float v)   { VarIdx = idx; BackupFloat[0] = v; }
309     ImGuiStyleMod(ImGuiStyleVar idx, ImVec2 v)  { VarIdx = idx; BackupFloat[0] = v.x; BackupFloat[1] = v.y; }
310 };
311
312 // Stacked data for BeginGroup()/EndGroup()
313 struct ImGuiGroupData
314 {
315     ImVec2      BackupCursorPos;
316     ImVec2      BackupCursorMaxPos;
317     float       BackupIndentX;
318     float       BackupGroupOffsetX;
319     float       BackupCurrentLineHeight;
320     float       BackupCurrentLineTextBaseOffset;
321     float       BackupLogLinePosY;
322     bool        BackupActiveIdIsAlive;
323     bool        AdvanceCursor;
324 };
325
326 // Per column data for Columns()
327 struct ImGuiColumnData
328 {
329     float       OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right)
330     ImRect      ClipRect;
331     //float     IndentX;
332 };
333
334 // Simple column measurement currently used for MenuItem() only. This is very short-sighted/throw-away code and NOT a generic helper.
335 struct IMGUI_API ImGuiSimpleColumns
336 {
337     int         Count;
338     float       Spacing;
339     float       Width, NextWidth;
340     float       Pos[8], NextWidths[8];
341
342     ImGuiSimpleColumns();
343     void        Update(int count, float spacing, bool clear);
344     float       DeclColumns(float w0, float w1, float w2);
345     float       CalcExtraSpace(float avail_w);
346 };
347
348 // Internal state of the currently focused/edited text input box
349 struct IMGUI_API ImGuiTextEditState
350 {
351     ImGuiID             Id;                         // widget id owning the text state
352     ImVector<ImWchar>   Text;                       // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer.
353     ImVector<char>      InitialText;                // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
354     ImVector<char>      TempTextBuffer;
355     int                 CurLenA, CurLenW;           // we need to maintain our buffer length in both UTF-8 and wchar format.
356     int                 BufSizeA;                   // end-user buffer size
357     float               ScrollX;
358     ImGuiStb::STB_TexteditState   StbState;
359     float               CursorAnim;
360     bool                CursorFollow;
361     bool                SelectedAllMouseLock;
362
363     ImGuiTextEditState()                            { memset(this, 0, sizeof(*this)); }
364     void                CursorAnimReset()           { CursorAnim = -0.30f; }                                   // After a user-input the cursor stays on for a while without blinking
365     void                CursorClamp()               { StbState.cursor = ImMin(StbState.cursor, CurLenW); StbState.select_start = ImMin(StbState.select_start, CurLenW); StbState.select_end = ImMin(StbState.select_end, CurLenW); }
366     bool                HasSelection() const        { return StbState.select_start != StbState.select_end; }
367     void                ClearSelection()            { StbState.select_start = StbState.select_end = StbState.cursor; }
368     void                SelectAll()                 { StbState.select_start = 0; StbState.select_end = CurLenW; StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
369     void                OnKeyPressed(int key);
370 };
371
372 // Data saved in imgui.ini file
373 struct ImGuiIniData
374 {
375     char*       Name;
376     ImGuiID     Id;
377     ImVec2      Pos;
378     ImVec2      Size;
379     bool        Collapsed;
380 };
381
382 // Mouse cursor data (used when io.MouseDrawCursor is set)
383 struct ImGuiMouseCursorData
384 {
385     ImGuiMouseCursor    Type;
386     ImVec2              HotOffset;
387     ImVec2              Size;
388     ImVec2              TexUvMin[2];
389     ImVec2              TexUvMax[2];
390 };
391
392 // Storage for current popup stack
393 struct ImGuiPopupRef
394 {
395     ImGuiID         PopupId;        // Set on OpenPopup()
396     ImGuiWindow*    Window;         // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup()
397     ImGuiWindow*    ParentWindow;   // Set on OpenPopup()
398     ImGuiID         ParentMenuSet;  // Set on OpenPopup()
399     ImVec2          MousePosOnOpen; // Copy of mouse position at the time of opening popup
400
401     ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& mouse_pos) { PopupId = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; MousePosOnOpen = mouse_pos; }
402 };
403
404 // Main state for ImGui
405 struct ImGuiContext
406 {
407     bool                    Initialized;
408     ImGuiIO                 IO;
409     ImGuiStyle              Style;
410     ImFont*                 Font;                               // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
411     float                   FontSize;                           // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize(). Text height for current window.
412     float                   FontBaseSize;                       // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Base text height.
413     ImVec2                  FontTexUvWhitePixel;                // (Shortcut) == Font->TexUvWhitePixel
414
415     float                   Time;
416     int                     FrameCount;
417     int                     FrameCountEnded;
418     int                     FrameCountRendered;
419     ImVector<ImGuiWindow*>  Windows;
420     ImVector<ImGuiWindow*>  WindowsSortBuffer;
421     ImVector<ImGuiWindow*>  CurrentWindowStack;
422     ImGuiStorage            WindowsById;
423     ImGuiWindow*            CurrentWindow;                      // Being drawn into
424     ImGuiWindow*            NavWindow;                          // Nav/focused window for navigation
425     ImGuiWindow*            HoveredWindow;                      // Will catch mouse inputs
426     ImGuiWindow*            HoveredRootWindow;                  // Will catch mouse inputs (for focus/move only)
427     ImGuiID                 HoveredId;                          // Hovered widget
428     bool                    HoveredIdAllowOverlap;
429     ImGuiID                 HoveredIdPreviousFrame;
430     float                   HoveredIdTimer;
431     ImGuiID                 ActiveId;                           // Active widget
432     ImGuiID                 ActiveIdPreviousFrame;
433     float                   ActiveIdTimer;
434     bool                    ActiveIdIsAlive;                    // Active widget has been seen this frame
435     bool                    ActiveIdIsJustActivated;            // Set at the time of activation for one frame
436     bool                    ActiveIdAllowOverlap;               // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always)
437     ImVec2                  ActiveIdClickOffset;                // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior)
438     ImGuiWindow*            ActiveIdWindow;
439     ImGuiWindow*            MovingWindow;                       // Track the child window we clicked on to move a window.
440     ImGuiID                 MovingWindowMoveId;                 // == MovingWindow->MoveId
441     ImVector<ImGuiIniData>  Settings;                           // .ini Settings
442     float                   SettingsDirtyTimer;                 // Save .ini Settings on disk when time reaches zero
443     ImVector<ImGuiColMod>   ColorModifiers;                     // Stack for PushStyleColor()/PopStyleColor()
444     ImVector<ImGuiStyleMod> StyleModifiers;                     // Stack for PushStyleVar()/PopStyleVar()
445     ImVector<ImFont*>       FontStack;                          // Stack for PushFont()/PopFont()
446     ImVector<ImGuiPopupRef> OpenPopupStack;                     // Which popups are open (persistent)
447     ImVector<ImGuiPopupRef> CurrentPopupStack;                  // Which level of BeginPopup() we are in (reset every frame)
448
449     // Storage for SetNexWindow** and SetNextTreeNode*** functions
450     ImVec2                  SetNextWindowPosVal;
451     ImVec2                  SetNextWindowPosPivot;
452     ImVec2                  SetNextWindowSizeVal;
453     ImVec2                  SetNextWindowContentSizeVal;
454     bool                    SetNextWindowCollapsedVal;
455     ImGuiCond               SetNextWindowPosCond;
456     ImGuiCond               SetNextWindowSizeCond;
457     ImGuiCond               SetNextWindowContentSizeCond;
458     ImGuiCond               SetNextWindowCollapsedCond;
459     ImRect                  SetNextWindowSizeConstraintRect;           // Valid if 'SetNextWindowSizeConstraint' is true
460     ImGuiSizeConstraintCallback SetNextWindowSizeConstraintCallback;
461     void*                   SetNextWindowSizeConstraintCallbackUserData;
462     bool                    SetNextWindowSizeConstraint;
463     bool                    SetNextWindowFocus;
464     bool                    SetNextTreeNodeOpenVal;
465     ImGuiCond               SetNextTreeNodeOpenCond;
466
467     // Render
468     ImDrawData              RenderDrawData;                     // Main ImDrawData instance to pass render information to the user
469     ImVector<ImDrawList*>   RenderDrawLists[3];
470     float                   ModalWindowDarkeningRatio;
471     ImDrawList              OverlayDrawList;                    // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays
472     ImGuiMouseCursor        MouseCursor;
473     ImGuiMouseCursorData    MouseCursorData[ImGuiMouseCursor_Count_];
474
475     // Widget state
476     ImGuiTextEditState      InputTextState;
477     ImFont                  InputTextPasswordFont;
478     ImGuiID                 ScalarAsInputTextId;                // Temporary text input when CTRL+clicking on a slider, etc.
479     ImGuiColorEditFlags     ColorEditOptions;                   // Store user options for color edit widgets
480     ImVec4                  ColorPickerRef;
481     float                   DragCurrentValue;                   // Currently dragged value, always float, not rounded by end-user precision settings
482     ImVec2                  DragLastMouseDelta;
483     float                   DragSpeedDefaultRatio;              // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
484     float                   DragSpeedScaleSlow;
485     float                   DragSpeedScaleFast;
486     ImVec2                  ScrollbarClickDeltaToGrabCenter;    // Distance between mouse and center of grab box, normalized in parent space. Use storage?
487     int                     TooltipOverrideCount;
488     ImVector<char>          PrivateClipboard;                   // If no custom clipboard handler is defined
489     ImVec2                  OsImePosRequest, OsImePosSet;       // Cursor position request & last passed to the OS Input Method Editor
490
491     // Logging
492     bool                    LogEnabled;
493     FILE*                   LogFile;                            // If != NULL log to stdout/ file
494     ImGuiTextBuffer*        LogClipboard;                       // Else log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators.
495     int                     LogStartDepth;
496     int                     LogAutoExpandMaxDepth;
497
498     // Misc
499     float                   FramerateSecPerFrame[120];          // calculate estimate of framerate for user
500     int                     FramerateSecPerFrameIdx;
501     float                   FramerateSecPerFrameAccum;
502     int                     WantCaptureMouseNextFrame;          // explicit capture via CaptureInputs() sets those flags
503     int                     WantCaptureKeyboardNextFrame;
504     int                     WantTextInputNextFrame;
505     char                    TempBuffer[1024*3+1];               // temporary text buffer
506
507     ImGuiContext()
508     {
509         Initialized = false;
510         Font = NULL;
511         FontSize = FontBaseSize = 0.0f;
512         FontTexUvWhitePixel = ImVec2(0.0f, 0.0f);
513
514         Time = 0.0f;
515         FrameCount = 0;
516         FrameCountEnded = FrameCountRendered = -1;
517         CurrentWindow = NULL;
518         NavWindow = NULL;
519         HoveredWindow = NULL;
520         HoveredRootWindow = NULL;
521         HoveredId = 0;
522         HoveredIdAllowOverlap = false;
523         HoveredIdPreviousFrame = 0;
524         HoveredIdTimer = 0.0f;
525         ActiveId = 0;
526         ActiveIdPreviousFrame = 0;
527         ActiveIdTimer = 0.0f;
528         ActiveIdIsAlive = false;
529         ActiveIdIsJustActivated = false;
530         ActiveIdAllowOverlap = false;
531         ActiveIdClickOffset = ImVec2(-1,-1);
532         ActiveIdWindow = NULL;
533         MovingWindow = NULL;
534         MovingWindowMoveId = 0;
535         SettingsDirtyTimer = 0.0f;
536
537         SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
538         SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
539         SetNextWindowCollapsedVal = false;
540         SetNextWindowPosCond = 0;
541         SetNextWindowSizeCond = 0;
542         SetNextWindowContentSizeCond = 0;
543         SetNextWindowCollapsedCond = 0;
544         SetNextWindowSizeConstraintRect = ImRect();
545         SetNextWindowSizeConstraintCallback = NULL;
546         SetNextWindowSizeConstraintCallbackUserData = NULL;
547         SetNextWindowSizeConstraint = false;
548         SetNextWindowFocus = false;
549         SetNextTreeNodeOpenVal = false;
550         SetNextTreeNodeOpenCond = 0;
551
552         ScalarAsInputTextId = 0;
553         ColorEditOptions = ImGuiColorEditFlags__OptionsDefault;
554         DragCurrentValue = 0.0f;
555         DragLastMouseDelta = ImVec2(0.0f, 0.0f);
556         DragSpeedDefaultRatio = 1.0f / 100.0f;
557         DragSpeedScaleSlow = 1.0f / 100.0f;
558         DragSpeedScaleFast = 10.0f;
559         ScrollbarClickDeltaToGrabCenter = ImVec2(0.0f, 0.0f);
560         TooltipOverrideCount = 0;
561         OsImePosRequest = OsImePosSet = ImVec2(-1.0f, -1.0f);
562
563         ModalWindowDarkeningRatio = 0.0f;
564         OverlayDrawList._OwnerName = "##Overlay"; // Give it a name for debugging
565         MouseCursor = ImGuiMouseCursor_Arrow;
566         memset(MouseCursorData, 0, sizeof(MouseCursorData));
567
568         LogEnabled = false;
569         LogFile = NULL;
570         LogClipboard = NULL;
571         LogStartDepth = 0;
572         LogAutoExpandMaxDepth = 2;
573
574         memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
575         FramerateSecPerFrameIdx = 0;
576         FramerateSecPerFrameAccum = 0.0f;
577         WantCaptureMouseNextFrame = WantCaptureKeyboardNextFrame = WantTextInputNextFrame = -1;
578         memset(TempBuffer, 0, sizeof(TempBuffer));
579     }
580 };
581
582 // Transient per-window flags, reset at the beginning of the frame. For child window, inherited from parent on first Begin().
583 enum ImGuiItemFlags_
584 {
585     ImGuiItemFlags_AllowKeyboardFocus           = 1 << 0,  // true
586     ImGuiItemFlags_ButtonRepeat                 = 1 << 1,  // false    // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings.
587     ImGuiItemFlags_Disabled                     = 1 << 2,  // false    // FIXME-WIP: Disable interactions but doesn't affect visuals. Should be: grey out and disable interactions with widgets that affect data + view widgets (WIP) 
588     //ImGuiItemFlags_NoNav                      = 1 << 3,  // false
589     //ImGuiItemFlags_NoNavDefaultFocus          = 1 << 4,  // false
590     ImGuiItemFlags_SelectableDontClosePopup     = 1 << 5,  // false    // MenuItem/Selectable() automatically closes current Popup window
591     ImGuiItemFlags_Default_                     = ImGuiItemFlags_AllowKeyboardFocus
592 };
593
594 // Transient per-window data, reset at the beginning of the frame
595 // FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiDrawContext is quite tenuous and could be reconsidered.
596 struct IMGUI_API ImGuiDrawContext
597 {
598     ImVec2                  CursorPos;
599     ImVec2                  CursorPosPrevLine;
600     ImVec2                  CursorStartPos;
601     ImVec2                  CursorMaxPos;           // Implicitly calculate the size of our contents, always extending. Saved into window->SizeContents at the end of the frame
602     float                   CurrentLineHeight;
603     float                   CurrentLineTextBaseOffset;
604     float                   PrevLineHeight;
605     float                   PrevLineTextBaseOffset;
606     float                   LogLinePosY;
607     int                     TreeDepth;
608     ImGuiID                 LastItemId;
609     ImRect                  LastItemRect;
610     bool                    LastItemRectHoveredRect;
611     bool                    MenuBarAppending;
612     float                   MenuBarOffsetX;
613     ImVector<ImGuiWindow*>  ChildWindows;
614     ImGuiStorage*           StateStorage;
615     ImGuiLayoutType         LayoutType;
616
617     // We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings.
618     ImGuiItemFlags          ItemFlags;              // == ItemFlagsStack.back() [empty == ImGuiItemFlags_Default]
619     float                   ItemWidth;              // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
620     float                   TextWrapPos;            // == TextWrapPosStack.back() [empty == -1.0f]
621     ImVector<ImGuiItemFlags>ItemFlagsStack;
622     ImVector<float>         ItemWidthStack;
623     ImVector<float>         TextWrapPosStack;
624     ImVector<ImGuiGroupData>GroupStack;
625     int                     StackSizesBackup[6];    // Store size of various stacks for asserting
626
627     float                   IndentX;                // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
628     float                   GroupOffsetX;
629     float                   ColumnsOffsetX;         // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API.
630     int                     ColumnsCurrent;
631     int                     ColumnsCount;
632     float                   ColumnsMinX;
633     float                   ColumnsMaxX;
634     float                   ColumnsStartPosY;
635     float                   ColumnsStartMaxPosX;   // Backup of CursorMaxPos
636     float                   ColumnsCellMinY;
637     float                   ColumnsCellMaxY;
638     ImGuiColumnsFlags       ColumnsFlags;
639     ImGuiID                 ColumnsSetId;
640     ImVector<ImGuiColumnData> ColumnsData;
641
642     ImGuiDrawContext()
643     {
644         CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f);
645         CurrentLineHeight = PrevLineHeight = 0.0f;
646         CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f;
647         LogLinePosY = -1.0f;
648         TreeDepth = 0;
649         LastItemId = 0;
650         LastItemRect = ImRect();
651         LastItemRectHoveredRect = false;
652         MenuBarAppending = false;
653         MenuBarOffsetX = 0.0f;
654         StateStorage = NULL;
655         LayoutType = ImGuiLayoutType_Vertical;
656         ItemWidth = 0.0f;
657         ItemFlags = ImGuiItemFlags_Default_;
658         TextWrapPos = -1.0f;
659         memset(StackSizesBackup, 0, sizeof(StackSizesBackup));
660
661         IndentX = 0.0f;
662         GroupOffsetX = 0.0f;
663         ColumnsOffsetX = 0.0f;
664         ColumnsCurrent = 0;
665         ColumnsCount = 1;
666         ColumnsMinX = ColumnsMaxX = 0.0f;
667         ColumnsStartPosY = 0.0f;
668         ColumnsStartMaxPosX = 0.0f;
669         ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
670         ColumnsFlags = 0;
671         ColumnsSetId = 0;
672     }
673 };
674
675 // Windows data
676 struct IMGUI_API ImGuiWindow
677 {
678     char*                   Name;
679     ImGuiID                 ID;                                 // == ImHash(Name)
680     ImGuiWindowFlags        Flags;                              // See enum ImGuiWindowFlags_
681     int                     OrderWithinParent;                  // Order within immediate parent window, if we are a child window. Otherwise 0.
682     ImVec2                  PosFloat;
683     ImVec2                  Pos;                                // Position rounded-up to nearest pixel
684     ImVec2                  Size;                               // Current size (==SizeFull or collapsed title bar size)
685     ImVec2                  SizeFull;                           // Size when non collapsed
686     ImVec2                  SizeContents;                       // Size of contents (== extents reach of the drawing cursor) from previous frame
687     ImVec2                  SizeContentsExplicit;               // Size of contents explicitly set by the user via SetNextWindowContentSize()
688     ImRect                  ContentsRegionRect;                 // Maximum visible content position in window coordinates. ~~ (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis
689     ImVec2                  WindowPadding;                      // Window padding at the time of begin.
690     float                   WindowRounding;                     // Window rounding at the time of begin.
691     float                   WindowBorderSize;                   // Window border size at the time of begin.
692     ImGuiID                 MoveId;                             // == window->GetID("#MOVE")
693     ImVec2                  Scroll;
694     ImVec2                  ScrollTarget;                       // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change)
695     ImVec2                  ScrollTargetCenterRatio;            // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered
696     bool                    ScrollbarX, ScrollbarY;
697     ImVec2                  ScrollbarSizes;
698     bool                    Active;                             // Set to true on Begin()
699     bool                    WasActive;
700     bool                    WriteAccessed;                      // Set to true when any widget access the current window
701     bool                    Collapsed;                          // Set when collapsing window to become only title-bar
702     bool                    SkipItems;                          // Set when items can safely be all clipped (e.g. window not visible or collapsed)
703     bool                    Appearing;                          // Set during the frame where the window is appearing (or re-appearing)
704     bool                    CloseButton;                        // Set when the window has a close button (p_open != NULL)
705     int                     BeginCount;                         // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs)
706     ImGuiID                 PopupId;                            // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling)
707     int                     AutoFitFramesX, AutoFitFramesY;
708     bool                    AutoFitOnlyGrows;
709     int                     AutoFitChildAxises;
710     int                     AutoPosLastDirection;
711     int                     HiddenFrames;
712     ImGuiCond               SetWindowPosAllowFlags;             // store condition flags for next SetWindowPos() call.
713     ImGuiCond               SetWindowSizeAllowFlags;            // store condition flags for next SetWindowSize() call.
714     ImGuiCond               SetWindowCollapsedAllowFlags;       // store condition flags for next SetWindowCollapsed() call.
715     ImVec2                  SetWindowPosVal;                    // store window position when using a non-zero Pivot (position set needs to be processed when we know the window size)
716     ImVec2                  SetWindowPosPivot;                  // store window pivot for positioning. ImVec2(0,0) when positioning from top-left corner; ImVec2(0.5f,0.5f) for centering; ImVec2(1,1) for bottom right.
717
718     ImGuiDrawContext        DC;                                 // Temporary per-window data, reset at the beginning of the frame
719     ImVector<ImGuiID>       IDStack;                            // ID stack. ID are hashes seeded with the value at the top of the stack
720     ImRect                  ClipRect;                           // = DrawList->clip_rect_stack.back(). Scissoring / clipping rectangle. x1, y1, x2, y2.
721     ImRect                  WindowRectClipped;                  // = WindowRect just after setup in Begin(). == window->Rect() for root window.
722     ImRect                  InnerRect;
723     int                     LastFrameActive;
724     float                   ItemWidthDefault;
725     ImGuiSimpleColumns      MenuColumns;                        // Simplified columns storage for menu items
726     ImGuiStorage            StateStorage;
727     float                   FontWindowScale;                    // Scale multiplier per-window
728     ImDrawList*             DrawList;
729     ImGuiWindow*            ParentWindow;                       // Immediate parent in the window stack *regardless* of whether this window is a child window or not)
730     ImGuiWindow*            RootWindow;                         // Generally point to ourself. If we are a child window, this is pointing to the first non-child parent window.
731     ImGuiWindow*            RootNonPopupWindow;                 // Generally point to ourself. Used to display TitleBgActive color and for selecting which window to use for NavWindowing
732
733     // Navigation / Focus
734     int                     FocusIdxAllCounter;                 // Start at -1 and increase as assigned via FocusItemRegister()
735     int                     FocusIdxTabCounter;                 // (same, but only count widgets which you can Tab through)
736     int                     FocusIdxAllRequestCurrent;          // Item being requested for focus
737     int                     FocusIdxTabRequestCurrent;          // Tab-able item being requested for focus
738     int                     FocusIdxAllRequestNext;             // Item being requested for focus, for next update (relies on layout to be stable between the frame pressing TAB and the next frame)
739     int                     FocusIdxTabRequestNext;             // "
740
741 public:
742     ImGuiWindow(const char* name);
743     ~ImGuiWindow();
744
745     ImGuiID     GetID(const char* str, const char* str_end = NULL);
746     ImGuiID     GetID(const void* ptr);
747     ImGuiID     GetIDNoKeepAlive(const char* str, const char* str_end = NULL);
748
749     // We don't use g.FontSize because the window may be != g.CurrentWidow.
750     ImRect      Rect() const                            { return ImRect(Pos.x, Pos.y, Pos.x+Size.x, Pos.y+Size.y); }
751     float       CalcFontSize() const                    { return GImGui->FontBaseSize * FontWindowScale; }
752     float       TitleBarHeight() const                  { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; }
753     ImRect      TitleBarRect() const                    { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); }
754     float       MenuBarHeight() const                   { return (Flags & ImGuiWindowFlags_MenuBar) ? CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f : 0.0f; }
755     ImRect      MenuBarRect() const                     { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); }
756 };
757
758 // Backup and restore just enough data to be able to use IsItemHovered() on item A after another B in the same window has overwritten the data.  
759 struct ImGuiItemHoveredDataBackup
760 {
761     ImGuiID     LastItemId;
762     ImRect      LastItemRect;
763     bool        LastItemRectHoveredRect;
764
765     void Backup()  { ImGuiWindow* window = GImGui->CurrentWindow; LastItemId = window->DC.LastItemId; LastItemRect = window->DC.LastItemRect; LastItemRectHoveredRect = window->DC.LastItemRectHoveredRect; }
766     void Restore() { ImGuiWindow* window = GImGui->CurrentWindow; window->DC.LastItemId = LastItemId; window->DC.LastItemRect = LastItemRect; window->DC.LastItemRectHoveredRect = LastItemRectHoveredRect; }
767 };
768
769 //-----------------------------------------------------------------------------
770 // Internal API
771 // No guarantee of forward compatibility here.
772 //-----------------------------------------------------------------------------
773
774 namespace ImGui
775 {
776     // We should always have a CurrentWindow in the stack (there is an implicit "Debug" window)
777     // If this ever crash because g.CurrentWindow is NULL it means that either
778     // - ImGui::NewFrame() has never been called, which is illegal.
779     // - You are calling ImGui functions after ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal.
780     inline    ImGuiWindow*  GetCurrentWindowRead()      { ImGuiContext& g = *GImGui; return g.CurrentWindow; }
781     inline    ImGuiWindow*  GetCurrentWindow()          { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; }
782     IMGUI_API ImGuiWindow*  GetParentWindow();
783     IMGUI_API ImGuiWindow*  FindWindowByName(const char* name);
784     IMGUI_API void          FocusWindow(ImGuiWindow* window);
785     IMGUI_API void          BringWindowToFront(ImGuiWindow* window);
786     IMGUI_API void          BringWindowToBack(ImGuiWindow* window);
787
788     IMGUI_API void          Initialize();
789
790     IMGUI_API void          SetActiveID(ImGuiID id, ImGuiWindow* window);
791     IMGUI_API void          ClearActiveID();
792     IMGUI_API void          SetHoveredID(ImGuiID id);
793     IMGUI_API void          KeepAliveID(ImGuiID id);
794
795     IMGUI_API void          ItemSize(const ImVec2& size, float text_offset_y = 0.0f);
796     IMGUI_API void          ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
797     IMGUI_API bool          ItemAdd(const ImRect& bb, ImGuiID id);
798     IMGUI_API bool          ItemHoverable(const ImRect& bb, ImGuiID id);
799     IMGUI_API bool          IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged);
800     IMGUI_API bool          FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop = true);      // Return true if focus is requested
801     IMGUI_API void          FocusableItemUnregister(ImGuiWindow* window);
802     IMGUI_API ImVec2        CalcItemSize(ImVec2 size, float default_x, float default_y);
803     IMGUI_API float         CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
804     IMGUI_API void          PushMultiItemsWidths(int components, float width_full = 0.0f);
805     IMGUI_API void          PushItemFlag(ImGuiItemFlags option, bool enabled);
806     IMGUI_API void          PopItemFlag();
807
808     IMGUI_API void          OpenPopupEx(ImGuiID id, bool reopen_existing);
809     IMGUI_API void          ClosePopup(ImGuiID id);
810     IMGUI_API bool          IsPopupOpen(ImGuiID id);
811     IMGUI_API bool          BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags);
812     IMGUI_API void          BeginTooltipEx(ImGuiWindowFlags extra_flags, bool override_previous_tooltip = true);
813
814     IMGUI_API int           CalcTypematicPressedRepeatAmount(float t, float t_prev, float repeat_delay, float repeat_rate);
815
816     IMGUI_API void          Scrollbar(ImGuiLayoutType direction);
817     IMGUI_API void          VerticalSeparator();        // Vertical separator, for menu bars (use current line height). not exposed because it is misleading what it doesn't have an effect on regular layout.
818     IMGUI_API bool          SplitterBehavior(ImGuiID id, const ImRect& bb, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend = 0.0f);
819
820     // FIXME-WIP: New Columns API
821     IMGUI_API void          BeginColumns(const char* id, int count, ImGuiColumnsFlags flags = 0); // setup number of columns. use an identifier to distinguish multiple column sets. close with EndColumns().
822     IMGUI_API void          EndColumns();                                                         // close columns
823     IMGUI_API void          PushColumnClipRect(int column_index = -1);
824
825     // FIXME-WIP: New Combo API
826     IMGUI_API bool          BeginCombo(const char* label, const char* preview_value, ImVec2 popup_size = ImVec2(0.0f,0.0f));
827     IMGUI_API void          EndCombo();
828
829     // NB: All position are in absolute pixels coordinates (never using window coordinates internally)
830     // AVOID USING OUTSIDE OF IMGUI.CPP! NOT FOR PUBLIC CONSUMPTION. THOSE FUNCTIONS ARE A MESS. THEIR SIGNATURE AND BEHAVIOR WILL CHANGE, THEY NEED TO BE REFACTORED INTO SOMETHING DECENT.
831     IMGUI_API void          RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
832     IMGUI_API void          RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width);
833     IMGUI_API void          RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0,0), const ImRect* clip_rect = NULL);
834     IMGUI_API void          RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
835     IMGUI_API void          RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f);
836     IMGUI_API void          RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0);
837     IMGUI_API void          RenderTriangle(ImVec2 pos, ImGuiDir dir, float scale = 1.0f);
838     IMGUI_API void          RenderBullet(ImVec2 pos);
839     IMGUI_API void          RenderCheckMark(ImVec2 pos, ImU32 col, float sz);
840     IMGUI_API void          RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding);
841     IMGUI_API const char*   FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text.
842
843     IMGUI_API bool          ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0);
844     IMGUI_API bool          ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0);
845     IMGUI_API bool          CloseButton(ImGuiID id, const ImVec2& pos, float radius);
846     IMGUI_API bool          ArrowButton(ImGuiID id, ImGuiDir dir, ImVec2 padding, ImGuiButtonFlags flags = 0);
847
848     IMGUI_API bool          SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags = 0);
849     IMGUI_API bool          SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power);
850     IMGUI_API bool          SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format);
851
852     IMGUI_API bool          DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power);
853     IMGUI_API bool          DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power);
854     IMGUI_API bool          DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format);
855
856     IMGUI_API bool          InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
857     IMGUI_API bool          InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags);
858     IMGUI_API bool          InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags);
859     IMGUI_API bool          InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags);
860     IMGUI_API bool          InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision);
861
862     IMGUI_API void          ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags);
863     IMGUI_API void          ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags);
864
865     IMGUI_API bool          TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL);
866     IMGUI_API bool          TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0);                     // Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging
867     IMGUI_API void          TreePushRawID(ImGuiID id);
868
869     IMGUI_API void          PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size);
870
871     IMGUI_API int           ParseFormatPrecision(const char* fmt, int default_value);
872     IMGUI_API float         RoundScalar(float value, int decimal_precision);
873
874     // Shade functions
875     IMGUI_API void          ShadeVertsLinearColorGradientKeepAlpha(ImDrawVert* vert_start, ImDrawVert* vert_end, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1);
876     IMGUI_API void          ShadeVertsLinearAlphaGradientForLeftToRightText(ImDrawVert* vert_start, ImDrawVert* vert_end, float gradient_p0_x, float gradient_p1_x);
877     IMGUI_API void          ShadeVertsLinearUV(ImDrawVert* vert_start, ImDrawVert* vert_end, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, bool clamp);
878
879 } // namespace ImGui
880
881 // ImFontAtlas internals
882 IMGUI_API bool              ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas);
883 IMGUI_API void              ImFontAtlasBuildRegisterDefaultCustomRects(ImFontAtlas* atlas);
884 IMGUI_API void              ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent); 
885 IMGUI_API void              ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* spc);
886 IMGUI_API void              ImFontAtlasBuildFinish(ImFontAtlas* atlas);
887 IMGUI_API void              ImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256], float in_multiply_factor);
888 IMGUI_API void              ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride);
889
890 #ifdef __clang__
891 #pragma clang diagnostic pop
892 #endif
893
894 #ifdef _MSC_VER
895 #pragma warning (pop)
896 #endif