1b8e80941Smrg// dear imgui, v1.68 WIP
2b8e80941Smrg// (internal structures/api)
3b8e80941Smrg
4b8e80941Smrg// You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility!
5b8e80941Smrg// Set:
6b8e80941Smrg//   #define IMGUI_DEFINE_MATH_OPERATORS
7b8e80941Smrg// 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)
8b8e80941Smrg
9b8e80941Smrg/*
10b8e80941Smrg
11b8e80941SmrgIndex of this file:
12b8e80941Smrg// Header mess
13b8e80941Smrg// Forward declarations
14b8e80941Smrg// STB libraries includes
15b8e80941Smrg// Context pointer
16b8e80941Smrg// Generic helpers
17b8e80941Smrg// Misc data structures
18b8e80941Smrg// Main imgui context
19b8e80941Smrg// Tab bar, tab item
20b8e80941Smrg// Internal API
21b8e80941Smrg
22b8e80941Smrg*/
23b8e80941Smrg
24b8e80941Smrg#pragma once
25b8e80941Smrg
26b8e80941Smrg//-----------------------------------------------------------------------------
27b8e80941Smrg// Header mess
28b8e80941Smrg//-----------------------------------------------------------------------------
29b8e80941Smrg
30b8e80941Smrg#ifndef IMGUI_VERSION
31b8e80941Smrg#error Must include imgui.h before imgui_internal.h
32b8e80941Smrg#endif
33b8e80941Smrg
34b8e80941Smrg#include <stdio.h>      // FILE*
35b8e80941Smrg#include <stdlib.h>     // NULL, malloc, free, qsort, atoi, atof
36b8e80941Smrg#include <math.h>       // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf
37b8e80941Smrg#include <limits.h>     // INT_MIN, INT_MAX
38b8e80941Smrg
39b8e80941Smrg#ifdef _MSC_VER
40b8e80941Smrg#pragma warning (push)
41b8e80941Smrg#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)
42b8e80941Smrg#endif
43b8e80941Smrg
44b8e80941Smrg#ifdef __clang__
45b8e80941Smrg#pragma clang diagnostic push
46b8e80941Smrg#pragma clang diagnostic ignored "-Wunused-function"                // for stb_textedit.h
47b8e80941Smrg#pragma clang diagnostic ignored "-Wmissing-prototypes"             // for stb_textedit.h
48b8e80941Smrg#pragma clang diagnostic ignored "-Wold-style-cast"
49b8e80941Smrg#if __has_warning("-Wzero-as-null-pointer-constant")
50b8e80941Smrg#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
51b8e80941Smrg#endif
52b8e80941Smrg#if __has_warning("-Wdouble-promotion")
53b8e80941Smrg#pragma clang diagnostic ignored "-Wdouble-promotion"
54b8e80941Smrg#endif
55b8e80941Smrg#endif
56b8e80941Smrg
57b8e80941Smrg//-----------------------------------------------------------------------------
58b8e80941Smrg// Forward declarations
59b8e80941Smrg//-----------------------------------------------------------------------------
60b8e80941Smrg
61b8e80941Smrgstruct ImRect;                      // An axis-aligned rectangle (2 points)
62b8e80941Smrgstruct ImDrawDataBuilder;           // Helper to build a ImDrawData instance
63b8e80941Smrgstruct ImDrawListSharedData;        // Data shared between all ImDrawList instances
64b8e80941Smrgstruct ImGuiColorMod;               // Stacked color modifier, backup of modified data so we can restore it
65b8e80941Smrgstruct ImGuiColumnData;             // Storage data for a single column
66b8e80941Smrgstruct ImGuiColumnsSet;             // Storage data for a columns set
67b8e80941Smrgstruct ImGuiContext;                // Main imgui context
68b8e80941Smrgstruct ImGuiGroupData;              // Stacked storage data for BeginGroup()/EndGroup()
69b8e80941Smrgstruct ImGuiInputTextState;         // Internal state of the currently focused/edited text input box
70b8e80941Smrgstruct ImGuiItemHoveredDataBackup;  // Backup and restore IsItemHovered() internal data
71b8e80941Smrgstruct ImGuiMenuColumns;            // Simple column measurement, currently used for MenuItem() only
72b8e80941Smrgstruct ImGuiNavMoveResult;          // Result of a directional navigation move query result
73b8e80941Smrgstruct ImGuiNextWindowData;         // Storage for SetNexWindow** functions
74b8e80941Smrgstruct ImGuiPopupRef;               // Storage for current popup stack
75b8e80941Smrgstruct ImGuiSettingsHandler;        // Storage for one type registered in the .ini file
76b8e80941Smrgstruct ImGuiStyleMod;               // Stacked style modifier, backup of modified data so we can restore it
77b8e80941Smrgstruct ImGuiTabBar;                 // Storage for a tab bar
78b8e80941Smrgstruct ImGuiTabItem;                // Storage for a tab item (within a tab bar)
79b8e80941Smrgstruct ImGuiWindow;                 // Storage for one window
80b8e80941Smrgstruct ImGuiWindowTempData;         // Temporary storage for one window (that's the data which in theory we could ditch at the end of the frame)
81b8e80941Smrgstruct ImGuiWindowSettings;         // Storage for window settings stored in .ini file (we keep one of those even if the actual window wasn't instanced during this session)
82b8e80941Smrg
83b8e80941Smrg// Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists.
84b8e80941Smrgtypedef int ImGuiLayoutType;        // -> enum ImGuiLayoutType_        // Enum: Horizontal or vertical
85b8e80941Smrgtypedef int ImGuiButtonFlags;       // -> enum ImGuiButtonFlags_       // Flags: for ButtonEx(), ButtonBehavior()
86b8e80941Smrgtypedef int ImGuiItemFlags;         // -> enum ImGuiItemFlags_         // Flags: for PushItemFlag()
87b8e80941Smrgtypedef int ImGuiItemStatusFlags;   // -> enum ImGuiItemStatusFlags_   // Flags: for DC.LastItemStatusFlags
88b8e80941Smrgtypedef int ImGuiNavHighlightFlags; // -> enum ImGuiNavHighlightFlags_ // Flags: for RenderNavHighlight()
89b8e80941Smrgtypedef int ImGuiNavDirSourceFlags; // -> enum ImGuiNavDirSourceFlags_ // Flags: for GetNavInputAmount2d()
90b8e80941Smrgtypedef int ImGuiNavMoveFlags;      // -> enum ImGuiNavMoveFlags_      // Flags: for navigation requests
91b8e80941Smrgtypedef int ImGuiSeparatorFlags;    // -> enum ImGuiSeparatorFlags_    // Flags: for Separator() - internal
92b8e80941Smrgtypedef int ImGuiSliderFlags;       // -> enum ImGuiSliderFlags_       // Flags: for SliderBehavior()
93b8e80941Smrgtypedef int ImGuiDragFlags;         // -> enum ImGuiDragFlags_         // Flags: for DragBehavior()
94b8e80941Smrg
95b8e80941Smrg//-------------------------------------------------------------------------
96b8e80941Smrg// STB libraries includes
97b8e80941Smrg//-------------------------------------------------------------------------
98b8e80941Smrg
99b8e80941Smrgnamespace ImGuiStb
100b8e80941Smrg{
101b8e80941Smrg
102b8e80941Smrg#undef STB_TEXTEDIT_STRING
103b8e80941Smrg#undef STB_TEXTEDIT_CHARTYPE
104b8e80941Smrg#define STB_TEXTEDIT_STRING             ImGuiInputTextState
105b8e80941Smrg#define STB_TEXTEDIT_CHARTYPE           ImWchar
106b8e80941Smrg#define STB_TEXTEDIT_GETWIDTH_NEWLINE   -1.0f
107b8e80941Smrg#include "imstb_textedit.h"
108b8e80941Smrg
109b8e80941Smrg} // namespace ImGuiStb
110b8e80941Smrg
111b8e80941Smrg//-----------------------------------------------------------------------------
112b8e80941Smrg// Context pointer
113b8e80941Smrg//-----------------------------------------------------------------------------
114b8e80941Smrg
115b8e80941Smrg#ifndef GImGui
116b8e80941Smrgextern IMGUI_API ImGuiContext* GImGui;  // Current implicit ImGui context pointer
117b8e80941Smrg#endif
118b8e80941Smrg
119b8e80941Smrg//-----------------------------------------------------------------------------
120b8e80941Smrg// Generic helpers
121b8e80941Smrg//-----------------------------------------------------------------------------
122b8e80941Smrg
123b8e80941Smrg#define IM_PI           3.14159265358979323846f
124b8e80941Smrg#ifdef _WIN32
125b8e80941Smrg#define IM_NEWLINE      "\r\n"   // Play it nice with Windows users (2018/05 news: Microsoft announced that Notepad will finally display Unix-style carriage returns!)
126b8e80941Smrg#else
127b8e80941Smrg#define IM_NEWLINE      "\n"
128b8e80941Smrg#endif
129b8e80941Smrg
130b8e80941Smrg#define IMGUI_DEBUG_LOG(_FMT,...)       printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__)
131b8e80941Smrg#define IM_STATIC_ASSERT(_COND)         typedef char static_assertion_##__line__[(_COND)?1:-1]
132b8e80941Smrg#define IM_F32_TO_INT8_UNBOUND(_VAL)    ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f)))   // Unsaturated, for display purpose
133b8e80941Smrg#define IM_F32_TO_INT8_SAT(_VAL)        ((int)(ImSaturate(_VAL) * 255.0f + 0.5f))               // Saturated, always output 0..255
134b8e80941Smrg
135b8e80941Smrg// Enforce cdecl calling convention for functions called by the standard library, in case compilation settings changed the default to e.g. __vectorcall
136b8e80941Smrg#ifdef _MSC_VER
137b8e80941Smrg#define IMGUI_CDECL __cdecl
138b8e80941Smrg#else
139b8e80941Smrg#define IMGUI_CDECL
140b8e80941Smrg#endif
141b8e80941Smrg
142b8e80941Smrg// Helpers: UTF-8 <> wchar
143b8e80941SmrgIMGUI_API int           ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end);      // return output UTF-8 bytes count
144b8e80941SmrgIMGUI_API int           ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end);          // read one character. return input UTF-8 bytes count
145b8e80941SmrgIMGUI_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
146b8e80941SmrgIMGUI_API int           ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end);                            // return number of UTF-8 code-points (NOT bytes count)
147b8e80941SmrgIMGUI_API int           ImTextCountUtf8BytesFromChar(const char* in_text, const char* in_text_end);                        // return number of bytes to express one char in UTF-8
148b8e80941SmrgIMGUI_API int           ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end);                   // return number of bytes to express string in UTF-8
149b8e80941Smrg
150b8e80941Smrg// Helpers: Misc
151b8e80941SmrgIMGUI_API ImU32         ImHashData(const void* data, size_t data_size, ImU32 seed = 0);
152b8e80941SmrgIMGUI_API ImU32         ImHashStr(const char* data, size_t data_size, ImU32 seed = 0);
153b8e80941SmrgIMGUI_API void*         ImFileLoadToMemory(const char* filename, const char* file_open_mode, size_t* out_file_size = NULL, int padding_bytes = 0);
154b8e80941SmrgIMGUI_API FILE*         ImFileOpen(const char* filename, const char* file_open_mode);
155b8e80941Smrgstatic inline bool      ImCharIsBlankA(char c)          { return c == ' ' || c == '\t'; }
156b8e80941Smrgstatic inline bool      ImCharIsBlankW(unsigned int c)  { return c == ' ' || c == '\t' || c == 0x3000; }
157b8e80941Smrgstatic inline bool      ImIsPowerOfTwo(int v)           { return v != 0 && (v & (v - 1)) == 0; }
158b8e80941Smrgstatic inline int       ImUpperPowerOfTwo(int v)        { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
159b8e80941Smrg#define ImQsort         qsort
160b8e80941Smrg#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
161b8e80941Smrgstatic inline ImU32     ImHash(const void* data, int size, ImU32 seed = 0) { return size ? ImHashData(data, (size_t)size, seed) : ImHashStr((const char*)data, 0, seed); } // [moved to ImHashStr/ImHashData in 1.68]
162b8e80941Smrg#endif
163b8e80941Smrg
164b8e80941Smrg// Helpers: Geometry
165b8e80941SmrgIMGUI_API ImVec2        ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p);
166b8e80941SmrgIMGUI_API bool          ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p);
167b8e80941SmrgIMGUI_API ImVec2        ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p);
168b8e80941SmrgIMGUI_API void          ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w);
169b8e80941SmrgIMGUI_API ImGuiDir      ImGetDirQuadrantFromDelta(float dx, float dy);
170b8e80941Smrg
171b8e80941Smrg// Helpers: String
172b8e80941SmrgIMGUI_API int           ImStricmp(const char* str1, const char* str2);
173b8e80941SmrgIMGUI_API int           ImStrnicmp(const char* str1, const char* str2, size_t count);
174b8e80941SmrgIMGUI_API void          ImStrncpy(char* dst, const char* src, size_t count);
175b8e80941SmrgIMGUI_API char*         ImStrdup(const char* str);
176b8e80941SmrgIMGUI_API char*         ImStrdupcpy(char* dst, size_t* p_dst_size, const char* str);
177b8e80941SmrgIMGUI_API const char*   ImStrchrRange(const char* str_begin, const char* str_end, char c);
178b8e80941SmrgIMGUI_API int           ImStrlenW(const ImWchar* str);
179b8e80941SmrgIMGUI_API const char*   ImStreolRange(const char* str, const char* str_end);                // End end-of-line
180b8e80941SmrgIMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin);   // Find beginning-of-line
181b8e80941SmrgIMGUI_API const char*   ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end);
182b8e80941SmrgIMGUI_API void          ImStrTrimBlanks(char* str);
183b8e80941SmrgIMGUI_API int           ImFormatString(char* buf, size_t buf_size, const char* fmt, ...) IM_FMTARGS(3);
184b8e80941SmrgIMGUI_API int           ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) IM_FMTLIST(3);
185b8e80941SmrgIMGUI_API const char*   ImParseFormatFindStart(const char* format);
186b8e80941SmrgIMGUI_API const char*   ImParseFormatFindEnd(const char* format);
187b8e80941SmrgIMGUI_API const char*   ImParseFormatTrimDecorations(const char* format, char* buf, size_t buf_size);
188b8e80941SmrgIMGUI_API int           ImParseFormatPrecision(const char* format, int default_value);
189b8e80941Smrg
190b8e80941Smrg// Helpers: ImVec2/ImVec4 operators
191b8e80941Smrg// We are keeping those disabled by default so they don't leak in user space, to allow user enabling implicit cast operators between ImVec2 and their own types (using IM_VEC2_CLASS_EXTRA etc.)
192b8e80941Smrg// We unfortunately don't have a unary- operator for ImVec2 because this would needs to be defined inside the class itself.
193b8e80941Smrg#ifdef IMGUI_DEFINE_MATH_OPERATORS
194b8e80941Smrgstatic inline ImVec2 operator*(const ImVec2& lhs, const float rhs)              { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
195b8e80941Smrgstatic inline ImVec2 operator/(const ImVec2& lhs, const float rhs)              { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
196b8e80941Smrgstatic inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs)            { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
197b8e80941Smrgstatic inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs)            { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
198b8e80941Smrgstatic inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs)            { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
199b8e80941Smrgstatic inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs)            { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
200b8e80941Smrgstatic inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs)                { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
201b8e80941Smrgstatic inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs)                { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
202b8e80941Smrgstatic inline ImVec2& operator*=(ImVec2& lhs, const float rhs)                  { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
203b8e80941Smrgstatic inline ImVec2& operator/=(ImVec2& lhs, const float rhs)                  { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
204b8e80941Smrgstatic 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); }
205b8e80941Smrgstatic 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); }
206b8e80941Smrgstatic 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); }
207b8e80941Smrg#endif
208b8e80941Smrg
209b8e80941Smrg// Helpers: Maths
210b8e80941Smrg// - Wrapper for standard libs functions. (Note that imgui_demo.cpp does _not_ use them to keep the code easy to copy)
211b8e80941Smrg#ifndef IMGUI_DISABLE_MATH_FUNCTIONS
212b8e80941Smrgstatic inline float  ImFabs(float x)                                            { return fabsf(x); }
213b8e80941Smrgstatic inline float  ImSqrt(float x)                                            { return sqrtf(x); }
214b8e80941Smrgstatic inline float  ImPow(float x, float y)                                    { return powf(x, y); }
215b8e80941Smrgstatic inline double ImPow(double x, double y)                                  { return pow(x, y); }
216b8e80941Smrgstatic inline float  ImFmod(float x, float y)                                   { return fmodf(x, y); }
217b8e80941Smrgstatic inline double ImFmod(double x, double y)                                 { return fmod(x, y); }
218b8e80941Smrgstatic inline float  ImCos(float x)                                             { return cosf(x); }
219b8e80941Smrgstatic inline float  ImSin(float x)                                             { return sinf(x); }
220b8e80941Smrgstatic inline float  ImAcos(float x)                                            { return acosf(x); }
221b8e80941Smrgstatic inline float  ImAtan2(float y, float x)                                  { return atan2f(y, x); }
222b8e80941Smrgstatic inline double ImAtof(const char* s)                                      { return atof(s); }
223b8e80941Smrgstatic inline float  ImFloorStd(float x)                                        { return floorf(x); }   // we already uses our own ImFloor() { return (float)(int)v } internally so the standard one wrapper is named differently (it's used by stb_truetype)
224b8e80941Smrgstatic inline float  ImCeil(float x)                                            { return ceilf(x); }
225b8e80941Smrg#endif
226b8e80941Smrg// - ImMin/ImMax/ImClamp/ImLerp/ImSwap are used by widgets which support for variety of types: signed/unsigned int/long long float/double, using templates here but we could also redefine them 6 times
227b8e80941Smrgtemplate<typename T> static inline T ImMin(T lhs, T rhs)                        { return lhs < rhs ? lhs : rhs; }
228b8e80941Smrgtemplate<typename T> static inline T ImMax(T lhs, T rhs)                        { return lhs >= rhs ? lhs : rhs; }
229b8e80941Smrgtemplate<typename T> static inline T ImClamp(T v, T mn, T mx)                   { return (v < mn) ? mn : (v > mx) ? mx : v; }
230b8e80941Smrgtemplate<typename T> static inline T ImLerp(T a, T b, float t)                  { return (T)(a + (b - a) * t); }
231b8e80941Smrgtemplate<typename T> static inline void ImSwap(T& a, T& b)                      { T tmp = a; a = b; b = tmp; }
232b8e80941Smrg// - Misc maths helpers
233b8e80941Smrgstatic inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs)                { return ImVec2(lhs.x < rhs.x ? lhs.x : rhs.x, lhs.y < rhs.y ? lhs.y : rhs.y); }
234b8e80941Smrgstatic inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs)                { return ImVec2(lhs.x >= rhs.x ? lhs.x : rhs.x, lhs.y >= rhs.y ? lhs.y : rhs.y); }
235b8e80941Smrgstatic inline ImVec2 ImClamp(const ImVec2& v, const ImVec2& mn, ImVec2 mx)      { return ImVec2((v.x < mn.x) ? mn.x : (v.x > mx.x) ? mx.x : v.x, (v.y < mn.y) ? mn.y : (v.y > mx.y) ? mx.y : v.y); }
236b8e80941Smrgstatic 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); }
237b8e80941Smrgstatic 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); }
238b8e80941Smrgstatic 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); }
239b8e80941Smrgstatic inline float  ImSaturate(float f)                                        { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
240b8e80941Smrgstatic inline float  ImLengthSqr(const ImVec2& lhs)                             { return lhs.x*lhs.x + lhs.y*lhs.y; }
241b8e80941Smrgstatic inline float  ImLengthSqr(const ImVec4& lhs)                             { return lhs.x*lhs.x + lhs.y*lhs.y + lhs.z*lhs.z + lhs.w*lhs.w; }
242b8e80941Smrgstatic 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 / ImSqrt(d); return fail_value; }
243b8e80941Smrgstatic inline float  ImFloor(float f)                                           { return (float)(int)f; }
244b8e80941Smrgstatic inline ImVec2 ImFloor(const ImVec2& v)                                   { return ImVec2((float)(int)v.x, (float)(int)v.y); }
245b8e80941Smrgstatic inline float  ImDot(const ImVec2& a, const ImVec2& b)                    { return a.x * b.x + a.y * b.y; }
246b8e80941Smrgstatic 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); }
247b8e80941Smrgstatic 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; }
248b8e80941Smrgstatic inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs)                { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); }
249b8e80941Smrg
250b8e80941Smrg// Helper: ImBoolVector. Store 1-bit per value.
251b8e80941Smrg// Note that Resize() currently clears the whole vector.
252b8e80941Smrgstruct ImBoolVector
253b8e80941Smrg{
254b8e80941Smrg    ImVector<int>   Storage;
255b8e80941Smrg    ImBoolVector()  { }
256b8e80941Smrg    void            Resize(int sz)          { Storage.resize((sz + 31) >> 5); memset(Storage.Data, 0, (size_t)Storage.Size * sizeof(Storage.Data[0])); }
257b8e80941Smrg    void            Clear()                 { Storage.clear(); }
258b8e80941Smrg    bool            GetBit(int n) const     { int off = (n >> 5); int mask = 1 << (n & 31); return (Storage[off] & mask) != 0; }
259b8e80941Smrg    void            SetBit(int n, bool v)   { int off = (n >> 5); int mask = 1 << (n & 31); if (v) Storage[off] |= mask; else Storage[off] &= ~mask; }
260b8e80941Smrg};
261b8e80941Smrg
262b8e80941Smrg// Helper: ImPool<>. Basic keyed storage for contiguous instances, slow/amortized insertion, O(1) indexable, O(Log N) queries by ID over a dense/hot buffer,
263b8e80941Smrg// Honor constructor/destructor. Add/remove invalidate all pointers. Indexes have the same lifetime as the associated object.
264b8e80941Smrgtypedef int ImPoolIdx;
265b8e80941Smrgtemplate<typename T>
266b8e80941Smrgstruct IMGUI_API ImPool
267b8e80941Smrg{
268b8e80941Smrg    ImVector<T>     Data;       // Contiguous data
269b8e80941Smrg    ImGuiStorage    Map;        // ID->Index
270b8e80941Smrg    ImPoolIdx       FreeIdx;    // Next free idx to use
271b8e80941Smrg
272b8e80941Smrg    ImPool()    { FreeIdx = 0; }
273b8e80941Smrg    ~ImPool()   { Clear(); }
274b8e80941Smrg    T*          GetByKey(ImGuiID key)               { int idx = Map.GetInt(key, -1); return (idx != -1) ? &Data[idx] : NULL; }
275b8e80941Smrg    T*          GetByIndex(ImPoolIdx n)             { return &Data[n]; }
276b8e80941Smrg    ImPoolIdx   GetIndex(const T* p) const          { IM_ASSERT(p >= Data.Data && p < Data.Data + Data.Size); return (ImPoolIdx)(p - Data.Data); }
277b8e80941Smrg    T*          GetOrAddByKey(ImGuiID key)          { int* p_idx = Map.GetIntRef(key, -1); if (*p_idx != -1) return &Data[*p_idx]; *p_idx = FreeIdx; return Add(); }
278b8e80941Smrg    void        Clear()                             { for (int n = 0; n < Map.Data.Size; n++) { int idx = Map.Data[n].val_i; if (idx != -1) Data[idx].~T(); }  Map.Clear(); Data.clear(); FreeIdx = 0; }
279b8e80941Smrg    T*          Add()                               { int idx = FreeIdx; if (idx == Data.Size) { Data.resize(Data.Size + 1); FreeIdx++; } else { FreeIdx = *(int*)&Data[idx]; } IM_PLACEMENT_NEW(&Data[idx]) T(); return &Data[idx]; }
280b8e80941Smrg    void        Remove(ImGuiID key, const T* p)     { Remove(key, GetIndex(p)); }
281b8e80941Smrg    void        Remove(ImGuiID key, ImPoolIdx idx)  { Data[idx].~T(); *(int*)&Data[idx] = FreeIdx; FreeIdx = idx; Map.SetInt(key, -1); }
282b8e80941Smrg    void        Reserve(int capacity)               { Data.reserve(capacity); Map.Data.reserve(capacity); }
283b8e80941Smrg    int         GetSize() const                     { return Data.Size; }
284b8e80941Smrg};
285b8e80941Smrg
286b8e80941Smrg//-----------------------------------------------------------------------------
287b8e80941Smrg// Misc data structures
288b8e80941Smrg//-----------------------------------------------------------------------------
289b8e80941Smrg
290b8e80941Smrgenum ImGuiButtonFlags_
291b8e80941Smrg{
292b8e80941Smrg    ImGuiButtonFlags_None                   = 0,
293b8e80941Smrg    ImGuiButtonFlags_Repeat                 = 1 << 0,   // hold to repeat
294b8e80941Smrg    ImGuiButtonFlags_PressedOnClickRelease  = 1 << 1,   // return true on click + release on same item [DEFAULT if no PressedOn* flag is set]
295b8e80941Smrg    ImGuiButtonFlags_PressedOnClick         = 1 << 2,   // return true on click (default requires click+release)
296b8e80941Smrg    ImGuiButtonFlags_PressedOnRelease       = 1 << 3,   // return true on release (default requires click+release)
297b8e80941Smrg    ImGuiButtonFlags_PressedOnDoubleClick   = 1 << 4,   // return true on double-click (default requires click+release)
298b8e80941Smrg    ImGuiButtonFlags_FlattenChildren        = 1 << 5,   // allow interactions even if a child window is overlapping
299b8e80941Smrg    ImGuiButtonFlags_AllowItemOverlap       = 1 << 6,   // require previous frame HoveredId to either match id or be null before being usable, use along with SetItemAllowOverlap()
300b8e80941Smrg    ImGuiButtonFlags_DontClosePopups        = 1 << 7,   // disable automatically closing parent popup on press // [UNUSED]
301b8e80941Smrg    ImGuiButtonFlags_Disabled               = 1 << 8,   // disable interactions
302b8e80941Smrg    ImGuiButtonFlags_AlignTextBaseLine      = 1 << 9,   // vertically align button to match text baseline - ButtonEx() only // FIXME: Should be removed and handled by SmallButton(), not possible currently because of DC.CursorPosPrevLine
303b8e80941Smrg    ImGuiButtonFlags_NoKeyModifiers         = 1 << 10,  // disable interaction if a key modifier is held
304b8e80941Smrg    ImGuiButtonFlags_NoHoldingActiveID      = 1 << 11,  // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only)
305b8e80941Smrg    ImGuiButtonFlags_PressedOnDragDropHold  = 1 << 12,  // press when held into while we are drag and dropping another item (used by e.g. tree nodes, collapsing headers)
306b8e80941Smrg    ImGuiButtonFlags_NoNavFocus             = 1 << 13   // don't override navigation focus when activated
307b8e80941Smrg};
308b8e80941Smrg
309b8e80941Smrgenum ImGuiSliderFlags_
310b8e80941Smrg{
311b8e80941Smrg    ImGuiSliderFlags_None                   = 0,
312b8e80941Smrg    ImGuiSliderFlags_Vertical               = 1 << 0
313b8e80941Smrg};
314b8e80941Smrg
315b8e80941Smrgenum ImGuiDragFlags_
316b8e80941Smrg{
317b8e80941Smrg    ImGuiDragFlags_None                     = 0,
318b8e80941Smrg    ImGuiDragFlags_Vertical                 = 1 << 0
319b8e80941Smrg};
320b8e80941Smrg
321b8e80941Smrgenum ImGuiColumnsFlags_
322b8e80941Smrg{
323b8e80941Smrg    // Default: 0
324b8e80941Smrg    ImGuiColumnsFlags_None                  = 0,
325b8e80941Smrg    ImGuiColumnsFlags_NoBorder              = 1 << 0,   // Disable column dividers
326b8e80941Smrg    ImGuiColumnsFlags_NoResize              = 1 << 1,   // Disable resizing columns when clicking on the dividers
327b8e80941Smrg    ImGuiColumnsFlags_NoPreserveWidths      = 1 << 2,   // Disable column width preservation when adjusting columns
328b8e80941Smrg    ImGuiColumnsFlags_NoForceWithinWindow   = 1 << 3,   // Disable forcing columns to fit within window
329b8e80941Smrg    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.
330b8e80941Smrg};
331b8e80941Smrg
332b8e80941Smrgenum ImGuiSelectableFlagsPrivate_
333b8e80941Smrg{
334b8e80941Smrg    // NB: need to be in sync with last value of ImGuiSelectableFlags_
335b8e80941Smrg    ImGuiSelectableFlags_NoHoldingActiveID  = 1 << 10,
336b8e80941Smrg    ImGuiSelectableFlags_PressedOnClick     = 1 << 11,
337b8e80941Smrg    ImGuiSelectableFlags_PressedOnRelease   = 1 << 12,
338b8e80941Smrg    ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 13
339b8e80941Smrg};
340b8e80941Smrg
341b8e80941Smrgenum ImGuiSeparatorFlags_
342b8e80941Smrg{
343b8e80941Smrg    ImGuiSeparatorFlags_None                = 0,
344b8e80941Smrg    ImGuiSeparatorFlags_Horizontal          = 1 << 0,   // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar
345b8e80941Smrg    ImGuiSeparatorFlags_Vertical            = 1 << 1
346b8e80941Smrg};
347b8e80941Smrg
348b8e80941Smrg// Transient per-window flags, reset at the beginning of the frame. For child window, inherited from parent on first Begin().
349b8e80941Smrg// This is going to be exposed in imgui.h when stabilized enough.
350b8e80941Smrgenum ImGuiItemFlags_
351b8e80941Smrg{
352b8e80941Smrg    ImGuiItemFlags_NoTabStop                = 1 << 0,  // false
353b8e80941Smrg    ImGuiItemFlags_ButtonRepeat             = 1 << 1,  // false    // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings.
354b8e80941Smrg    ImGuiItemFlags_Disabled                 = 1 << 2,  // false    // [BETA] Disable interactions but doesn't affect visuals yet. See github.com/ocornut/imgui/issues/211
355b8e80941Smrg    ImGuiItemFlags_NoNav                    = 1 << 3,  // false
356b8e80941Smrg    ImGuiItemFlags_NoNavDefaultFocus        = 1 << 4,  // false
357b8e80941Smrg    ImGuiItemFlags_SelectableDontClosePopup = 1 << 5,  // false    // MenuItem/Selectable() automatically closes current Popup window
358b8e80941Smrg    ImGuiItemFlags_Default_                 = 0
359b8e80941Smrg};
360b8e80941Smrg
361b8e80941Smrg// Storage for LastItem data
362b8e80941Smrgenum ImGuiItemStatusFlags_
363b8e80941Smrg{
364b8e80941Smrg    ImGuiItemStatusFlags_None               = 0,
365b8e80941Smrg    ImGuiItemStatusFlags_HoveredRect        = 1 << 0,
366b8e80941Smrg    ImGuiItemStatusFlags_HasDisplayRect     = 1 << 1,
367b8e80941Smrg    ImGuiItemStatusFlags_Edited             = 1 << 2    // Value exposed by item was edited in the current frame (should match the bool return value of most widgets)
368b8e80941Smrg
369b8e80941Smrg#ifdef IMGUI_ENABLE_TEST_ENGINE
370b8e80941Smrg    , // [imgui-test only]
371b8e80941Smrg    ImGuiItemStatusFlags_Openable           = 1 << 10,  //
372b8e80941Smrg    ImGuiItemStatusFlags_Opened             = 1 << 11,  //
373b8e80941Smrg    ImGuiItemStatusFlags_Checkable          = 1 << 12,  //
374b8e80941Smrg    ImGuiItemStatusFlags_Checked            = 1 << 13   //
375b8e80941Smrg#endif
376b8e80941Smrg};
377b8e80941Smrg
378b8e80941Smrg// FIXME: this is in development, not exposed/functional as a generic feature yet.
379b8e80941Smrg// Horizontal/Vertical enums are fixed to 0/1 so they may be used to index ImVec2
380b8e80941Smrgenum ImGuiLayoutType_
381b8e80941Smrg{
382b8e80941Smrg    ImGuiLayoutType_Horizontal = 0,
383b8e80941Smrg    ImGuiLayoutType_Vertical = 1
384b8e80941Smrg};
385b8e80941Smrg
386b8e80941Smrg// X/Y enums are fixed to 0/1 so they may be used to index ImVec2
387b8e80941Smrgenum ImGuiAxis
388b8e80941Smrg{
389b8e80941Smrg    ImGuiAxis_None = -1,
390b8e80941Smrg    ImGuiAxis_X = 0,
391b8e80941Smrg    ImGuiAxis_Y = 1
392b8e80941Smrg};
393b8e80941Smrg
394b8e80941Smrgenum ImGuiPlotType
395b8e80941Smrg{
396b8e80941Smrg    ImGuiPlotType_Lines,
397b8e80941Smrg    ImGuiPlotType_Histogram
398b8e80941Smrg};
399b8e80941Smrg
400b8e80941Smrgenum ImGuiInputSource
401b8e80941Smrg{
402b8e80941Smrg    ImGuiInputSource_None = 0,
403b8e80941Smrg    ImGuiInputSource_Mouse,
404b8e80941Smrg    ImGuiInputSource_Nav,
405b8e80941Smrg    ImGuiInputSource_NavKeyboard,   // Only used occasionally for storage, not tested/handled by most code
406b8e80941Smrg    ImGuiInputSource_NavGamepad,    // "
407b8e80941Smrg    ImGuiInputSource_COUNT
408b8e80941Smrg};
409b8e80941Smrg
410b8e80941Smrg// FIXME-NAV: Clarify/expose various repeat delay/rate
411b8e80941Smrgenum ImGuiInputReadMode
412b8e80941Smrg{
413b8e80941Smrg    ImGuiInputReadMode_Down,
414b8e80941Smrg    ImGuiInputReadMode_Pressed,
415b8e80941Smrg    ImGuiInputReadMode_Released,
416b8e80941Smrg    ImGuiInputReadMode_Repeat,
417b8e80941Smrg    ImGuiInputReadMode_RepeatSlow,
418b8e80941Smrg    ImGuiInputReadMode_RepeatFast
419b8e80941Smrg};
420b8e80941Smrg
421b8e80941Smrgenum ImGuiNavHighlightFlags_
422b8e80941Smrg{
423b8e80941Smrg    ImGuiNavHighlightFlags_None         = 0,
424b8e80941Smrg    ImGuiNavHighlightFlags_TypeDefault  = 1 << 0,
425b8e80941Smrg    ImGuiNavHighlightFlags_TypeThin     = 1 << 1,
426b8e80941Smrg    ImGuiNavHighlightFlags_AlwaysDraw   = 1 << 2,       // Draw rectangular highlight if (g.NavId == id) _even_ when using the mouse.
427b8e80941Smrg    ImGuiNavHighlightFlags_NoRounding   = 1 << 3
428b8e80941Smrg};
429b8e80941Smrg
430b8e80941Smrgenum ImGuiNavDirSourceFlags_
431b8e80941Smrg{
432b8e80941Smrg    ImGuiNavDirSourceFlags_None         = 0,
433b8e80941Smrg    ImGuiNavDirSourceFlags_Keyboard     = 1 << 0,
434b8e80941Smrg    ImGuiNavDirSourceFlags_PadDPad      = 1 << 1,
435b8e80941Smrg    ImGuiNavDirSourceFlags_PadLStick    = 1 << 2
436b8e80941Smrg};
437b8e80941Smrg
438b8e80941Smrgenum ImGuiNavMoveFlags_
439b8e80941Smrg{
440b8e80941Smrg    ImGuiNavMoveFlags_None                  = 0,
441b8e80941Smrg    ImGuiNavMoveFlags_LoopX                 = 1 << 0,   // On failed request, restart from opposite side
442b8e80941Smrg    ImGuiNavMoveFlags_LoopY                 = 1 << 1,
443b8e80941Smrg    ImGuiNavMoveFlags_WrapX                 = 1 << 2,   // On failed request, request from opposite side one line down (when NavDir==right) or one line up (when NavDir==left)
444b8e80941Smrg    ImGuiNavMoveFlags_WrapY                 = 1 << 3,   // This is not super useful for provided for completeness
445b8e80941Smrg    ImGuiNavMoveFlags_AllowCurrentNavId     = 1 << 4,   // Allow scoring and considering the current NavId as a move target candidate. This is used when the move source is offset (e.g. pressing PageDown actually needs to send a Up move request, if we are pressing PageDown from the bottom-most item we need to stay in place)
446b8e80941Smrg    ImGuiNavMoveFlags_AlsoScoreVisibleSet   = 1 << 5    // Store alternate result in NavMoveResultLocalVisibleSet that only comprise elements that are already fully visible.
447b8e80941Smrg};
448b8e80941Smrg
449b8e80941Smrgenum ImGuiNavForward
450b8e80941Smrg{
451b8e80941Smrg    ImGuiNavForward_None,
452b8e80941Smrg    ImGuiNavForward_ForwardQueued,
453b8e80941Smrg    ImGuiNavForward_ForwardActive
454b8e80941Smrg};
455b8e80941Smrg
456b8e80941Smrgenum ImGuiNavLayer
457b8e80941Smrg{
458b8e80941Smrg    ImGuiNavLayer_Main  = 0,    // Main scrolling layer
459b8e80941Smrg    ImGuiNavLayer_Menu  = 1,    // Menu layer (access with Alt/ImGuiNavInput_Menu)
460b8e80941Smrg    ImGuiNavLayer_COUNT
461b8e80941Smrg};
462b8e80941Smrg
463b8e80941Smrgenum ImGuiPopupPositionPolicy
464b8e80941Smrg{
465b8e80941Smrg    ImGuiPopupPositionPolicy_Default,
466b8e80941Smrg    ImGuiPopupPositionPolicy_ComboBox
467b8e80941Smrg};
468b8e80941Smrg
469b8e80941Smrg// 1D vector (this odd construct is used to facilitate the transition between 1D and 2D, and the maintenance of some branches/patches)
470b8e80941Smrgstruct ImVec1
471b8e80941Smrg{
472b8e80941Smrg    float   x;
473b8e80941Smrg    ImVec1()         { x = 0.0f; }
474b8e80941Smrg    ImVec1(float _x) { x = _x; }
475b8e80941Smrg};
476b8e80941Smrg
477b8e80941Smrg
478b8e80941Smrg// 2D axis aligned bounding-box
479b8e80941Smrg// NB: we can't rely on ImVec2 math operators being available here
480b8e80941Smrgstruct IMGUI_API ImRect
481b8e80941Smrg{
482b8e80941Smrg    ImVec2      Min;    // Upper-left
483b8e80941Smrg    ImVec2      Max;    // Lower-right
484b8e80941Smrg
485b8e80941Smrg    ImRect()                                        : Min(FLT_MAX,FLT_MAX), Max(-FLT_MAX,-FLT_MAX)  {}
486b8e80941Smrg    ImRect(const ImVec2& min, const ImVec2& max)    : Min(min), Max(max)                            {}
487b8e80941Smrg    ImRect(const ImVec4& v)                         : Min(v.x, v.y), Max(v.z, v.w)                  {}
488b8e80941Smrg    ImRect(float x1, float y1, float x2, float y2)  : Min(x1, y1), Max(x2, y2)                      {}
489b8e80941Smrg
490b8e80941Smrg    ImVec2      GetCenter() const                   { return ImVec2((Min.x + Max.x) * 0.5f, (Min.y + Max.y) * 0.5f); }
491b8e80941Smrg    ImVec2      GetSize() const                     { return ImVec2(Max.x - Min.x, Max.y - Min.y); }
492b8e80941Smrg    float       GetWidth() const                    { return Max.x - Min.x; }
493b8e80941Smrg    float       GetHeight() const                   { return Max.y - Min.y; }
494b8e80941Smrg    ImVec2      GetTL() const                       { return Min; }                   // Top-left
495b8e80941Smrg    ImVec2      GetTR() const                       { return ImVec2(Max.x, Min.y); }  // Top-right
496b8e80941Smrg    ImVec2      GetBL() const                       { return ImVec2(Min.x, Max.y); }  // Bottom-left
497b8e80941Smrg    ImVec2      GetBR() const                       { return Max; }                   // Bottom-right
498b8e80941Smrg    bool        Contains(const ImVec2& p) const     { return p.x     >= Min.x && p.y     >= Min.y && p.x     <  Max.x && p.y     <  Max.y; }
499b8e80941Smrg    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; }
500b8e80941Smrg    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; }
501b8e80941Smrg    void        Add(const ImVec2& p)                { if (Min.x > p.x)     Min.x = p.x;     if (Min.y > p.y)     Min.y = p.y;     if (Max.x < p.x)     Max.x = p.x;     if (Max.y < p.y)     Max.y = p.y; }
502b8e80941Smrg    void        Add(const ImRect& r)                { if (Min.x > r.Min.x) Min.x = r.Min.x; if (Min.y > r.Min.y) Min.y = r.Min.y; if (Max.x < r.Max.x) Max.x = r.Max.x; if (Max.y < r.Max.y) Max.y = r.Max.y; }
503b8e80941Smrg    void        Expand(const float amount)          { Min.x -= amount;   Min.y -= amount;   Max.x += amount;   Max.y += amount; }
504b8e80941Smrg    void        Expand(const ImVec2& amount)        { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; }
505b8e80941Smrg    void        Translate(const ImVec2& d)          { Min.x += d.x; Min.y += d.y; Max.x += d.x; Max.y += d.y; }
506b8e80941Smrg    void        TranslateX(float dx)                { Min.x += dx; Max.x += dx; }
507b8e80941Smrg    void        TranslateY(float dy)                { Min.y += dy; Max.y += dy; }
508b8e80941Smrg    void        ClipWith(const ImRect& r)           { Min = ImMax(Min, r.Min); Max = ImMin(Max, r.Max); }                   // Simple version, may lead to an inverted rectangle, which is fine for Contains/Overlaps test but not for display.
509b8e80941Smrg    void        ClipWithFull(const ImRect& r)       { Min = ImClamp(Min, r.Min, r.Max); Max = ImClamp(Max, r.Min, r.Max); } // Full version, ensure both points are fully clipped.
510b8e80941Smrg    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; }
511b8e80941Smrg    bool        IsInverted() const                  { return Min.x > Max.x || Min.y > Max.y; }
512b8e80941Smrg};
513b8e80941Smrg
514b8e80941Smrg// Stacked color modifier, backup of modified data so we can restore it
515b8e80941Smrgstruct ImGuiColorMod
516b8e80941Smrg{
517b8e80941Smrg    ImGuiCol    Col;
518b8e80941Smrg    ImVec4      BackupValue;
519b8e80941Smrg};
520b8e80941Smrg
521b8e80941Smrg// Stacked style modifier, backup of modified data so we can restore it. Data type inferred from the variable.
522b8e80941Smrgstruct ImGuiStyleMod
523b8e80941Smrg{
524b8e80941Smrg    ImGuiStyleVar   VarIdx;
525b8e80941Smrg    union           { int BackupInt[2]; float BackupFloat[2]; };
526b8e80941Smrg    ImGuiStyleMod(ImGuiStyleVar idx, int v)     { VarIdx = idx; BackupInt[0] = v; }
527b8e80941Smrg    ImGuiStyleMod(ImGuiStyleVar idx, float v)   { VarIdx = idx; BackupFloat[0] = v; }
528b8e80941Smrg    ImGuiStyleMod(ImGuiStyleVar idx, ImVec2 v)  { VarIdx = idx; BackupFloat[0] = v.x; BackupFloat[1] = v.y; }
529b8e80941Smrg};
530b8e80941Smrg
531b8e80941Smrg// Stacked storage data for BeginGroup()/EndGroup()
532b8e80941Smrgstruct ImGuiGroupData
533b8e80941Smrg{
534b8e80941Smrg    ImVec2      BackupCursorPos;
535b8e80941Smrg    ImVec2      BackupCursorMaxPos;
536b8e80941Smrg    ImVec1      BackupIndent;
537b8e80941Smrg    ImVec1      BackupGroupOffset;
538b8e80941Smrg    ImVec2      BackupCurrentLineSize;
539b8e80941Smrg    float       BackupCurrentLineTextBaseOffset;
540b8e80941Smrg    float       BackupLogLinePosY;
541b8e80941Smrg    ImGuiID     BackupActiveIdIsAlive;
542b8e80941Smrg    bool        BackupActiveIdPreviousFrameIsAlive;
543b8e80941Smrg    bool        AdvanceCursor;
544b8e80941Smrg};
545b8e80941Smrg
546b8e80941Smrg// Simple column measurement, currently used for MenuItem() only.. This is very short-sighted/throw-away code and NOT a generic helper.
547b8e80941Smrgstruct IMGUI_API ImGuiMenuColumns
548b8e80941Smrg{
549b8e80941Smrg    int         Count;
550b8e80941Smrg    float       Spacing;
551b8e80941Smrg    float       Width, NextWidth;
552b8e80941Smrg    float       Pos[4], NextWidths[4];
553b8e80941Smrg
554b8e80941Smrg    ImGuiMenuColumns();
555b8e80941Smrg    void        Update(int count, float spacing, bool clear);
556b8e80941Smrg    float       DeclColumns(float w0, float w1, float w2);
557b8e80941Smrg    float       CalcExtraSpace(float avail_w);
558b8e80941Smrg};
559b8e80941Smrg
560b8e80941Smrg// Internal state of the currently focused/edited text input box
561b8e80941Smrgstruct IMGUI_API ImGuiInputTextState
562b8e80941Smrg{
563b8e80941Smrg    ImGuiID                 ID;                     // widget id owning the text state
564b8e80941Smrg    ImVector<ImWchar>       TextW;                  // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer.
565b8e80941Smrg    ImVector<char>          InitialText;            // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
566b8e80941Smrg    ImVector<char>          TempBuffer;             // temporary buffer for callback and other other operations. size=capacity.
567b8e80941Smrg    int                     CurLenA, CurLenW;       // we need to maintain our buffer length in both UTF-8 and wchar format.
568b8e80941Smrg    int                     BufCapacityA;           // end-user buffer capacity
569b8e80941Smrg    float                   ScrollX;
570b8e80941Smrg    ImGuiStb::STB_TexteditState StbState;
571b8e80941Smrg    float                   CursorAnim;
572b8e80941Smrg    bool                    CursorFollow;
573b8e80941Smrg    bool                    SelectedAllMouseLock;
574b8e80941Smrg
575b8e80941Smrg    // Temporarily set when active
576b8e80941Smrg    ImGuiInputTextFlags     UserFlags;
577b8e80941Smrg    ImGuiInputTextCallback  UserCallback;
578b8e80941Smrg    void*                   UserCallbackData;
579b8e80941Smrg
580b8e80941Smrg    ImGuiInputTextState()                           { memset(this, 0, sizeof(*this)); }
581b8e80941Smrg    void                CursorAnimReset()           { CursorAnim = -0.30f; }                                   // After a user-input the cursor stays on for a while without blinking
582b8e80941Smrg    void                CursorClamp()               { StbState.cursor = ImMin(StbState.cursor, CurLenW); StbState.select_start = ImMin(StbState.select_start, CurLenW); StbState.select_end = ImMin(StbState.select_end, CurLenW); }
583b8e80941Smrg    bool                HasSelection() const        { return StbState.select_start != StbState.select_end; }
584b8e80941Smrg    void                ClearSelection()            { StbState.select_start = StbState.select_end = StbState.cursor; }
585b8e80941Smrg    void                SelectAll()                 { StbState.select_start = 0; StbState.cursor = StbState.select_end = CurLenW; StbState.has_preferred_x = 0; }
586b8e80941Smrg    void                OnKeyPressed(int key);      // Cannot be inline because we call in code in stb_textedit.h implementation
587b8e80941Smrg};
588b8e80941Smrg
589b8e80941Smrg// Windows data saved in imgui.ini file
590b8e80941Smrgstruct ImGuiWindowSettings
591b8e80941Smrg{
592b8e80941Smrg    char*       Name;
593b8e80941Smrg    ImGuiID     ID;
594b8e80941Smrg    ImVec2      Pos;
595b8e80941Smrg    ImVec2      Size;
596b8e80941Smrg    bool        Collapsed;
597b8e80941Smrg
598b8e80941Smrg    ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ImVec2(0,0); Collapsed = false; }
599b8e80941Smrg};
600b8e80941Smrg
601b8e80941Smrgstruct ImGuiSettingsHandler
602b8e80941Smrg{
603b8e80941Smrg    const char* TypeName;       // Short description stored in .ini file. Disallowed characters: '[' ']'
604b8e80941Smrg    ImGuiID     TypeHash;       // == ImHashStr(TypeName, 0, 0)
605b8e80941Smrg    void*       (*ReadOpenFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name);              // Read: Called when entering into a new ini entry e.g. "[Window][Name]"
606b8e80941Smrg    void        (*ReadLineFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line); // Read: Called for every line of text within an ini entry
607b8e80941Smrg    void        (*WriteAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf);      // Write: Output every entries into 'out_buf'
608b8e80941Smrg    void*       UserData;
609b8e80941Smrg
610b8e80941Smrg    ImGuiSettingsHandler() { memset(this, 0, sizeof(*this)); }
611b8e80941Smrg};
612b8e80941Smrg
613b8e80941Smrg// Storage for current popup stack
614b8e80941Smrgstruct ImGuiPopupRef
615b8e80941Smrg{
616b8e80941Smrg    ImGuiID             PopupId;        // Set on OpenPopup()
617b8e80941Smrg    ImGuiWindow*        Window;         // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup()
618b8e80941Smrg    ImGuiWindow*        ParentWindow;   // Set on OpenPopup()
619b8e80941Smrg    int                 OpenFrameCount; // Set on OpenPopup()
620b8e80941Smrg    ImGuiID             OpenParentId;   // Set on OpenPopup(), we need this to differenciate multiple menu sets from each others (e.g. inside menu bar vs loose menu items)
621b8e80941Smrg    ImVec2              OpenPopupPos;   // Set on OpenPopup(), preferred popup position (typically == OpenMousePos when using mouse)
622b8e80941Smrg    ImVec2              OpenMousePos;   // Set on OpenPopup(), copy of mouse position at the time of opening popup
623b8e80941Smrg};
624b8e80941Smrg
625b8e80941Smrgstruct ImGuiColumnData
626b8e80941Smrg{
627b8e80941Smrg    float               OffsetNorm;         // Column start offset, normalized 0.0 (far left) -> 1.0 (far right)
628b8e80941Smrg    float               OffsetNormBeforeResize;
629b8e80941Smrg    ImGuiColumnsFlags   Flags;              // Not exposed
630b8e80941Smrg    ImRect              ClipRect;
631b8e80941Smrg
632b8e80941Smrg    ImGuiColumnData()   { OffsetNorm = OffsetNormBeforeResize = 0.0f; Flags = 0; }
633b8e80941Smrg};
634b8e80941Smrg
635b8e80941Smrgstruct ImGuiColumnsSet
636b8e80941Smrg{
637b8e80941Smrg    ImGuiID             ID;
638b8e80941Smrg    ImGuiColumnsFlags   Flags;
639b8e80941Smrg    bool                IsFirstFrame;
640b8e80941Smrg    bool                IsBeingResized;
641b8e80941Smrg    int                 Current;
642b8e80941Smrg    int                 Count;
643b8e80941Smrg    float               MinX, MaxX;
644b8e80941Smrg    float               LineMinY, LineMaxY;
645b8e80941Smrg    float               StartPosY;          // Copy of CursorPos
646b8e80941Smrg    float               StartMaxPosX;       // Copy of CursorMaxPos
647b8e80941Smrg    ImVector<ImGuiColumnData> Columns;
648b8e80941Smrg
649b8e80941Smrg    ImGuiColumnsSet()   { Clear(); }
650b8e80941Smrg    void Clear()
651b8e80941Smrg    {
652b8e80941Smrg        ID = 0;
653b8e80941Smrg        Flags = 0;
654b8e80941Smrg        IsFirstFrame = false;
655b8e80941Smrg        IsBeingResized = false;
656b8e80941Smrg        Current = 0;
657b8e80941Smrg        Count = 1;
658b8e80941Smrg        MinX = MaxX = 0.0f;
659b8e80941Smrg        LineMinY = LineMaxY = 0.0f;
660b8e80941Smrg        StartPosY = 0.0f;
661b8e80941Smrg        StartMaxPosX = 0.0f;
662b8e80941Smrg        Columns.clear();
663b8e80941Smrg    }
664b8e80941Smrg};
665b8e80941Smrg
666b8e80941Smrg// Data shared between all ImDrawList instances
667b8e80941Smrgstruct IMGUI_API ImDrawListSharedData
668b8e80941Smrg{
669b8e80941Smrg    ImVec2          TexUvWhitePixel;            // UV of white pixel in the atlas
670b8e80941Smrg    ImFont*         Font;                       // Current/default font (optional, for simplified AddText overload)
671b8e80941Smrg    float           FontSize;                   // Current/default font size (optional, for simplified AddText overload)
672b8e80941Smrg    float           CurveTessellationTol;
673b8e80941Smrg    ImVec4          ClipRectFullscreen;         // Value for PushClipRectFullscreen()
674b8e80941Smrg
675b8e80941Smrg    // Const data
676b8e80941Smrg    // FIXME: Bake rounded corners fill/borders in atlas
677b8e80941Smrg    ImVec2          CircleVtx12[12];
678b8e80941Smrg
679b8e80941Smrg    ImDrawListSharedData();
680b8e80941Smrg};
681b8e80941Smrg
682b8e80941Smrgstruct ImDrawDataBuilder
683b8e80941Smrg{
684b8e80941Smrg    ImVector<ImDrawList*>   Layers[2];           // Global layers for: regular, tooltip
685b8e80941Smrg
686b8e80941Smrg    void Clear()            { for (int n = 0; n < IM_ARRAYSIZE(Layers); n++) Layers[n].resize(0); }
687b8e80941Smrg    void ClearFreeMemory()  { for (int n = 0; n < IM_ARRAYSIZE(Layers); n++) Layers[n].clear(); }
688b8e80941Smrg    IMGUI_API void FlattenIntoSingleLayer();
689b8e80941Smrg};
690b8e80941Smrg
691b8e80941Smrgstruct ImGuiNavMoveResult
692b8e80941Smrg{
693b8e80941Smrg    ImGuiID       ID;           // Best candidate
694b8e80941Smrg    ImGuiID       SelectScopeId;// Best candidate window current selectable group ID
695b8e80941Smrg    ImGuiWindow*  Window;       // Best candidate window
696b8e80941Smrg    float         DistBox;      // Best candidate box distance to current NavId
697b8e80941Smrg    float         DistCenter;   // Best candidate center distance to current NavId
698b8e80941Smrg    float         DistAxial;
699b8e80941Smrg    ImRect        RectRel;      // Best candidate bounding box in window relative space
700b8e80941Smrg
701b8e80941Smrg    ImGuiNavMoveResult() { Clear(); }
702b8e80941Smrg    void Clear()         { ID = SelectScopeId = 0; Window = NULL; DistBox = DistCenter = DistAxial = FLT_MAX; RectRel = ImRect(); }
703b8e80941Smrg};
704b8e80941Smrg
705b8e80941Smrg// Storage for SetNexWindow** functions
706b8e80941Smrgstruct ImGuiNextWindowData
707b8e80941Smrg{
708b8e80941Smrg    ImGuiCond               PosCond;
709b8e80941Smrg    ImGuiCond               SizeCond;
710b8e80941Smrg    ImGuiCond               ContentSizeCond;
711b8e80941Smrg    ImGuiCond               CollapsedCond;
712b8e80941Smrg    ImGuiCond               SizeConstraintCond;
713b8e80941Smrg    ImGuiCond               FocusCond;
714b8e80941Smrg    ImGuiCond               BgAlphaCond;
715b8e80941Smrg    ImVec2                  PosVal;
716b8e80941Smrg    ImVec2                  PosPivotVal;
717b8e80941Smrg    ImVec2                  SizeVal;
718b8e80941Smrg    ImVec2                  ContentSizeVal;
719b8e80941Smrg    bool                    CollapsedVal;
720b8e80941Smrg    ImRect                  SizeConstraintRect;
721b8e80941Smrg    ImGuiSizeCallback       SizeCallback;
722b8e80941Smrg    void*                   SizeCallbackUserData;
723b8e80941Smrg    float                   BgAlphaVal;
724b8e80941Smrg    ImVec2                  MenuBarOffsetMinVal;                // This is not exposed publicly, so we don't clear it.
725b8e80941Smrg
726b8e80941Smrg    ImGuiNextWindowData()
727b8e80941Smrg    {
728b8e80941Smrg        PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = BgAlphaCond = 0;
729b8e80941Smrg        PosVal = PosPivotVal = SizeVal = ImVec2(0.0f, 0.0f);
730b8e80941Smrg        ContentSizeVal = ImVec2(0.0f, 0.0f);
731b8e80941Smrg        CollapsedVal = false;
732b8e80941Smrg        SizeConstraintRect = ImRect();
733b8e80941Smrg        SizeCallback = NULL;
734b8e80941Smrg        SizeCallbackUserData = NULL;
735b8e80941Smrg        BgAlphaVal = FLT_MAX;
736b8e80941Smrg        MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f);
737b8e80941Smrg    }
738b8e80941Smrg
739b8e80941Smrg    void    Clear()
740b8e80941Smrg    {
741b8e80941Smrg        PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = BgAlphaCond = 0;
742b8e80941Smrg    }
743b8e80941Smrg};
744b8e80941Smrg
745b8e80941Smrg//-----------------------------------------------------------------------------
746b8e80941Smrg// Tabs
747b8e80941Smrg//-----------------------------------------------------------------------------
748b8e80941Smrg
749b8e80941Smrgstruct ImGuiTabBarSortItem
750b8e80941Smrg{
751b8e80941Smrg    int         Index;
752b8e80941Smrg    float       Width;
753b8e80941Smrg};
754b8e80941Smrg
755b8e80941Smrg//-----------------------------------------------------------------------------
756b8e80941Smrg// Main imgui context
757b8e80941Smrg//-----------------------------------------------------------------------------
758b8e80941Smrg
759b8e80941Smrgstruct ImGuiContext
760b8e80941Smrg{
761b8e80941Smrg    bool                    Initialized;
762b8e80941Smrg    bool                    FrameScopeActive;                   // Set by NewFrame(), cleared by EndFrame()
763b8e80941Smrg    bool                    FrameScopePushedImplicitWindow;     // Set by NewFrame(), cleared by EndFrame()
764b8e80941Smrg    bool                    FontAtlasOwnedByContext;            // Io.Fonts-> is owned by the ImGuiContext and will be destructed along with it.
765b8e80941Smrg    ImGuiIO                 IO;
766b8e80941Smrg    ImGuiStyle              Style;
767b8e80941Smrg    ImFont*                 Font;                               // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
768b8e80941Smrg    float                   FontSize;                           // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize(). Text height for current window.
769b8e80941Smrg    float                   FontBaseSize;                       // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Base text height.
770b8e80941Smrg    ImDrawListSharedData    DrawListSharedData;
771b8e80941Smrg
772b8e80941Smrg    double                  Time;
773b8e80941Smrg    int                     FrameCount;
774b8e80941Smrg    int                     FrameCountEnded;
775b8e80941Smrg    int                     FrameCountRendered;
776b8e80941Smrg    ImVector<ImGuiWindow*>  Windows;                            // Windows, sorted in display order, back to front
777b8e80941Smrg    ImVector<ImGuiWindow*>  WindowsFocusOrder;                  // Windows, sorted in focus order, back to front
778b8e80941Smrg    ImVector<ImGuiWindow*>  WindowsSortBuffer;
779b8e80941Smrg    ImVector<ImGuiWindow*>  CurrentWindowStack;
780b8e80941Smrg    ImGuiStorage            WindowsById;
781b8e80941Smrg    int                     WindowsActiveCount;
782b8e80941Smrg    ImGuiWindow*            CurrentWindow;                      // Being drawn into
783b8e80941Smrg    ImGuiWindow*            HoveredWindow;                      // Will catch mouse inputs
784b8e80941Smrg    ImGuiWindow*            HoveredRootWindow;                  // Will catch mouse inputs (for focus/move only)
785b8e80941Smrg    ImGuiID                 HoveredId;                          // Hovered widget
786b8e80941Smrg    bool                    HoveredIdAllowOverlap;
787b8e80941Smrg    ImGuiID                 HoveredIdPreviousFrame;
788b8e80941Smrg    float                   HoveredIdTimer;                     // Measure contiguous hovering time
789b8e80941Smrg    float                   HoveredIdNotActiveTimer;            // Measure contiguous hovering time where the item has not been active
790b8e80941Smrg    ImGuiID                 ActiveId;                           // Active widget
791b8e80941Smrg    ImGuiID                 ActiveIdPreviousFrame;
792b8e80941Smrg    ImGuiID                 ActiveIdIsAlive;                    // Active widget has been seen this frame (we can't use a bool as the ActiveId may change within the frame)
793b8e80941Smrg    float                   ActiveIdTimer;
794b8e80941Smrg    bool                    ActiveIdIsJustActivated;            // Set at the time of activation for one frame
795b8e80941Smrg    bool                    ActiveIdAllowOverlap;               // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always)
796b8e80941Smrg    bool                    ActiveIdHasBeenPressed;             // Track whether the active id led to a press (this is to allow changing between PressOnClick and PressOnRelease without pressing twice). Used by range_select branch.
797b8e80941Smrg    bool                    ActiveIdHasBeenEdited;              // Was the value associated to the widget Edited over the course of the Active state.
798b8e80941Smrg    bool                    ActiveIdPreviousFrameIsAlive;
799b8e80941Smrg    bool                    ActiveIdPreviousFrameHasBeenEdited;
800b8e80941Smrg    int                     ActiveIdAllowNavDirFlags;           // Active widget allows using directional navigation (e.g. can activate a button and move away from it)
801b8e80941Smrg    int                     ActiveIdBlockNavInputFlags;
802b8e80941Smrg    ImVec2                  ActiveIdClickOffset;                // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior)
803b8e80941Smrg    ImGuiWindow*            ActiveIdWindow;
804b8e80941Smrg    ImGuiWindow*            ActiveIdPreviousFrameWindow;
805b8e80941Smrg    ImGuiInputSource        ActiveIdSource;                     // Activating with mouse or nav (gamepad/keyboard)
806b8e80941Smrg    ImGuiID                 LastActiveId;                       // Store the last non-zero ActiveId, useful for animation.
807b8e80941Smrg    float                   LastActiveIdTimer;                  // Store the last non-zero ActiveId timer since the beginning of activation, useful for animation.
808b8e80941Smrg    ImVec2                  LastValidMousePos;
809b8e80941Smrg    ImGuiWindow*            MovingWindow;                       // Track the window we clicked on (in order to preserve focus). The actually window that is moved is generally MovingWindow->RootWindow.
810b8e80941Smrg    ImVector<ImGuiColorMod> ColorModifiers;                     // Stack for PushStyleColor()/PopStyleColor()
811b8e80941Smrg    ImVector<ImGuiStyleMod> StyleModifiers;                     // Stack for PushStyleVar()/PopStyleVar()
812b8e80941Smrg    ImVector<ImFont*>       FontStack;                          // Stack for PushFont()/PopFont()
813b8e80941Smrg    ImVector<ImGuiPopupRef> OpenPopupStack;                     // Which popups are open (persistent)
814b8e80941Smrg    ImVector<ImGuiPopupRef> BeginPopupStack;                    // Which level of BeginPopup() we are in (reset every frame)
815b8e80941Smrg    ImGuiNextWindowData     NextWindowData;                     // Storage for SetNextWindow** functions
816b8e80941Smrg    bool                    NextTreeNodeOpenVal;                // Storage for SetNextTreeNode** functions
817b8e80941Smrg    ImGuiCond               NextTreeNodeOpenCond;
818b8e80941Smrg
819b8e80941Smrg    // Navigation data (for gamepad/keyboard)
820b8e80941Smrg    ImGuiWindow*            NavWindow;                          // Focused window for navigation. Could be called 'FocusWindow'
821b8e80941Smrg    ImGuiID                 NavId;                              // Focused item for navigation
822b8e80941Smrg    ImGuiID                 NavActivateId;                      // ~~ (g.ActiveId == 0) && IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0, also set when calling ActivateItem()
823b8e80941Smrg    ImGuiID                 NavActivateDownId;                  // ~~ IsNavInputDown(ImGuiNavInput_Activate) ? NavId : 0
824b8e80941Smrg    ImGuiID                 NavActivatePressedId;               // ~~ IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0
825b8e80941Smrg    ImGuiID                 NavInputId;                         // ~~ IsNavInputPressed(ImGuiNavInput_Input) ? NavId : 0
826b8e80941Smrg    ImGuiID                 NavJustTabbedId;                    // Just tabbed to this id.
827b8e80941Smrg    ImGuiID                 NavJustMovedToId;                   // Just navigated to this id (result of a successfully MoveRequest).
828b8e80941Smrg    ImGuiID                 NavJustMovedToSelectScopeId;        // Just navigated to this select scope id (result of a successfully MoveRequest).
829b8e80941Smrg    ImGuiID                 NavNextActivateId;                  // Set by ActivateItem(), queued until next frame.
830b8e80941Smrg    ImGuiInputSource        NavInputSource;                     // Keyboard or Gamepad mode? THIS WILL ONLY BE None or NavGamepad or NavKeyboard.
831b8e80941Smrg    ImRect                  NavScoringRectScreen;               // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring.
832b8e80941Smrg    int                     NavScoringCount;                    // Metrics for debugging
833b8e80941Smrg    ImGuiWindow*            NavWindowingTarget;                 // When selecting a window (holding Menu+FocusPrev/Next, or equivalent of CTRL-TAB) this window is temporarily displayed front-most.
834b8e80941Smrg    ImGuiWindow*            NavWindowingTargetAnim;             // Record of last valid NavWindowingTarget until DimBgRatio and NavWindowingHighlightAlpha becomes 0.0f
835b8e80941Smrg    ImGuiWindow*            NavWindowingList;
836b8e80941Smrg    float                   NavWindowingTimer;
837b8e80941Smrg    float                   NavWindowingHighlightAlpha;
838b8e80941Smrg    bool                    NavWindowingToggleLayer;
839b8e80941Smrg    ImGuiNavLayer           NavLayer;                           // Layer we are navigating on. For now the system is hard-coded for 0=main contents and 1=menu/title bar, may expose layers later.
840b8e80941Smrg    int                     NavIdTabCounter;                    // == NavWindow->DC.FocusIdxTabCounter at time of NavId processing
841b8e80941Smrg    bool                    NavIdIsAlive;                       // Nav widget has been seen this frame ~~ NavRefRectRel is valid
842b8e80941Smrg    bool                    NavMousePosDirty;                   // When set we will update mouse position if (io.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos) if set (NB: this not enabled by default)
843b8e80941Smrg    bool                    NavDisableHighlight;                // When user starts using mouse, we hide gamepad/keyboard highlight (NB: but they are still available, which is why NavDisableHighlight isn't always != NavDisableMouseHover)
844b8e80941Smrg    bool                    NavDisableMouseHover;               // When user starts using gamepad/keyboard, we hide mouse hovering highlight until mouse is touched again.
845b8e80941Smrg    bool                    NavAnyRequest;                      // ~~ NavMoveRequest || NavInitRequest
846b8e80941Smrg    bool                    NavInitRequest;                     // Init request for appearing window to select first item
847b8e80941Smrg    bool                    NavInitRequestFromMove;
848b8e80941Smrg    ImGuiID                 NavInitResultId;
849b8e80941Smrg    ImRect                  NavInitResultRectRel;
850b8e80941Smrg    bool                    NavMoveFromClampedRefRect;          // Set by manual scrolling, if we scroll to a point where NavId isn't visible we reset navigation from visible items
851b8e80941Smrg    bool                    NavMoveRequest;                     // Move request for this frame
852b8e80941Smrg    ImGuiNavMoveFlags       NavMoveRequestFlags;
853b8e80941Smrg    ImGuiNavForward         NavMoveRequestForward;              // None / ForwardQueued / ForwardActive (this is used to navigate sibling parent menus from a child menu)
854b8e80941Smrg    ImGuiDir                NavMoveDir, NavMoveDirLast;         // Direction of the move request (left/right/up/down), direction of the previous move request
855b8e80941Smrg    ImGuiDir                NavMoveClipDir;
856b8e80941Smrg    ImGuiNavMoveResult      NavMoveResultLocal;                 // Best move request candidate within NavWindow
857b8e80941Smrg    ImGuiNavMoveResult      NavMoveResultLocalVisibleSet;       // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag)
858b8e80941Smrg    ImGuiNavMoveResult      NavMoveResultOther;                 // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag)
859b8e80941Smrg
860b8e80941Smrg    // Render
861b8e80941Smrg    ImDrawData              DrawData;                           // Main ImDrawData instance to pass render information to the user
862b8e80941Smrg    ImDrawDataBuilder       DrawDataBuilder;
863b8e80941Smrg    float                   DimBgRatio;                         // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list)
864b8e80941Smrg    ImDrawList              OverlayDrawList;                    // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays
865b8e80941Smrg    ImGuiMouseCursor        MouseCursor;
866b8e80941Smrg
867b8e80941Smrg    // Drag and Drop
868b8e80941Smrg    bool                    DragDropActive;
869b8e80941Smrg    bool                    DragDropWithinSourceOrTarget;
870b8e80941Smrg    ImGuiDragDropFlags      DragDropSourceFlags;
871b8e80941Smrg    int                     DragDropSourceFrameCount;
872b8e80941Smrg    int                     DragDropMouseButton;
873b8e80941Smrg    ImGuiPayload            DragDropPayload;
874b8e80941Smrg    ImRect                  DragDropTargetRect;
875b8e80941Smrg    ImGuiID                 DragDropTargetId;
876b8e80941Smrg    ImGuiDragDropFlags      DragDropAcceptFlags;
877b8e80941Smrg    float                   DragDropAcceptIdCurrRectSurface;    // Target item surface (we resolve overlapping targets by prioritizing the smaller surface)
878b8e80941Smrg    ImGuiID                 DragDropAcceptIdCurr;               // Target item id (set at the time of accepting the payload)
879b8e80941Smrg    ImGuiID                 DragDropAcceptIdPrev;               // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets)
880b8e80941Smrg    int                     DragDropAcceptFrameCount;           // Last time a target expressed a desire to accept the source
881b8e80941Smrg    ImVector<unsigned char> DragDropPayloadBufHeap;             // We don't expose the ImVector<> directly
882b8e80941Smrg    unsigned char           DragDropPayloadBufLocal[8];         // Local buffer for small payloads
883b8e80941Smrg
884b8e80941Smrg    // Tab bars
885b8e80941Smrg    ImPool<ImGuiTabBar>     TabBars;
886b8e80941Smrg    ImVector<ImGuiTabBar*>  CurrentTabBar;
887b8e80941Smrg    ImVector<ImGuiTabBarSortItem>   TabSortByWidthBuffer;
888b8e80941Smrg
889b8e80941Smrg    // Widget state
890b8e80941Smrg    ImGuiInputTextState     InputTextState;
891b8e80941Smrg    ImFont                  InputTextPasswordFont;
892b8e80941Smrg    ImGuiID                 ScalarAsInputTextId;                // Temporary text input when CTRL+clicking on a slider, etc.
893b8e80941Smrg    ImGuiColorEditFlags     ColorEditOptions;                   // Store user options for color edit widgets
894b8e80941Smrg    ImVec4                  ColorPickerRef;
895b8e80941Smrg    bool                    DragCurrentAccumDirty;
896b8e80941Smrg    float                   DragCurrentAccum;                   // Accumulator for dragging modification. Always high-precision, not rounded by end-user precision settings
897b8e80941Smrg    float                   DragSpeedDefaultRatio;              // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
898b8e80941Smrg    ImVec2                  ScrollbarClickDeltaToGrabCenter;    // Distance between mouse and center of grab box, normalized in parent space. Use storage?
899b8e80941Smrg    int                     TooltipOverrideCount;
900b8e80941Smrg    ImVector<char>          PrivateClipboard;                   // If no custom clipboard handler is defined
901b8e80941Smrg
902b8e80941Smrg    // Range-Select/Multi-Select
903b8e80941Smrg    // [This is unused in this branch, but left here to facilitate merging/syncing multiple branches]
904b8e80941Smrg    ImGuiID                 MultiSelectScopeId;
905b8e80941Smrg
906b8e80941Smrg    // Platform support
907b8e80941Smrg    ImVec2                  PlatformImePos;                     // Cursor position request & last passed to the OS Input Method Editor
908b8e80941Smrg    ImVec2                  PlatformImeLastPos;
909b8e80941Smrg
910b8e80941Smrg    // Settings
911b8e80941Smrg    bool                           SettingsLoaded;
912b8e80941Smrg    float                          SettingsDirtyTimer;          // Save .ini Settings to memory when time reaches zero
913b8e80941Smrg    ImGuiTextBuffer                SettingsIniData;             // In memory .ini settings
914b8e80941Smrg    ImVector<ImGuiSettingsHandler> SettingsHandlers;            // List of .ini settings handlers
915b8e80941Smrg    ImVector<ImGuiWindowSettings>  SettingsWindows;             // ImGuiWindow .ini settings entries (parsed from the last loaded .ini file and maintained on saving)
916b8e80941Smrg
917b8e80941Smrg    // Logging
918b8e80941Smrg    bool                    LogEnabled;
919b8e80941Smrg    FILE*                   LogFile;                            // If != NULL log to stdout/ file
920b8e80941Smrg    ImGuiTextBuffer         LogClipboard;                       // Accumulation buffer when log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators.
921b8e80941Smrg    int                     LogStartDepth;
922b8e80941Smrg    int                     LogAutoExpandMaxDepth;
923b8e80941Smrg
924b8e80941Smrg    // Misc
925b8e80941Smrg    float                   FramerateSecPerFrame[120];          // Calculate estimate of framerate for user over the last 2 seconds.
926b8e80941Smrg    int                     FramerateSecPerFrameIdx;
927b8e80941Smrg    float                   FramerateSecPerFrameAccum;
928b8e80941Smrg    int                     WantCaptureMouseNextFrame;          // Explicit capture via CaptureKeyboardFromApp()/CaptureMouseFromApp() sets those flags
929b8e80941Smrg    int                     WantCaptureKeyboardNextFrame;
930b8e80941Smrg    int                     WantTextInputNextFrame;
931b8e80941Smrg    char                    TempBuffer[1024*3+1];               // Temporary text buffer
932b8e80941Smrg
933b8e80941Smrg    ImGuiContext(ImFontAtlas* shared_font_atlas) : OverlayDrawList(NULL)
934b8e80941Smrg    {
935b8e80941Smrg        Initialized = false;
936b8e80941Smrg        FrameScopeActive = FrameScopePushedImplicitWindow = false;
937b8e80941Smrg        Font = NULL;
938b8e80941Smrg        FontSize = FontBaseSize = 0.0f;
939b8e80941Smrg        FontAtlasOwnedByContext = shared_font_atlas ? false : true;
940b8e80941Smrg        IO.Fonts = shared_font_atlas ? shared_font_atlas : IM_NEW(ImFontAtlas)();
941b8e80941Smrg
942b8e80941Smrg        Time = 0.0f;
943b8e80941Smrg        FrameCount = 0;
944b8e80941Smrg        FrameCountEnded = FrameCountRendered = -1;
945b8e80941Smrg        WindowsActiveCount = 0;
946b8e80941Smrg        CurrentWindow = NULL;
947b8e80941Smrg        HoveredWindow = NULL;
948b8e80941Smrg        HoveredRootWindow = NULL;
949b8e80941Smrg        HoveredId = 0;
950b8e80941Smrg        HoveredIdAllowOverlap = false;
951b8e80941Smrg        HoveredIdPreviousFrame = 0;
952b8e80941Smrg        HoveredIdTimer = HoveredIdNotActiveTimer = 0.0f;
953b8e80941Smrg        ActiveId = 0;
954b8e80941Smrg        ActiveIdPreviousFrame = 0;
955b8e80941Smrg        ActiveIdIsAlive = 0;
956b8e80941Smrg        ActiveIdTimer = 0.0f;
957b8e80941Smrg        ActiveIdIsJustActivated = false;
958b8e80941Smrg        ActiveIdAllowOverlap = false;
959b8e80941Smrg        ActiveIdHasBeenPressed = false;
960b8e80941Smrg        ActiveIdHasBeenEdited = false;
961b8e80941Smrg        ActiveIdPreviousFrameIsAlive = false;
962b8e80941Smrg        ActiveIdPreviousFrameHasBeenEdited = false;
963b8e80941Smrg        ActiveIdAllowNavDirFlags = 0x00;
964b8e80941Smrg        ActiveIdBlockNavInputFlags = 0x00;
965b8e80941Smrg        ActiveIdClickOffset = ImVec2(-1,-1);
966b8e80941Smrg        ActiveIdWindow = ActiveIdPreviousFrameWindow = NULL;
967b8e80941Smrg        ActiveIdSource = ImGuiInputSource_None;
968b8e80941Smrg        LastActiveId = 0;
969b8e80941Smrg        LastActiveIdTimer = 0.0f;
970b8e80941Smrg        LastValidMousePos = ImVec2(0.0f, 0.0f);
971b8e80941Smrg        MovingWindow = NULL;
972b8e80941Smrg        NextTreeNodeOpenVal = false;
973b8e80941Smrg        NextTreeNodeOpenCond = 0;
974b8e80941Smrg
975b8e80941Smrg        NavWindow = NULL;
976b8e80941Smrg        NavId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0;
977b8e80941Smrg        NavJustTabbedId = NavJustMovedToId = NavJustMovedToSelectScopeId = NavNextActivateId = 0;
978b8e80941Smrg        NavInputSource = ImGuiInputSource_None;
979b8e80941Smrg        NavScoringRectScreen = ImRect();
980b8e80941Smrg        NavScoringCount = 0;
981b8e80941Smrg        NavWindowingTarget = NavWindowingTargetAnim = NavWindowingList = NULL;
982b8e80941Smrg        NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f;
983b8e80941Smrg        NavWindowingToggleLayer = false;
984b8e80941Smrg        NavLayer = ImGuiNavLayer_Main;
985b8e80941Smrg        NavIdTabCounter = INT_MAX;
986b8e80941Smrg        NavIdIsAlive = false;
987b8e80941Smrg        NavMousePosDirty = false;
988b8e80941Smrg        NavDisableHighlight = true;
989b8e80941Smrg        NavDisableMouseHover = false;
990b8e80941Smrg        NavAnyRequest = false;
991b8e80941Smrg        NavInitRequest = false;
992b8e80941Smrg        NavInitRequestFromMove = false;
993b8e80941Smrg        NavInitResultId = 0;
994b8e80941Smrg        NavMoveFromClampedRefRect = false;
995b8e80941Smrg        NavMoveRequest = false;
996b8e80941Smrg        NavMoveRequestFlags = 0;
997b8e80941Smrg        NavMoveRequestForward = ImGuiNavForward_None;
998b8e80941Smrg        NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None;
999b8e80941Smrg
1000b8e80941Smrg        DimBgRatio = 0.0f;
1001b8e80941Smrg        OverlayDrawList._Data = &DrawListSharedData;
1002b8e80941Smrg        OverlayDrawList._OwnerName = "##Overlay"; // Give it a name for debugging
1003b8e80941Smrg        MouseCursor = ImGuiMouseCursor_Arrow;
1004b8e80941Smrg
1005b8e80941Smrg        DragDropActive = DragDropWithinSourceOrTarget = false;
1006b8e80941Smrg        DragDropSourceFlags = 0;
1007b8e80941Smrg        DragDropSourceFrameCount = -1;
1008b8e80941Smrg        DragDropMouseButton = -1;
1009b8e80941Smrg        DragDropTargetId = 0;
1010b8e80941Smrg        DragDropAcceptFlags = 0;
1011b8e80941Smrg        DragDropAcceptIdCurrRectSurface = 0.0f;
1012b8e80941Smrg        DragDropAcceptIdPrev = DragDropAcceptIdCurr = 0;
1013b8e80941Smrg        DragDropAcceptFrameCount = -1;
1014b8e80941Smrg        memset(DragDropPayloadBufLocal, 0, sizeof(DragDropPayloadBufLocal));
1015b8e80941Smrg
1016b8e80941Smrg        ScalarAsInputTextId = 0;
1017b8e80941Smrg        ColorEditOptions = ImGuiColorEditFlags__OptionsDefault;
1018b8e80941Smrg        DragCurrentAccumDirty = false;
1019b8e80941Smrg        DragCurrentAccum = 0.0f;
1020b8e80941Smrg        DragSpeedDefaultRatio = 1.0f / 100.0f;
1021b8e80941Smrg        ScrollbarClickDeltaToGrabCenter = ImVec2(0.0f, 0.0f);
1022b8e80941Smrg        TooltipOverrideCount = 0;
1023b8e80941Smrg
1024b8e80941Smrg        MultiSelectScopeId = 0;
1025b8e80941Smrg
1026b8e80941Smrg        PlatformImePos = PlatformImeLastPos = ImVec2(FLT_MAX, FLT_MAX);
1027b8e80941Smrg
1028b8e80941Smrg        SettingsLoaded = false;
1029b8e80941Smrg        SettingsDirtyTimer = 0.0f;
1030b8e80941Smrg
1031b8e80941Smrg        LogEnabled = false;
1032b8e80941Smrg        LogFile = NULL;
1033b8e80941Smrg        LogStartDepth = 0;
1034b8e80941Smrg        LogAutoExpandMaxDepth = 2;
1035b8e80941Smrg
1036b8e80941Smrg        memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
1037b8e80941Smrg        FramerateSecPerFrameIdx = 0;
1038b8e80941Smrg        FramerateSecPerFrameAccum = 0.0f;
1039b8e80941Smrg        WantCaptureMouseNextFrame = WantCaptureKeyboardNextFrame = WantTextInputNextFrame = -1;
1040b8e80941Smrg        memset(TempBuffer, 0, sizeof(TempBuffer));
1041b8e80941Smrg    }
1042b8e80941Smrg};
1043b8e80941Smrg
1044b8e80941Smrg//-----------------------------------------------------------------------------
1045b8e80941Smrg// ImGuiWindow
1046b8e80941Smrg//-----------------------------------------------------------------------------
1047b8e80941Smrg
1048b8e80941Smrg// Transient per-window data, reset at the beginning of the frame. This used to be called ImGuiDrawContext, hence the DC variable name in ImGuiWindow.
1049b8e80941Smrg// FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiWindowTempData is quite tenuous and could be reconsidered.
1050b8e80941Smrgstruct IMGUI_API ImGuiWindowTempData
1051b8e80941Smrg{
1052b8e80941Smrg    ImVec2                  CursorPos;
1053b8e80941Smrg    ImVec2                  CursorPosPrevLine;
1054b8e80941Smrg    ImVec2                  CursorStartPos;         // Initial position in client area with padding
1055b8e80941Smrg    ImVec2                  CursorMaxPos;           // Used to implicitly calculate the size of our contents, always growing during the frame. Turned into window->SizeContents at the beginning of next frame
1056b8e80941Smrg    ImVec2                  CurrentLineSize;
1057b8e80941Smrg    float                   CurrentLineTextBaseOffset;
1058b8e80941Smrg    ImVec2                  PrevLineSize;
1059b8e80941Smrg    float                   PrevLineTextBaseOffset;
1060b8e80941Smrg    float                   LogLinePosY;
1061b8e80941Smrg    int                     TreeDepth;
1062b8e80941Smrg    ImU32                   TreeDepthMayJumpToParentOnPop; // Store a copy of !g.NavIdIsAlive for TreeDepth 0..31
1063b8e80941Smrg    ImGuiID                 LastItemId;
1064b8e80941Smrg    ImGuiItemStatusFlags    LastItemStatusFlags;
1065b8e80941Smrg    ImRect                  LastItemRect;           // Interaction rect
1066b8e80941Smrg    ImRect                  LastItemDisplayRect;    // End-user display rect (only valid if LastItemStatusFlags & ImGuiItemStatusFlags_HasDisplayRect)
1067b8e80941Smrg    ImGuiNavLayer           NavLayerCurrent;        // Current layer, 0..31 (we currently only use 0..1)
1068b8e80941Smrg    int                     NavLayerCurrentMask;    // = (1 << NavLayerCurrent) used by ItemAdd prior to clipping.
1069b8e80941Smrg    int                     NavLayerActiveMask;     // Which layer have been written to (result from previous frame)
1070b8e80941Smrg    int                     NavLayerActiveMaskNext; // Which layer have been written to (buffer for current frame)
1071b8e80941Smrg    bool                    NavHideHighlightOneFrame;
1072b8e80941Smrg    bool                    NavHasScroll;           // Set when scrolling can be used (ScrollMax > 0.0f)
1073b8e80941Smrg    bool                    MenuBarAppending;       // FIXME: Remove this
1074b8e80941Smrg    ImVec2                  MenuBarOffset;          // MenuBarOffset.x is sort of equivalent of a per-layer CursorPos.x, saved/restored as we switch to the menu bar. The only situation when MenuBarOffset.y is > 0 if when (SafeAreaPadding.y > FramePadding.y), often used on TVs.
1075b8e80941Smrg    ImVector<ImGuiWindow*>  ChildWindows;
1076b8e80941Smrg    ImGuiStorage*           StateStorage;
1077b8e80941Smrg    ImGuiLayoutType         LayoutType;
1078b8e80941Smrg    ImGuiLayoutType         ParentLayoutType;       // Layout type of parent window at the time of Begin()
1079b8e80941Smrg
1080b8e80941Smrg    // 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.
1081b8e80941Smrg    ImGuiItemFlags          ItemFlags;              // == ItemFlagsStack.back() [empty == ImGuiItemFlags_Default]
1082b8e80941Smrg    float                   ItemWidth;              // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
1083b8e80941Smrg    float                   TextWrapPos;            // == TextWrapPosStack.back() [empty == -1.0f]
1084b8e80941Smrg    ImVector<ImGuiItemFlags>ItemFlagsStack;
1085b8e80941Smrg    ImVector<float>         ItemWidthStack;
1086b8e80941Smrg    ImVector<float>         TextWrapPosStack;
1087b8e80941Smrg    ImVector<ImGuiGroupData>GroupStack;
1088b8e80941Smrg    short                   StackSizesBackup[6];    // Store size of various stacks for asserting
1089b8e80941Smrg
1090b8e80941Smrg    ImVec1                  Indent;                 // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
1091b8e80941Smrg    ImVec1                  GroupOffset;
1092b8e80941Smrg    ImVec1                  ColumnsOffset;          // 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.
1093b8e80941Smrg    ImGuiColumnsSet*        ColumnsSet;             // Current columns set
1094b8e80941Smrg
1095b8e80941Smrg    ImGuiWindowTempData()
1096b8e80941Smrg    {
1097b8e80941Smrg        CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f);
1098b8e80941Smrg        CurrentLineSize = PrevLineSize = ImVec2(0.0f, 0.0f);
1099b8e80941Smrg        CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f;
1100b8e80941Smrg        LogLinePosY = -1.0f;
1101b8e80941Smrg        TreeDepth = 0;
1102b8e80941Smrg        TreeDepthMayJumpToParentOnPop = 0x00;
1103b8e80941Smrg        LastItemId = 0;
1104b8e80941Smrg        LastItemStatusFlags = 0;
1105b8e80941Smrg        LastItemRect = LastItemDisplayRect = ImRect();
1106b8e80941Smrg        NavLayerActiveMask = NavLayerActiveMaskNext = 0x00;
1107b8e80941Smrg        NavLayerCurrent = ImGuiNavLayer_Main;
1108b8e80941Smrg        NavLayerCurrentMask = (1 << ImGuiNavLayer_Main);
1109b8e80941Smrg        NavHideHighlightOneFrame = false;
1110b8e80941Smrg        NavHasScroll = false;
1111b8e80941Smrg        MenuBarAppending = false;
1112b8e80941Smrg        MenuBarOffset = ImVec2(0.0f, 0.0f);
1113b8e80941Smrg        StateStorage = NULL;
1114b8e80941Smrg        LayoutType = ParentLayoutType = ImGuiLayoutType_Vertical;
1115b8e80941Smrg        ItemWidth = 0.0f;
1116b8e80941Smrg        ItemFlags = ImGuiItemFlags_Default_;
1117b8e80941Smrg        TextWrapPos = -1.0f;
1118b8e80941Smrg        memset(StackSizesBackup, 0, sizeof(StackSizesBackup));
1119b8e80941Smrg
1120b8e80941Smrg        Indent = ImVec1(0.0f);
1121b8e80941Smrg        GroupOffset = ImVec1(0.0f);
1122b8e80941Smrg        ColumnsOffset = ImVec1(0.0f);
1123b8e80941Smrg        ColumnsSet = NULL;
1124b8e80941Smrg    }
1125b8e80941Smrg};
1126b8e80941Smrg
1127b8e80941Smrg// Storage for one window
1128b8e80941Smrgstruct IMGUI_API ImGuiWindow
1129b8e80941Smrg{
1130b8e80941Smrg    char*                   Name;
1131b8e80941Smrg    ImGuiID                 ID;                                 // == ImHash(Name)
1132b8e80941Smrg    ImGuiWindowFlags        Flags;                              // See enum ImGuiWindowFlags_
1133b8e80941Smrg    ImVec2                  Pos;                                // Position (always rounded-up to nearest pixel)
1134b8e80941Smrg    ImVec2                  Size;                               // Current size (==SizeFull or collapsed title bar size)
1135b8e80941Smrg    ImVec2                  SizeFull;                           // Size when non collapsed
1136b8e80941Smrg    ImVec2                  SizeFullAtLastBegin;                // Copy of SizeFull at the end of Begin. This is the reference value we'll use on the next frame to decide if we need scrollbars.
1137b8e80941Smrg    ImVec2                  SizeContents;                       // Size of contents (== extents reach of the drawing cursor) from previous frame. Include decoration, window title, border, menu, etc.
1138b8e80941Smrg    ImVec2                  SizeContentsExplicit;               // Size of contents explicitly set by the user via SetNextWindowContentSize()
1139b8e80941Smrg    ImVec2                  WindowPadding;                      // Window padding at the time of begin.
1140b8e80941Smrg    float                   WindowRounding;                     // Window rounding at the time of begin.
1141b8e80941Smrg    float                   WindowBorderSize;                   // Window border size at the time of begin.
1142b8e80941Smrg    int                     NameBufLen;                         // Size of buffer storing Name. May be larger than strlen(Name)!
1143b8e80941Smrg    ImGuiID                 MoveId;                             // == window->GetID("#MOVE")
1144b8e80941Smrg    ImGuiID                 ChildId;                            // ID of corresponding item in parent window (for navigation to return from child window to parent window)
1145b8e80941Smrg    ImVec2                  Scroll;
1146b8e80941Smrg    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)
1147b8e80941Smrg    ImVec2                  ScrollTargetCenterRatio;            // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered
1148b8e80941Smrg    ImVec2                  ScrollbarSizes;                     // Size taken by scrollbars on each axis
1149b8e80941Smrg    bool                    ScrollbarX, ScrollbarY;
1150b8e80941Smrg    bool                    Active;                             // Set to true on Begin(), unless Collapsed
1151b8e80941Smrg    bool                    WasActive;
1152b8e80941Smrg    bool                    WriteAccessed;                      // Set to true when any widget access the current window
1153b8e80941Smrg    bool                    Collapsed;                          // Set when collapsing window to become only title-bar
1154b8e80941Smrg    bool                    WantCollapseToggle;
1155b8e80941Smrg    bool                    SkipItems;                          // Set when items can safely be all clipped (e.g. window not visible or collapsed)
1156b8e80941Smrg    bool                    Appearing;                          // Set during the frame where the window is appearing (or re-appearing)
1157b8e80941Smrg    bool                    Hidden;                             // Do not display (== (HiddenFramesForResize > 0) ||
1158b8e80941Smrg    bool                    HasCloseButton;                     // Set when the window has a close button (p_open != NULL)
1159b8e80941Smrg    signed char             ResizeBorderHeld;                   // Current border being held for resize (-1: none, otherwise 0-3)
1160b8e80941Smrg    short                   BeginCount;                         // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs)
1161b8e80941Smrg    short                   BeginOrderWithinParent;             // Order within immediate parent window, if we are a child window. Otherwise 0.
1162b8e80941Smrg    short                   BeginOrderWithinContext;            // Order within entire imgui context. This is mostly used for debugging submission order related issues.
1163b8e80941Smrg    ImGuiID                 PopupId;                            // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling)
1164b8e80941Smrg    int                     AutoFitFramesX, AutoFitFramesY;
1165b8e80941Smrg    bool                    AutoFitOnlyGrows;
1166b8e80941Smrg    int                     AutoFitChildAxises;
1167b8e80941Smrg    ImGuiDir                AutoPosLastDirection;
1168b8e80941Smrg    int                     HiddenFramesRegular;                // Hide the window for N frames
1169b8e80941Smrg    int                     HiddenFramesForResize;              // Hide the window for N frames while allowing items to be submitted so we can measure their size
1170b8e80941Smrg    ImGuiCond               SetWindowPosAllowFlags;             // store acceptable condition flags for SetNextWindowPos() use.
1171b8e80941Smrg    ImGuiCond               SetWindowSizeAllowFlags;            // store acceptable condition flags for SetNextWindowSize() use.
1172b8e80941Smrg    ImGuiCond               SetWindowCollapsedAllowFlags;       // store acceptable condition flags for SetNextWindowCollapsed() use.
1173b8e80941Smrg    ImVec2                  SetWindowPosVal;                    // store window position when using a non-zero Pivot (position set needs to be processed when we know the window size)
1174b8e80941Smrg    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.
1175b8e80941Smrg
1176b8e80941Smrg    ImGuiWindowTempData     DC;                                 // Temporary per-window data, reset at the beginning of the frame. This used to be called ImGuiDrawContext, hence the "DC" variable name.
1177b8e80941Smrg    ImVector<ImGuiID>       IDStack;                            // ID stack. ID are hashes seeded with the value at the top of the stack
1178b8e80941Smrg    ImRect                  ClipRect;                           // Current clipping rectangle. = DrawList->clip_rect_stack.back(). Scissoring / clipping rectangle. x1, y1, x2, y2.
1179b8e80941Smrg    ImRect                  OuterRectClipped;                   // = WindowRect just after setup in Begin(). == window->Rect() for root window.
1180b8e80941Smrg    ImRect                  InnerMainRect, InnerClipRect;
1181b8e80941Smrg    ImRect                  ContentsRegionRect;                 // FIXME: This is currently confusing/misleading. Maximum visible content position ~~ Pos + (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis
1182b8e80941Smrg    int                     LastFrameActive;                    // Last frame number the window was Active.
1183b8e80941Smrg    float                   ItemWidthDefault;
1184b8e80941Smrg    ImGuiMenuColumns        MenuColumns;                        // Simplified columns storage for menu items
1185b8e80941Smrg    ImGuiStorage            StateStorage;
1186b8e80941Smrg    ImVector<ImGuiColumnsSet> ColumnsStorage;
1187b8e80941Smrg    float                   FontWindowScale;                    // User scale multiplier per-window
1188b8e80941Smrg    int                     SettingsIdx;                        // Index into SettingsWindow[] (indices are always valid as we only grow the array from the back)
1189b8e80941Smrg
1190b8e80941Smrg    ImDrawList*             DrawList;                           // == &DrawListInst (for backward compatibility reason with code using imgui_internal.h we keep this a pointer)
1191b8e80941Smrg    ImDrawList              DrawListInst;
1192b8e80941Smrg    ImGuiWindow*            ParentWindow;                       // If we are a child _or_ popup window, this is pointing to our parent. Otherwise NULL.
1193b8e80941Smrg    ImGuiWindow*            RootWindow;                         // Point to ourself or first ancestor that is not a child window.
1194b8e80941Smrg    ImGuiWindow*            RootWindowForTitleBarHighlight;     // Point to ourself or first ancestor which will display TitleBgActive color when this window is active.
1195b8e80941Smrg    ImGuiWindow*            RootWindowForNav;                   // Point to ourself or first ancestor which doesn't have the NavFlattened flag.
1196b8e80941Smrg
1197b8e80941Smrg    ImGuiWindow*            NavLastChildNavWindow;              // When going to the menu bar, we remember the child window we came from. (This could probably be made implicit if we kept g.Windows sorted by last focused including child window.)
1198b8e80941Smrg    ImGuiID                 NavLastIds[ImGuiNavLayer_COUNT];    // Last known NavId for this window, per layer (0/1)
1199b8e80941Smrg    ImRect                  NavRectRel[ImGuiNavLayer_COUNT];    // Reference rectangle, in window relative space
1200b8e80941Smrg
1201b8e80941Smrg    // Navigation / Focus
1202b8e80941Smrg    // FIXME-NAV: Merge all this with the new Nav system, at least the request variables should be moved to ImGuiContext
1203b8e80941Smrg    int                     FocusIdxAllCounter;                 // Start at -1 and increase as assigned via FocusItemRegister()
1204b8e80941Smrg    int                     FocusIdxTabCounter;                 // (same, but only count widgets which you can Tab through)
1205b8e80941Smrg    int                     FocusIdxAllRequestCurrent;          // Item being requested for focus
1206b8e80941Smrg    int                     FocusIdxTabRequestCurrent;          // Tab-able item being requested for focus
1207b8e80941Smrg    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)
1208b8e80941Smrg    int                     FocusIdxTabRequestNext;             // "
1209b8e80941Smrg
1210b8e80941Smrgpublic:
1211b8e80941Smrg    ImGuiWindow(ImGuiContext* context, const char* name);
1212b8e80941Smrg    ~ImGuiWindow();
1213b8e80941Smrg
1214b8e80941Smrg    ImGuiID     GetID(const char* str, const char* str_end = NULL);
1215b8e80941Smrg    ImGuiID     GetID(const void* ptr);
1216b8e80941Smrg    ImGuiID     GetIDNoKeepAlive(const char* str, const char* str_end = NULL);
1217b8e80941Smrg    ImGuiID     GetIDNoKeepAlive(const void* ptr);
1218b8e80941Smrg    ImGuiID     GetIDFromRectangle(const ImRect& r_abs);
1219b8e80941Smrg
1220b8e80941Smrg    // We don't use g.FontSize because the window may be != g.CurrentWidow.
1221b8e80941Smrg    ImRect      Rect() const                            { return ImRect(Pos.x, Pos.y, Pos.x+Size.x, Pos.y+Size.y); }
1222b8e80941Smrg    float       CalcFontSize() const                    { return GImGui->FontBaseSize * FontWindowScale; }
1223b8e80941Smrg    float       TitleBarHeight() const                  { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; }
1224b8e80941Smrg    ImRect      TitleBarRect() const                    { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); }
1225b8e80941Smrg    float       MenuBarHeight() const                   { return (Flags & ImGuiWindowFlags_MenuBar) ? DC.MenuBarOffset.y + CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f : 0.0f; }
1226b8e80941Smrg    ImRect      MenuBarRect() const                     { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); }
1227b8e80941Smrg};
1228b8e80941Smrg
1229b8e80941Smrg// 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.
1230b8e80941Smrgstruct ImGuiItemHoveredDataBackup
1231b8e80941Smrg{
1232b8e80941Smrg    ImGuiID                 LastItemId;
1233b8e80941Smrg    ImGuiItemStatusFlags    LastItemStatusFlags;
1234b8e80941Smrg    ImRect                  LastItemRect;
1235b8e80941Smrg    ImRect                  LastItemDisplayRect;
1236b8e80941Smrg
1237b8e80941Smrg    ImGuiItemHoveredDataBackup() { Backup(); }
1238b8e80941Smrg    void Backup()           { ImGuiWindow* window = GImGui->CurrentWindow; LastItemId = window->DC.LastItemId; LastItemStatusFlags = window->DC.LastItemStatusFlags; LastItemRect = window->DC.LastItemRect; LastItemDisplayRect = window->DC.LastItemDisplayRect; }
1239b8e80941Smrg    void Restore() const    { ImGuiWindow* window = GImGui->CurrentWindow; window->DC.LastItemId = LastItemId; window->DC.LastItemStatusFlags = LastItemStatusFlags; window->DC.LastItemRect = LastItemRect; window->DC.LastItemDisplayRect = LastItemDisplayRect; }
1240b8e80941Smrg};
1241b8e80941Smrg
1242b8e80941Smrg//-----------------------------------------------------------------------------
1243b8e80941Smrg// Tab bar, tab item
1244b8e80941Smrg//-----------------------------------------------------------------------------
1245b8e80941Smrg
1246b8e80941Smrgenum ImGuiTabBarFlagsPrivate_
1247b8e80941Smrg{
1248b8e80941Smrg    ImGuiTabBarFlags_DockNode                   = 1 << 20,  // Part of a dock node
1249b8e80941Smrg    ImGuiTabBarFlags_IsFocused                  = 1 << 21,
1250b8e80941Smrg    ImGuiTabBarFlags_SaveSettings               = 1 << 22   // FIXME: Settings are handled by the docking system, this only request the tab bar to mark settings dirty when reordering tabs
1251b8e80941Smrg};
1252b8e80941Smrg
1253b8e80941Smrgenum ImGuiTabItemFlagsPrivate_
1254b8e80941Smrg{
1255b8e80941Smrg    ImGuiTabItemFlags_NoCloseButton             = 1 << 20   // Store whether p_open is set or not, which we need to recompute WidthContents during layout.
1256b8e80941Smrg};
1257b8e80941Smrg
1258b8e80941Smrg// Storage for one active tab item (sizeof() 26~32 bytes)
1259b8e80941Smrgstruct ImGuiTabItem
1260b8e80941Smrg{
1261b8e80941Smrg    ImGuiID             ID;
1262b8e80941Smrg    ImGuiTabItemFlags   Flags;
1263b8e80941Smrg    int                 LastFrameVisible;
1264b8e80941Smrg    int                 LastFrameSelected;      // This allows us to infer an ordered list of the last activated tabs with little maintenance
1265b8e80941Smrg    int                 NameOffset;             // When Window==NULL, offset to name within parent ImGuiTabBar::TabsNames
1266b8e80941Smrg    float               Offset;                 // Position relative to beginning of tab
1267b8e80941Smrg    float               Width;                  // Width currently displayed
1268b8e80941Smrg    float               WidthContents;          // Width of actual contents, stored during BeginTabItem() call
1269b8e80941Smrg
1270b8e80941Smrg    ImGuiTabItem()      { ID = Flags = 0; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = WidthContents = 0.0f; }
1271b8e80941Smrg};
1272b8e80941Smrg
1273b8e80941Smrg// Storage for a tab bar (sizeof() 92~96 bytes)
1274b8e80941Smrgstruct ImGuiTabBar
1275b8e80941Smrg{
1276b8e80941Smrg    ImVector<ImGuiTabItem> Tabs;
1277b8e80941Smrg    ImGuiID             ID;                     // Zero for tab-bars used by docking
1278b8e80941Smrg    ImGuiID             SelectedTabId;          // Selected tab
1279b8e80941Smrg    ImGuiID             NextSelectedTabId;
1280b8e80941Smrg    ImGuiID             VisibleTabId;           // Can occasionally be != SelectedTabId (e.g. when previewing contents for CTRL+TAB preview)
1281b8e80941Smrg    int                 CurrFrameVisible;
1282b8e80941Smrg    int                 PrevFrameVisible;
1283b8e80941Smrg    ImRect              BarRect;
1284b8e80941Smrg    float               ContentsHeight;
1285b8e80941Smrg    float               OffsetMax;              // Distance from BarRect.Min.x, locked during layout
1286b8e80941Smrg    float               OffsetNextTab;          // Distance from BarRect.Min.x, incremented with each BeginTabItem() call, not used if ImGuiTabBarFlags_Reorderable if set.
1287b8e80941Smrg    float               ScrollingAnim;
1288b8e80941Smrg    float               ScrollingTarget;
1289b8e80941Smrg    ImGuiTabBarFlags    Flags;
1290b8e80941Smrg    ImGuiID             ReorderRequestTabId;
1291b8e80941Smrg    int                 ReorderRequestDir;
1292b8e80941Smrg    bool                WantLayout;
1293b8e80941Smrg    bool                VisibleTabWasSubmitted;
1294b8e80941Smrg    short               LastTabItemIdx;         // For BeginTabItem()/EndTabItem()
1295b8e80941Smrg    ImVec2              FramePadding;           // style.FramePadding locked at the time of BeginTabBar()
1296b8e80941Smrg    ImGuiTextBuffer     TabsNames;              // For non-docking tab bar we re-append names in a contiguous buffer.
1297b8e80941Smrg
1298b8e80941Smrg    ImGuiTabBar();
1299b8e80941Smrg    int                 GetTabOrder(const ImGuiTabItem* tab) const  { return Tabs.index_from_ptr(tab); }
1300b8e80941Smrg    const char*         GetTabName(const ImGuiTabItem* tab) const
1301b8e80941Smrg    {
1302b8e80941Smrg        IM_ASSERT(tab->NameOffset != -1 && tab->NameOffset < TabsNames.Buf.Size);
1303b8e80941Smrg        return TabsNames.Buf.Data + tab->NameOffset;
1304b8e80941Smrg    }
1305b8e80941Smrg};
1306b8e80941Smrg
1307b8e80941Smrg//-----------------------------------------------------------------------------
1308b8e80941Smrg// Internal API
1309b8e80941Smrg// No guarantee of forward compatibility here.
1310b8e80941Smrg//-----------------------------------------------------------------------------
1311b8e80941Smrg
1312b8e80941Smrgnamespace ImGui
1313b8e80941Smrg{
1314b8e80941Smrg    // We should always have a CurrentWindow in the stack (there is an implicit "Debug" window)
1315b8e80941Smrg    // If this ever crash because g.CurrentWindow is NULL it means that either
1316b8e80941Smrg    // - ImGui::NewFrame() has never been called, which is illegal.
1317b8e80941Smrg    // - You are calling ImGui functions after ImGui::EndFrame()/ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal.
1318b8e80941Smrg    inline    ImGuiWindow*  GetCurrentWindowRead()      { ImGuiContext& g = *GImGui; return g.CurrentWindow; }
1319b8e80941Smrg    inline    ImGuiWindow*  GetCurrentWindow()          { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; }
1320b8e80941Smrg    IMGUI_API ImGuiWindow*  FindWindowByID(ImGuiID id);
1321b8e80941Smrg    IMGUI_API ImGuiWindow*  FindWindowByName(const char* name);
1322b8e80941Smrg    IMGUI_API void          FocusWindow(ImGuiWindow* window);
1323b8e80941Smrg    IMGUI_API void          FocusPreviousWindowIgnoringOne(ImGuiWindow* ignore_window);
1324b8e80941Smrg    IMGUI_API void          BringWindowToFocusFront(ImGuiWindow* window);
1325b8e80941Smrg    IMGUI_API void          BringWindowToDisplayFront(ImGuiWindow* window);
1326b8e80941Smrg    IMGUI_API void          BringWindowToDisplayBack(ImGuiWindow* window);
1327b8e80941Smrg    IMGUI_API void          UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window);
1328b8e80941Smrg    IMGUI_API ImVec2        CalcWindowExpectedSize(ImGuiWindow* window);
1329b8e80941Smrg    IMGUI_API bool          IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent);
1330b8e80941Smrg    IMGUI_API bool          IsWindowNavFocusable(ImGuiWindow* window);
1331b8e80941Smrg    IMGUI_API void          SetWindowScrollX(ImGuiWindow* window, float new_scroll_x);
1332b8e80941Smrg    IMGUI_API void          SetWindowScrollY(ImGuiWindow* window, float new_scroll_y);
1333b8e80941Smrg    IMGUI_API float         GetWindowScrollMaxX(ImGuiWindow* window);
1334b8e80941Smrg    IMGUI_API float         GetWindowScrollMaxY(ImGuiWindow* window);
1335b8e80941Smrg    IMGUI_API ImRect        GetWindowAllowedExtentRect(ImGuiWindow* window);
1336b8e80941Smrg    IMGUI_API void          SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond);
1337b8e80941Smrg    IMGUI_API void          SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond);
1338b8e80941Smrg    IMGUI_API void          SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond);
1339b8e80941Smrg
1340b8e80941Smrg    IMGUI_API void          SetCurrentFont(ImFont* font);
1341b8e80941Smrg    inline ImFont*          GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; }
1342b8e80941Smrg
1343b8e80941Smrg    // Init
1344b8e80941Smrg    IMGUI_API void          Initialize(ImGuiContext* context);
1345b8e80941Smrg    IMGUI_API void          Shutdown(ImGuiContext* context);    // Since 1.60 this is a _private_ function. You can call DestroyContext() to destroy the context created by CreateContext().
1346b8e80941Smrg
1347b8e80941Smrg    // NewFrame
1348b8e80941Smrg    IMGUI_API void          UpdateHoveredWindowAndCaptureFlags();
1349b8e80941Smrg    IMGUI_API void          StartMouseMovingWindow(ImGuiWindow* window);
1350b8e80941Smrg    IMGUI_API void          UpdateMouseMovingWindowNewFrame();
1351b8e80941Smrg    IMGUI_API void          UpdateMouseMovingWindowEndFrame();
1352b8e80941Smrg
1353b8e80941Smrg    // Settings
1354b8e80941Smrg    IMGUI_API void                  MarkIniSettingsDirty();
1355b8e80941Smrg    IMGUI_API void                  MarkIniSettingsDirty(ImGuiWindow* window);
1356b8e80941Smrg    IMGUI_API ImGuiWindowSettings*  CreateNewWindowSettings(const char* name);
1357b8e80941Smrg    IMGUI_API ImGuiWindowSettings*  FindWindowSettings(ImGuiID id);
1358b8e80941Smrg    IMGUI_API ImGuiWindowSettings*  FindOrCreateWindowSettings(const char* name);
1359b8e80941Smrg    IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name);
1360b8e80941Smrg
1361b8e80941Smrg    // Basic Accessors
1362b8e80941Smrg    inline ImGuiID          GetItemID()     { ImGuiContext& g = *GImGui; return g.CurrentWindow->DC.LastItemId; }
1363b8e80941Smrg    inline ImGuiID          GetActiveID()   { ImGuiContext& g = *GImGui; return g.ActiveId; }
1364b8e80941Smrg    inline ImGuiID          GetFocusID()    { ImGuiContext& g = *GImGui; return g.NavId; }
1365b8e80941Smrg    IMGUI_API void          SetActiveID(ImGuiID id, ImGuiWindow* window);
1366b8e80941Smrg    IMGUI_API void          SetFocusID(ImGuiID id, ImGuiWindow* window);
1367b8e80941Smrg    IMGUI_API void          ClearActiveID();
1368b8e80941Smrg    IMGUI_API ImGuiID       GetHoveredID();
1369b8e80941Smrg    IMGUI_API void          SetHoveredID(ImGuiID id);
1370b8e80941Smrg    IMGUI_API void          KeepAliveID(ImGuiID id);
1371b8e80941Smrg    IMGUI_API void          MarkItemEdited(ImGuiID id);
1372b8e80941Smrg
1373b8e80941Smrg    // Basic Helpers for widget code
1374b8e80941Smrg    IMGUI_API void          ItemSize(const ImVec2& size, float text_offset_y = 0.0f);
1375b8e80941Smrg    IMGUI_API void          ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
1376b8e80941Smrg    IMGUI_API bool          ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb = NULL);
1377b8e80941Smrg    IMGUI_API bool          ItemHoverable(const ImRect& bb, ImGuiID id);
1378b8e80941Smrg    IMGUI_API bool          IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged);
1379b8e80941Smrg    IMGUI_API bool          FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop = true);   // Return true if focus is requested
1380b8e80941Smrg    IMGUI_API void          FocusableItemUnregister(ImGuiWindow* window);
1381b8e80941Smrg    IMGUI_API ImVec2        CalcItemSize(ImVec2 size, float default_x, float default_y);
1382b8e80941Smrg    IMGUI_API float         CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
1383b8e80941Smrg    IMGUI_API void          PushMultiItemsWidths(int components, float width_full = 0.0f);
1384b8e80941Smrg    IMGUI_API void          PushItemFlag(ImGuiItemFlags option, bool enabled);
1385b8e80941Smrg    IMGUI_API void          PopItemFlag();
1386b8e80941Smrg
1387b8e80941Smrg    // Popups, Modals, Tooltips
1388b8e80941Smrg    IMGUI_API void          OpenPopupEx(ImGuiID id);
1389b8e80941Smrg    IMGUI_API void          ClosePopupToLevel(int remaining, bool apply_focus_to_window_under);
1390b8e80941Smrg    IMGUI_API void          ClosePopupsOverWindow(ImGuiWindow* ref_window);
1391b8e80941Smrg    IMGUI_API bool          IsPopupOpen(ImGuiID id); // Test for id within current popup stack level (currently begin-ed into); this doesn't scan the whole popup stack!
1392b8e80941Smrg    IMGUI_API bool          BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags);
1393b8e80941Smrg    IMGUI_API void          BeginTooltipEx(ImGuiWindowFlags extra_flags, bool override_previous_tooltip = true);
1394b8e80941Smrg    IMGUI_API ImGuiWindow*  GetFrontMostPopupModal();
1395b8e80941Smrg    IMGUI_API ImVec2        FindBestWindowPosForPopup(ImGuiWindow* window);
1396b8e80941Smrg    IMGUI_API ImVec2        FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& size, ImGuiDir* last_dir, const ImRect& r_outer, const ImRect& r_avoid, ImGuiPopupPositionPolicy policy = ImGuiPopupPositionPolicy_Default);
1397b8e80941Smrg
1398b8e80941Smrg    // Navigation
1399b8e80941Smrg    IMGUI_API void          NavInitWindow(ImGuiWindow* window, bool force_reinit);
1400b8e80941Smrg    IMGUI_API bool          NavMoveRequestButNoResultYet();
1401b8e80941Smrg    IMGUI_API void          NavMoveRequestCancel();
1402b8e80941Smrg    IMGUI_API void          NavMoveRequestForward(ImGuiDir move_dir, ImGuiDir clip_dir, const ImRect& bb_rel, ImGuiNavMoveFlags move_flags);
1403b8e80941Smrg    IMGUI_API void          NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags);
1404b8e80941Smrg    IMGUI_API float         GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode);
1405b8e80941Smrg    IMGUI_API ImVec2        GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f);
1406b8e80941Smrg    IMGUI_API int           CalcTypematicPressedRepeatAmount(float t, float t_prev, float repeat_delay, float repeat_rate);
1407b8e80941Smrg    IMGUI_API void          ActivateItem(ImGuiID id);   // Remotely activate a button, checkbox, tree node etc. given its unique ID. activation is queued and processed on the next frame when the item is encountered again.
1408b8e80941Smrg    IMGUI_API void          SetNavID(ImGuiID id, int nav_layer);
1409b8e80941Smrg    IMGUI_API void          SetNavIDWithRectRel(ImGuiID id, int nav_layer, const ImRect& rect_rel);
1410b8e80941Smrg
1411b8e80941Smrg    // Inputs
1412b8e80941Smrg    inline bool             IsKeyPressedMap(ImGuiKey key, bool repeat = true)           { const int key_index = GImGui->IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; }
1413b8e80941Smrg    inline bool             IsNavInputDown(ImGuiNavInput n)                             { return GImGui->IO.NavInputs[n] > 0.0f; }
1414b8e80941Smrg    inline bool             IsNavInputPressed(ImGuiNavInput n, ImGuiInputReadMode mode) { return GetNavInputAmount(n, mode) > 0.0f; }
1415b8e80941Smrg    inline bool             IsNavInputPressedAnyOfTwo(ImGuiNavInput n1, ImGuiNavInput n2, ImGuiInputReadMode mode) { return (GetNavInputAmount(n1, mode) + GetNavInputAmount(n2, mode)) > 0.0f; }
1416b8e80941Smrg
1417b8e80941Smrg    // Drag and Drop
1418b8e80941Smrg    IMGUI_API bool          BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id);
1419b8e80941Smrg    IMGUI_API void          ClearDragDrop();
1420b8e80941Smrg    IMGUI_API bool          IsDragDropPayloadBeingAccepted();
1421b8e80941Smrg
1422b8e80941Smrg    // New Columns API (FIXME-WIP)
1423b8e80941Smrg    IMGUI_API void          BeginColumns(const char* str_id, int count, ImGuiColumnsFlags flags = 0); // setup number of columns. use an identifier to distinguish multiple column sets. close with EndColumns().
1424b8e80941Smrg    IMGUI_API void          EndColumns();                                                             // close columns
1425b8e80941Smrg    IMGUI_API void          PushColumnClipRect(int column_index = -1);
1426b8e80941Smrg
1427b8e80941Smrg    // Tab Bars
1428b8e80941Smrg    IMGUI_API bool          BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& bb, ImGuiTabBarFlags flags);
1429b8e80941Smrg    IMGUI_API ImGuiTabItem* TabBarFindTabByID(ImGuiTabBar* tab_bar, ImGuiID tab_id);
1430b8e80941Smrg    IMGUI_API void          TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id);
1431b8e80941Smrg    IMGUI_API void          TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab);
1432b8e80941Smrg    IMGUI_API void          TabBarQueueChangeTabOrder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, int dir);
1433b8e80941Smrg    IMGUI_API bool          TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags);
1434b8e80941Smrg    IMGUI_API ImVec2        TabItemCalcSize(const char* label, bool has_close_button);
1435b8e80941Smrg    IMGUI_API void          TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col);
1436b8e80941Smrg    IMGUI_API bool          TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImVec2 frame_padding, const char* label, ImGuiID tab_id, ImGuiID close_button_id);
1437b8e80941Smrg
1438b8e80941Smrg    // Render helpers
1439b8e80941Smrg    // 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.
1440b8e80941Smrg    // NB: All position are in absolute pixels coordinates (we are never using window coordinates internally)
1441b8e80941Smrg    IMGUI_API void          RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
1442b8e80941Smrg    IMGUI_API void          RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width);
1443b8e80941Smrg    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);
1444b8e80941Smrg    IMGUI_API void          RenderTextClippedEx(ImDrawList* draw_list, 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);
1445b8e80941Smrg    IMGUI_API void          RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
1446b8e80941Smrg    IMGUI_API void          RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f);
1447b8e80941Smrg    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);
1448b8e80941Smrg    IMGUI_API void          RenderArrow(ImVec2 pos, ImGuiDir dir, float scale = 1.0f);
1449b8e80941Smrg    IMGUI_API void          RenderBullet(ImVec2 pos);
1450b8e80941Smrg    IMGUI_API void          RenderCheckMark(ImVec2 pos, ImU32 col, float sz);
1451b8e80941Smrg    IMGUI_API void          RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight
1452b8e80941Smrg    IMGUI_API const char*   FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text.
1453b8e80941Smrg    IMGUI_API void          LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL);
1454b8e80941Smrg
1455b8e80941Smrg    // Render helpers (those functions don't access any ImGui state!)
1456b8e80941Smrg    IMGUI_API void          RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor = ImGuiMouseCursor_Arrow);
1457b8e80941Smrg    IMGUI_API void          RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col);
1458b8e80941Smrg    IMGUI_API void          RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding);
1459b8e80941Smrg    IMGUI_API void          RenderPixelEllipsis(ImDrawList* draw_list, ImVec2 pos, int count, ImU32 col);
1460b8e80941Smrg
1461b8e80941Smrg    // Widgets
1462b8e80941Smrg    IMGUI_API bool          ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0);
1463b8e80941Smrg    IMGUI_API bool          CloseButton(ImGuiID id, const ImVec2& pos, float radius);
1464b8e80941Smrg    IMGUI_API bool          CollapseButton(ImGuiID id, const ImVec2& pos);
1465b8e80941Smrg    IMGUI_API bool          ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags);
1466b8e80941Smrg    IMGUI_API void          Scrollbar(ImGuiLayoutType direction);
1467b8e80941Smrg    IMGUI_API ImGuiID       GetScrollbarID(ImGuiLayoutType direction);
1468b8e80941Smrg    IMGUI_API void          VerticalSeparator();        // Vertical separator, for menu bars (use current line height). Not exposed because it is misleading and it doesn't have an effect on regular layout.
1469b8e80941Smrg
1470b8e80941Smrg    // Widgets low-level behaviors
1471b8e80941Smrg    IMGUI_API bool          ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0);
1472b8e80941Smrg    IMGUI_API bool          DragBehavior(ImGuiID id, ImGuiDataType data_type, void* v, float v_speed, const void* v_min, const void* v_max, const char* format, float power, ImGuiDragFlags flags);
1473b8e80941Smrg    IMGUI_API bool          SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power, ImGuiSliderFlags flags, ImRect* out_grab_bb);
1474b8e80941Smrg    IMGUI_API bool          SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend = 0.0f, float hover_visibility_delay = 0.0f);
1475b8e80941Smrg    IMGUI_API bool          TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL);
1476b8e80941Smrg    IMGUI_API bool          TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0);                     // Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging
1477b8e80941Smrg    IMGUI_API void          TreePushRawID(ImGuiID id);
1478b8e80941Smrg
1479b8e80941Smrg    // Template functions are instantiated in imgui_widgets.cpp for a finite number of types.
1480b8e80941Smrg    // To use them externally (for custom widget) you may need an "extern template" statement in your code in order to link to existing instances and silence Clang warnings (see #2036).
1481b8e80941Smrg    // e.g. " extern template IMGUI_API float RoundScalarWithFormatT<float, float>(const char* format, ImGuiDataType data_type, float v); "
1482b8e80941Smrg    template<typename T, typename SIGNED_T, typename FLOAT_T>   IMGUI_API bool  DragBehaviorT(ImGuiDataType data_type, T* v, float v_speed, const T v_min, const T v_max, const char* format, float power, ImGuiDragFlags flags);
1483b8e80941Smrg    template<typename T, typename SIGNED_T, typename FLOAT_T>   IMGUI_API bool  SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, T* v, const T v_min, const T v_max, const char* format, float power, ImGuiSliderFlags flags, ImRect* out_grab_bb);
1484b8e80941Smrg    template<typename T, typename FLOAT_T>                      IMGUI_API float SliderCalcRatioFromValueT(ImGuiDataType data_type, T v, T v_min, T v_max, float power, float linear_zero_pos);
1485b8e80941Smrg    template<typename T, typename SIGNED_T>                     IMGUI_API T     RoundScalarWithFormatT(const char* format, ImGuiDataType data_type, T v);
1486b8e80941Smrg
1487b8e80941Smrg    // InputText
1488b8e80941Smrg    IMGUI_API bool          InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
1489b8e80941Smrg    IMGUI_API bool          InputScalarAsWidgetReplacement(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* data_ptr, const char* format);
1490b8e80941Smrg
1491b8e80941Smrg    // Color
1492b8e80941Smrg    IMGUI_API void          ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags);
1493b8e80941Smrg    IMGUI_API void          ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags);
1494b8e80941Smrg    IMGUI_API void          ColorPickerOptionsPopup(const float* ref_col, ImGuiColorEditFlags flags);
1495b8e80941Smrg
1496b8e80941Smrg    // Plot
1497b8e80941Smrg    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 frame_size);
1498b8e80941Smrg
1499b8e80941Smrg    // Shade functions (write over already created vertices)
1500b8e80941Smrg    IMGUI_API void          ShadeVertsLinearColorGradientKeepAlpha(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1);
1501b8e80941Smrg    IMGUI_API void          ShadeVertsLinearUV(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, bool clamp);
1502b8e80941Smrg
1503b8e80941Smrg} // namespace ImGui
1504b8e80941Smrg
1505b8e80941Smrg// ImFontAtlas internals
1506b8e80941SmrgIMGUI_API bool              ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas);
1507b8e80941SmrgIMGUI_API void              ImFontAtlasBuildRegisterDefaultCustomRects(ImFontAtlas* atlas);
1508b8e80941SmrgIMGUI_API void              ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent);
1509b8e80941SmrgIMGUI_API void              ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opaque);
1510b8e80941SmrgIMGUI_API void              ImFontAtlasBuildFinish(ImFontAtlas* atlas);
1511b8e80941SmrgIMGUI_API void              ImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256], float in_multiply_factor);
1512b8e80941SmrgIMGUI_API void              ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride);
1513b8e80941Smrg
1514b8e80941Smrg// Test engine hooks (imgui-test)
1515b8e80941Smrg//#define IMGUI_ENABLE_TEST_ENGINE
1516b8e80941Smrg#ifdef IMGUI_ENABLE_TEST_ENGINE
1517b8e80941Smrgextern void                 ImGuiTestEngineHook_PreNewFrame(ImGuiContext* ctx);
1518b8e80941Smrgextern void                 ImGuiTestEngineHook_PostNewFrame(ImGuiContext* ctx);
1519b8e80941Smrgextern void                 ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, const ImRect& bb, ImGuiID id);
1520b8e80941Smrgextern void                 ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* label, ImGuiItemStatusFlags flags);
1521b8e80941Smrg#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID, _LABEL, _FLAGS)  ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS)   // Register status flags
1522b8e80941Smrg#else
1523b8e80941Smrg#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID, _LABEL, _FLAGS)  do { } while (0)
1524b8e80941Smrg#endif
1525b8e80941Smrg
1526b8e80941Smrg#ifdef __clang__
1527b8e80941Smrg#pragma clang diagnostic pop
1528b8e80941Smrg#endif
1529b8e80941Smrg
1530b8e80941Smrg#ifdef _MSC_VER
1531b8e80941Smrg#pragma warning (pop)
1532b8e80941Smrg#endif
1533