Changeset e66fd66 in opengl-game for IMGUI/imgui_internal.h
- Timestamp:
- Dec 5, 2020, 7:14:31 PM (4 years ago)
- Branches:
- feature/imgui-sdl, master
- Children:
- 95c657f
- Parents:
- 78c3045
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
IMGUI/imgui_internal.h
r78c3045 re66fd66 1 // dear imgui, v1. 61 WIP2 // (internal s)1 // dear imgui, v1.79 2 // (internal structures/api) 3 3 4 4 // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! … … 7 7 // To implement maths operators for ImVec2 (disabled by default to not collide with using IM_VEC2_CLASS_EXTRA along with your own math types+operators) 8 8 9 /* 10 11 Index of this file: 12 13 // [SECTION] Header mess 14 // [SECTION] Forward declarations 15 // [SECTION] Context pointer 16 // [SECTION] STB libraries includes 17 // [SECTION] Macros 18 // [SECTION] Generic helpers 19 // [SECTION] ImDrawList support 20 // [SECTION] Widgets support: flags, enums, data structures 21 // [SECTION] Columns support 22 // [SECTION] Settings support 23 // [SECTION] Multi-select support 24 // [SECTION] Docking support 25 // [SECTION] Viewport support 26 // [SECTION] ImGuiContext (main imgui context) 27 // [SECTION] ImGuiWindowTempData, ImGuiWindow 28 // [SECTION] Tab bar, Tab item support 29 // [SECTION] Table support 30 // [SECTION] Internal API 31 // [SECTION] Test Engine Hooks (imgui_test_engine) 32 33 */ 34 9 35 #pragma once 36 #ifndef IMGUI_DISABLE 37 38 //----------------------------------------------------------------------------- 39 // [SECTION] Header mess 40 //----------------------------------------------------------------------------- 10 41 11 42 #ifndef IMGUI_VERSION … … 13 44 #endif 14 45 15 #include <stdio.h> // FILE* 46 #include <stdio.h> // FILE*, sscanf 47 #include <stdlib.h> // NULL, malloc, free, qsort, atoi, atof 16 48 #include <math.h> // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf 17 49 #include <limits.h> // INT_MIN, INT_MAX 18 50 51 // Visual Studio warnings 19 52 #ifdef _MSC_VER 20 53 #pragma warning (push) … … 22 55 #endif 23 56 24 #ifdef __clang__ 57 // Clang/GCC warnings with -Weverything 58 #if defined(__clang__) 25 59 #pragma clang diagnostic push 26 #pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h 27 #pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h 60 #if __has_warning("-Wunknown-warning-option") 61 #pragma clang diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx' 62 #endif 63 #pragma clang diagnostic ignored "-Wunknown-pragmas" // warning: unknown warning group 'xxx' 64 #pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h 65 #pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h 28 66 #pragma clang diagnostic ignored "-Wold-style-cast" 29 #endif 30 31 //----------------------------------------------------------------------------- 32 // Forward Declarations 33 //----------------------------------------------------------------------------- 34 35 struct ImRect; 36 struct ImGuiColMod; 37 struct ImGuiStyleMod; 38 struct ImGuiGroupData; 39 struct ImGuiMenuColumns; 40 struct ImGuiDrawContext; 41 struct ImGuiTextEditState; 42 struct ImGuiPopupRef; 43 struct ImGuiWindow; 44 struct ImGuiWindowSettings; 45 46 typedef int ImGuiLayoutType; // enum: horizontal or vertical // enum ImGuiLayoutType_ 47 typedef int ImGuiButtonFlags; // flags: for ButtonEx(), ButtonBehavior() // enum ImGuiButtonFlags_ 48 typedef int ImGuiItemFlags; // flags: for PushItemFlag() // enum ImGuiItemFlags_ 49 typedef int ImGuiItemStatusFlags; // flags: storage for DC.LastItemXXX // enum ImGuiItemStatusFlags_ 50 typedef int ImGuiNavHighlightFlags; // flags: for RenderNavHighlight() // enum ImGuiNavHighlightFlags_ 51 typedef int ImGuiNavDirSourceFlags; // flags: for GetNavInputAmount2d() // enum ImGuiNavDirSourceFlags_ 52 typedef int ImGuiSeparatorFlags; // flags: for Separator() - internal // enum ImGuiSeparatorFlags_ 53 typedef int ImGuiSliderFlags; // flags: for SliderBehavior() // enum ImGuiSliderFlags_ 54 55 //------------------------------------------------------------------------- 56 // STB libraries 57 //------------------------------------------------------------------------- 58 59 namespace ImGuiStb 67 #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" 68 #pragma clang diagnostic ignored "-Wdouble-promotion" 69 #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision 70 #elif defined(__GNUC__) 71 #pragma GCC diagnostic push 72 #pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind 73 #pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead 74 #endif 75 76 // Legacy defines 77 #ifdef IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Renamed in 1.74 78 #error Use IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS 79 #endif 80 #ifdef IMGUI_DISABLE_MATH_FUNCTIONS // Renamed in 1.74 81 #error Use IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS 82 #endif 83 84 //----------------------------------------------------------------------------- 85 // [SECTION] Forward declarations 86 //----------------------------------------------------------------------------- 87 88 struct ImBitVector; // Store 1-bit per value 89 struct ImRect; // An axis-aligned rectangle (2 points) 90 struct ImDrawDataBuilder; // Helper to build a ImDrawData instance 91 struct ImDrawListSharedData; // Data shared between all ImDrawList instances 92 struct ImGuiColorMod; // Stacked color modifier, backup of modified data so we can restore it 93 struct ImGuiColumnData; // Storage data for a single column 94 struct ImGuiColumns; // Storage data for a columns set 95 struct ImGuiContext; // Main Dear ImGui context 96 struct ImGuiDataTypeInfo; // Type information associated to a ImGuiDataType enum 97 struct ImGuiGroupData; // Stacked storage data for BeginGroup()/EndGroup() 98 struct ImGuiInputTextState; // Internal state of the currently focused/edited text input box 99 struct ImGuiLastItemDataBackup; // Backup and restore IsItemHovered() internal data 100 struct ImGuiMenuColumns; // Simple column measurement, currently used for MenuItem() only 101 struct ImGuiNavMoveResult; // Result of a gamepad/keyboard directional navigation move query result 102 struct ImGuiNextWindowData; // Storage for SetNextWindow** functions 103 struct ImGuiNextItemData; // Storage for SetNextItem** functions 104 struct ImGuiPopupData; // Storage for current popup stack 105 struct ImGuiSettingsHandler; // Storage for one type registered in the .ini file 106 struct ImGuiStyleMod; // Stacked style modifier, backup of modified data so we can restore it 107 struct ImGuiTabBar; // Storage for a tab bar 108 struct ImGuiTabItem; // Storage for a tab item (within a tab bar) 109 struct ImGuiWindow; // Storage for one window 110 struct ImGuiWindowTempData; // Temporary storage for one window (that's the data which in theory we could ditch at the end of the frame) 111 struct ImGuiWindowSettings; // Storage for a window .ini settings (we keep one of those even if the actual window wasn't instanced during this session) 112 113 // Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists. 114 typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical 115 typedef int ImGuiButtonFlags; // -> enum ImGuiButtonFlags_ // Flags: for ButtonEx(), ButtonBehavior() 116 typedef int ImGuiColumnsFlags; // -> enum ImGuiColumnsFlags_ // Flags: BeginColumns() 117 typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag() 118 typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for DC.LastItemStatusFlags 119 typedef int ImGuiNavHighlightFlags; // -> enum ImGuiNavHighlightFlags_ // Flags: for RenderNavHighlight() 120 typedef int ImGuiNavDirSourceFlags; // -> enum ImGuiNavDirSourceFlags_ // Flags: for GetNavInputAmount2d() 121 typedef int ImGuiNavMoveFlags; // -> enum ImGuiNavMoveFlags_ // Flags: for navigation requests 122 typedef int ImGuiNextItemDataFlags; // -> enum ImGuiNextItemDataFlags_ // Flags: for SetNextItemXXX() functions 123 typedef int ImGuiNextWindowDataFlags; // -> enum ImGuiNextWindowDataFlags_// Flags: for SetNextWindowXXX() functions 124 typedef int ImGuiSeparatorFlags; // -> enum ImGuiSeparatorFlags_ // Flags: for SeparatorEx() 125 typedef int ImGuiTextFlags; // -> enum ImGuiTextFlags_ // Flags: for TextEx() 126 typedef int ImGuiTooltipFlags; // -> enum ImGuiTooltipFlags_ // Flags: for BeginTooltipEx() 127 128 //----------------------------------------------------------------------------- 129 // [SECTION] Context pointer 130 // See implementation of this variable in imgui.cpp for comments and details. 131 //----------------------------------------------------------------------------- 132 133 #ifndef GImGui 134 extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer 135 #endif 136 137 //------------------------------------------------------------------------- 138 // [SECTION] STB libraries includes 139 //------------------------------------------------------------------------- 140 141 namespace ImStb 60 142 { 61 143 62 144 #undef STB_TEXTEDIT_STRING 63 145 #undef STB_TEXTEDIT_CHARTYPE 64 #define STB_TEXTEDIT_STRING ImGui TextEditState146 #define STB_TEXTEDIT_STRING ImGuiInputTextState 65 147 #define STB_TEXTEDIT_CHARTYPE ImWchar 66 #define STB_TEXTEDIT_GETWIDTH_NEWLINE -1.0f 67 #include "stb_textedit.h" 68 69 } // namespace ImGuiStb 70 71 //----------------------------------------------------------------------------- 72 // Context 73 //----------------------------------------------------------------------------- 74 75 #ifndef GImGui 76 extern IMGUI_API ImGuiContext* GImGui; // Current implicit ImGui context pointer 77 #endif 78 79 //----------------------------------------------------------------------------- 80 // Helpers 81 //----------------------------------------------------------------------------- 82 83 #define IM_PI 3.14159265358979323846f 148 #define STB_TEXTEDIT_GETWIDTH_NEWLINE (-1.0f) 149 #define STB_TEXTEDIT_UNDOSTATECOUNT 99 150 #define STB_TEXTEDIT_UNDOCHARCOUNT 999 151 #include "imstb_textedit.h" 152 153 } // namespace ImStb 154 155 //----------------------------------------------------------------------------- 156 // [SECTION] Macros 157 //----------------------------------------------------------------------------- 158 159 // Debug Logging 160 #ifndef IMGUI_DEBUG_LOG 161 #define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__) 162 #endif 163 164 // Debug Logging for selected systems. Remove the '((void)0) //' to enable. 165 //#define IMGUI_DEBUG_LOG_POPUP IMGUI_DEBUG_LOG // Enable log 166 //#define IMGUI_DEBUG_LOG_NAV IMGUI_DEBUG_LOG // Enable log 167 #define IMGUI_DEBUG_LOG_POPUP(...) ((void)0) // Disable log 168 #define IMGUI_DEBUG_LOG_NAV(...) ((void)0) // Disable log 169 170 // Static Asserts 171 #if (__cplusplus >= 201100) 172 #define IM_STATIC_ASSERT(_COND) static_assert(_COND, "") 173 #else 174 #define IM_STATIC_ASSERT(_COND) typedef char static_assertion_##__line__[(_COND)?1:-1] 175 #endif 176 177 // "Paranoid" Debug Asserts are meant to only be enabled during specific debugging/work, otherwise would slow down the code too much. 178 // We currently don't have many of those so the effect is currently negligible, but onward intent to add more aggressive ones in the code. 179 //#define IMGUI_DEBUG_PARANOID 180 #ifdef IMGUI_DEBUG_PARANOID 181 #define IM_ASSERT_PARANOID(_EXPR) IM_ASSERT(_EXPR) 182 #else 183 #define IM_ASSERT_PARANOID(_EXPR) 184 #endif 185 186 // Error handling 187 // Down the line in some frameworks/languages we would like to have a way to redirect those to the programmer and recover from more faults. 188 #ifndef IM_ASSERT_USER_ERROR 189 #define IM_ASSERT_USER_ERROR(_EXP,_MSG) IM_ASSERT((_EXP) && _MSG) // Recoverable User Error 190 #endif 191 192 // Misc Macros 193 #define IM_PI 3.14159265358979323846f 84 194 #ifdef _WIN32 85 #define IM_NEWLINE "\r\n" // Play it nice with Windows users (2018: Notepad _still_ doesn't display files properly when they use Unix-style carriage returns)195 #define IM_NEWLINE "\r\n" // Play it nice with Windows users (Update: since 2018-05, Notepad finally appears to support Unix-style carriage returns!) 86 196 #else 87 #define IM_NEWLINE "\n" 88 #endif 89 90 // Helpers: UTF-8 <> wchar 91 IMGUI_API int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count 92 IMGUI_API int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count 93 IMGUI_API int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count 94 IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count) 95 IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points 96 97 // Helpers: Misc 98 IMGUI_API ImU32 ImHash(const void* data, int data_size, ImU32 seed = 0); // Pass data_size==0 for zero-terminated strings 99 IMGUI_API void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, int* out_file_size = NULL, int padding_bytes = 0); 100 IMGUI_API FILE* ImFileOpen(const char* filename, const char* file_open_mode); 101 static inline bool ImCharIsSpace(unsigned int c) { return c == ' ' || c == '\t' || c == 0x3000; } 102 static inline bool ImIsPowerOfTwo(int v) { return v != 0 && (v & (v - 1)) == 0; } 103 static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } 104 105 // Helpers: Geometry 106 IMGUI_API ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p); 107 IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); 108 IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); 109 IMGUI_API void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w); 110 111 // Helpers: String 197 #define IM_NEWLINE "\n" 198 #endif 199 #define IM_TABSIZE (4) 200 #define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose 201 #define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255 202 #define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds 203 #define IM_ROUND(_VAL) ((float)(int)((_VAL) + 0.5f)) // 204 205 // Enforce cdecl calling convention for functions called by the standard library, in case compilation settings changed the default to e.g. __vectorcall 206 #ifdef _MSC_VER 207 #define IMGUI_CDECL __cdecl 208 #else 209 #define IMGUI_CDECL 210 #endif 211 212 // Debug Tools 213 // Use 'Metrics->Tools->Item Picker' to break into the call-stack of a specific item. 214 #ifndef IM_DEBUG_BREAK 215 #if defined(__clang__) 216 #define IM_DEBUG_BREAK() __builtin_debugtrap() 217 #elif defined (_MSC_VER) 218 #define IM_DEBUG_BREAK() __debugbreak() 219 #else 220 #define IM_DEBUG_BREAK() IM_ASSERT(0) // It is expected that you define IM_DEBUG_BREAK() into something that will break nicely in a debugger! 221 #endif 222 #endif // #ifndef IM_DEBUG_BREAK 223 224 //----------------------------------------------------------------------------- 225 // [SECTION] Generic helpers 226 // Note that the ImXXX helpers functions are lower-level than ImGui functions. 227 // ImGui functions or the ImGui context are never called/used from other ImXXX functions. 228 //----------------------------------------------------------------------------- 229 // - Helpers: Hashing 230 // - Helpers: Sorting 231 // - Helpers: Bit manipulation 232 // - Helpers: String, Formatting 233 // - Helpers: UTF-8 <> wchar conversions 234 // - Helpers: ImVec2/ImVec4 operators 235 // - Helpers: Maths 236 // - Helpers: Geometry 237 // - Helper: ImVec1 238 // - Helper: ImVec2ih 239 // - Helper: ImRect 240 // - Helper: ImBitArray 241 // - Helper: ImBitVector 242 // - Helper: ImPool<> 243 // - Helper: ImChunkStream<> 244 //----------------------------------------------------------------------------- 245 246 // Helpers: Hashing 247 IMGUI_API ImU32 ImHashData(const void* data, size_t data_size, ImU32 seed = 0); 248 IMGUI_API ImU32 ImHashStr(const char* data, size_t data_size = 0, ImU32 seed = 0); 249 #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS 250 static 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] 251 #endif 252 253 // Helpers: Sorting 254 #define ImQsort qsort 255 256 // Helpers: Color Blending 257 IMGUI_API ImU32 ImAlphaBlendColors(ImU32 col_a, ImU32 col_b); 258 259 // Helpers: Bit manipulation 260 static inline bool ImIsPowerOfTwo(int v) { return v != 0 && (v & (v - 1)) == 0; } 261 static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } 262 263 // Helpers: String, Formatting 112 264 IMGUI_API int ImStricmp(const char* str1, const char* str2); 113 265 IMGUI_API int ImStrnicmp(const char* str1, const char* str2, size_t count); 114 266 IMGUI_API void ImStrncpy(char* dst, const char* src, size_t count); 115 267 IMGUI_API char* ImStrdup(const char* str); 268 IMGUI_API char* ImStrdupcpy(char* dst, size_t* p_dst_size, const char* str); 116 269 IMGUI_API const char* ImStrchrRange(const char* str_begin, const char* str_end, char c); 117 270 IMGUI_API int ImStrlenW(const ImWchar* str); 118 IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line 271 IMGUI_API const char* ImStreolRange(const char* str, const char* str_end); // End end-of-line 272 IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line 119 273 IMGUI_API const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end); 274 IMGUI_API void ImStrTrimBlanks(char* str); 275 IMGUI_API const char* ImStrSkipBlank(const char* str); 120 276 IMGUI_API int ImFormatString(char* buf, size_t buf_size, const char* fmt, ...) IM_FMTARGS(3); 121 277 IMGUI_API int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) IM_FMTLIST(3); 122 123 // Helpers: Math 124 // We are keeping those not leaking to the user by default, in the case the user has implicit cast operators between ImVec2 and its own types (when IM_VEC2_CLASS_EXTRA is defined) 278 IMGUI_API const char* ImParseFormatFindStart(const char* format); 279 IMGUI_API const char* ImParseFormatFindEnd(const char* format); 280 IMGUI_API const char* ImParseFormatTrimDecorations(const char* format, char* buf, size_t buf_size); 281 IMGUI_API int ImParseFormatPrecision(const char* format, int default_value); 282 static inline bool ImCharIsBlankA(char c) { return c == ' ' || c == '\t'; } 283 static inline bool ImCharIsBlankW(unsigned int c) { return c == ' ' || c == '\t' || c == 0x3000; } 284 285 // Helpers: UTF-8 <> wchar conversions 286 IMGUI_API int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count 287 IMGUI_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 288 IMGUI_API int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count 289 IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count) 290 IMGUI_API int ImTextCountUtf8BytesFromChar(const char* in_text, const char* in_text_end); // return number of bytes to express one char in UTF-8 291 IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string in UTF-8 292 293 // Helpers: ImVec2/ImVec4 operators 294 // 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.) 295 // We unfortunately don't have a unary- operator for ImVec2 because this would needs to be defined inside the class itself. 125 296 #ifdef IMGUI_DEFINE_MATH_OPERATORS 126 static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); } 127 static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x / rhs, lhs.y / rhs); } 128 static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x + rhs.x, lhs.y + rhs.y); } 129 static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x - rhs.x, lhs.y - rhs.y); } 130 static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); } 131 static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x / rhs.x, lhs.y / rhs.y); } 132 static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } 133 static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } 134 static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } 135 static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } 136 static inline ImVec4 operator+(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z, lhs.w + rhs.w); } 137 static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z, lhs.w - rhs.w); } 138 static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x*rhs.x, lhs.y*rhs.y, lhs.z*rhs.z, lhs.w*rhs.w); } 139 #endif 140 141 static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; } 142 static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; } 143 static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; } 144 static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; } 145 static 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); } 146 static 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); } 147 static inline int ImClamp(int v, int mn, int mx) { return (v < mn) ? mn : (v > mx) ? mx : v; } 148 static inline float ImClamp(float v, float mn, float mx) { return (v < mn) ? mn : (v > mx) ? mx : v; } 149 static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx) { return ImVec2(ImClamp(f.x, mn.x, mx.x), ImClamp(f.y, mn.y, mx.y)); } 150 static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; } 151 static inline void ImSwap(int& a, int& b) { int tmp = a; a = b; b = tmp; } 152 static inline void ImSwap(float& a, float& b) { float tmp = a; a = b; b = tmp; } 153 static inline int ImLerp(int a, int b, float t) { return (int)(a + (b - a) * t); } 154 static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; } 155 static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, float t) { return ImVec2(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t); } 156 static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); } 157 static inline ImVec4 ImLerp(const ImVec4& a, const ImVec4& b, float t) { return ImVec4(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t); } 158 static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; } 159 static inline float ImLengthSqr(const ImVec4& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y + lhs.z*lhs.z + lhs.w*lhs.w; } 160 static inline float ImInvLength(const ImVec2& lhs, float fail_value) { float d = lhs.x*lhs.x + lhs.y*lhs.y; if (d > 0.0f) return 1.0f / sqrtf(d); return fail_value; } 161 static inline float ImFloor(float f) { return (float)(int)f; } 162 static inline ImVec2 ImFloor(const ImVec2& v) { return ImVec2((float)(int)v.x, (float)(int)v.y); } 163 static inline float ImDot(const ImVec2& a, const ImVec2& b) { return a.x * b.x + a.y * b.y; } 164 static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) { return ImVec2(v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a); } 165 static inline float ImLinearSweep(float current, float target, float speed) { if (current < target) return ImMin(current + speed, target); if (current > target) return ImMax(current - speed, target); return current; } 166 static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } 167 168 //----------------------------------------------------------------------------- 169 // Types 170 //----------------------------------------------------------------------------- 171 172 enum ImGuiButtonFlags_ 173 { 174 ImGuiButtonFlags_Repeat = 1 << 0, // hold to repeat 175 ImGuiButtonFlags_PressedOnClickRelease = 1 << 1, // return true on click + release on same item [DEFAULT if no PressedOn* flag is set] 176 ImGuiButtonFlags_PressedOnClick = 1 << 2, // return true on click (default requires click+release) 177 ImGuiButtonFlags_PressedOnRelease = 1 << 3, // return true on release (default requires click+release) 178 ImGuiButtonFlags_PressedOnDoubleClick = 1 << 4, // return true on double-click (default requires click+release) 179 ImGuiButtonFlags_FlattenChildren = 1 << 5, // allow interactions even if a child window is overlapping 180 ImGuiButtonFlags_AllowItemOverlap = 1 << 6, // require previous frame HoveredId to either match id or be null before being usable, use along with SetItemAllowOverlap() 181 ImGuiButtonFlags_DontClosePopups = 1 << 7, // disable automatically closing parent popup on press // [UNUSED] 182 ImGuiButtonFlags_Disabled = 1 << 8, // disable interactions 183 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 184 ImGuiButtonFlags_NoKeyModifiers = 1 << 10, // disable interaction if a key modifier is held 185 ImGuiButtonFlags_NoHoldingActiveID = 1 << 11, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) 186 ImGuiButtonFlags_PressedOnDragDropHold = 1 << 12, // press when held into while we are drag and dropping another item (used by e.g. tree nodes, collapsing headers) 187 ImGuiButtonFlags_NoNavFocus = 1 << 13 // don't override navigation focus when activated 188 }; 189 190 enum ImGuiSliderFlags_ 191 { 192 ImGuiSliderFlags_Vertical = 1 << 0 193 }; 194 195 enum ImGuiColumnsFlags_ 196 { 197 // Default: 0 198 ImGuiColumnsFlags_NoBorder = 1 << 0, // Disable column dividers 199 ImGuiColumnsFlags_NoResize = 1 << 1, // Disable resizing columns when clicking on the dividers 200 ImGuiColumnsFlags_NoPreserveWidths = 1 << 2, // Disable column width preservation when adjusting columns 201 ImGuiColumnsFlags_NoForceWithinWindow = 1 << 3, // Disable forcing columns to fit within window 202 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. 203 }; 204 205 enum ImGuiSelectableFlagsPrivate_ 206 { 207 // NB: need to be in sync with last value of ImGuiSelectableFlags_ 208 ImGuiSelectableFlags_Menu = 1 << 3, // -> PressedOnClick 209 ImGuiSelectableFlags_MenuItem = 1 << 4, // -> PressedOnRelease 210 ImGuiSelectableFlags_Disabled = 1 << 5, 211 ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 6 212 }; 213 214 enum ImGuiSeparatorFlags_ 215 { 216 ImGuiSeparatorFlags_Horizontal = 1 << 0, // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar 217 ImGuiSeparatorFlags_Vertical = 1 << 1 218 }; 219 220 // Storage for LastItem data 221 enum ImGuiItemStatusFlags_ 222 { 223 ImGuiItemStatusFlags_HoveredRect = 1 << 0, 224 ImGuiItemStatusFlags_HasDisplayRect = 1 << 1 225 }; 226 227 // FIXME: this is in development, not exposed/functional as a generic feature yet. 228 enum ImGuiLayoutType_ 229 { 230 ImGuiLayoutType_Vertical, 231 ImGuiLayoutType_Horizontal 232 }; 233 234 enum ImGuiAxis 235 { 236 ImGuiAxis_None = -1, 237 ImGuiAxis_X = 0, 238 ImGuiAxis_Y = 1 239 }; 240 241 enum ImGuiPlotType 242 { 243 ImGuiPlotType_Lines, 244 ImGuiPlotType_Histogram 245 }; 246 247 enum ImGuiDataType 248 { 249 ImGuiDataType_Int32, 250 ImGuiDataType_Uint32, 251 ImGuiDataType_Float, 252 ImGuiDataType_Double, 253 ImGuiDataType_COUNT 254 }; 255 256 enum ImGuiInputSource 257 { 258 ImGuiInputSource_None = 0, 259 ImGuiInputSource_Mouse, 260 ImGuiInputSource_Nav, 261 ImGuiInputSource_NavKeyboard, // Only used occasionally for storage, not tested/handled by most code 262 ImGuiInputSource_NavGamepad, // " 263 ImGuiInputSource_COUNT 264 }; 265 266 // FIXME-NAV: Clarify/expose various repeat delay/rate 267 enum ImGuiInputReadMode 268 { 269 ImGuiInputReadMode_Down, 270 ImGuiInputReadMode_Pressed, 271 ImGuiInputReadMode_Released, 272 ImGuiInputReadMode_Repeat, 273 ImGuiInputReadMode_RepeatSlow, 274 ImGuiInputReadMode_RepeatFast 275 }; 276 277 enum ImGuiNavHighlightFlags_ 278 { 279 ImGuiNavHighlightFlags_TypeDefault = 1 << 0, 280 ImGuiNavHighlightFlags_TypeThin = 1 << 1, 281 ImGuiNavHighlightFlags_AlwaysDraw = 1 << 2, 282 ImGuiNavHighlightFlags_NoRounding = 1 << 3 283 }; 284 285 enum ImGuiNavDirSourceFlags_ 286 { 287 ImGuiNavDirSourceFlags_Keyboard = 1 << 0, 288 ImGuiNavDirSourceFlags_PadDPad = 1 << 1, 289 ImGuiNavDirSourceFlags_PadLStick = 1 << 2 290 }; 291 292 enum ImGuiNavForward 293 { 294 ImGuiNavForward_None, 295 ImGuiNavForward_ForwardQueued, 296 ImGuiNavForward_ForwardActive 297 }; 298 299 // 2D axis aligned bounding-box 300 // NB: we can't rely on ImVec2 math operators being available here 297 static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x * rhs, lhs.y * rhs); } 298 static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x / rhs, lhs.y / rhs); } 299 static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x + rhs.x, lhs.y + rhs.y); } 300 static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x - rhs.x, lhs.y - rhs.y); } 301 static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } 302 static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x / rhs.x, lhs.y / rhs.y); } 303 static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } 304 static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } 305 static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } 306 static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } 307 static inline ImVec2& operator*=(ImVec2& lhs, const ImVec2& rhs) { lhs.x *= rhs.x; lhs.y *= rhs.y; return lhs; } 308 static inline ImVec2& operator/=(ImVec2& lhs, const ImVec2& rhs) { lhs.x /= rhs.x; lhs.y /= rhs.y; return lhs; } 309 static inline ImVec4 operator+(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z, lhs.w + rhs.w); } 310 static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z, lhs.w - rhs.w); } 311 static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z, lhs.w * rhs.w); } 312 #endif 313 314 // Helpers: File System 315 #ifdef IMGUI_DISABLE_FILE_FUNCTIONS 316 #define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS 317 typedef void* ImFileHandle; 318 static inline ImFileHandle ImFileOpen(const char*, const char*) { return NULL; } 319 static inline bool ImFileClose(ImFileHandle) { return false; } 320 static inline ImU64 ImFileGetSize(ImFileHandle) { return (ImU64)-1; } 321 static inline ImU64 ImFileRead(void*, ImU64, ImU64, ImFileHandle) { return 0; } 322 static inline ImU64 ImFileWrite(const void*, ImU64, ImU64, ImFileHandle) { return 0; } 323 #endif 324 #ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS 325 typedef FILE* ImFileHandle; 326 IMGUI_API ImFileHandle ImFileOpen(const char* filename, const char* mode); 327 IMGUI_API bool ImFileClose(ImFileHandle file); 328 IMGUI_API ImU64 ImFileGetSize(ImFileHandle file); 329 IMGUI_API ImU64 ImFileRead(void* data, ImU64 size, ImU64 count, ImFileHandle file); 330 IMGUI_API ImU64 ImFileWrite(const void* data, ImU64 size, ImU64 count, ImFileHandle file); 331 #else 332 #define IMGUI_DISABLE_TTY_FUNCTIONS // Can't use stdout, fflush if we are not using default file functions 333 #endif 334 IMGUI_API void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size = NULL, int padding_bytes = 0); 335 336 // Helpers: Maths 337 // - Wrapper for standard libs functions. (Note that imgui_demo.cpp does _not_ use them to keep the code easy to copy) 338 #ifndef IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS 339 #define ImFabs(X) fabsf(X) 340 #define ImSqrt(X) sqrtf(X) 341 #define ImFmod(X, Y) fmodf((X), (Y)) 342 #define ImCos(X) cosf(X) 343 #define ImSin(X) sinf(X) 344 #define ImAcos(X) acosf(X) 345 #define ImAtan2(Y, X) atan2f((Y), (X)) 346 #define ImAtof(STR) atof(STR) 347 #define ImFloorStd(X) 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 e.g. stb_truetype) 348 #define ImCeil(X) ceilf(X) 349 static inline float ImPow(float x, float y) { return powf(x, y); } // DragBehaviorT/SliderBehaviorT uses ImPow with either float/double and need the precision 350 static inline double ImPow(double x, double y) { return pow(x, y); } 351 static inline float ImLog(float x) { return logf(x); } // DragBehaviorT/SliderBehaviorT uses ImLog with either float/double and need the precision 352 static inline double ImLog(double x) { return log(x); } 353 static inline float ImAbs(float x) { return fabsf(x); } 354 static inline double ImAbs(double x) { return fabs(x); } 355 static inline float ImSign(float x) { return (x < 0.0f) ? -1.0f : ((x > 0.0f) ? 1.0f : 0.0f); } // Sign operator - returns -1, 0 or 1 based on sign of argument 356 static inline double ImSign(double x) { return (x < 0.0) ? -1.0 : ((x > 0.0) ? 1.0 : 0.0); } 357 #endif 358 // - ImMin/ImMax/ImClamp/ImLerp/ImSwap are used by widgets which support variety of types: signed/unsigned int/long long float/double 359 // (Exceptionally using templates here but we could also redefine them for those types) 360 template<typename T> static inline T ImMin(T lhs, T rhs) { return lhs < rhs ? lhs : rhs; } 361 template<typename T> static inline T ImMax(T lhs, T rhs) { return lhs >= rhs ? lhs : rhs; } 362 template<typename T> static inline T ImClamp(T v, T mn, T mx) { return (v < mn) ? mn : (v > mx) ? mx : v; } 363 template<typename T> static inline T ImLerp(T a, T b, float t) { return (T)(a + (b - a) * t); } 364 template<typename T> static inline void ImSwap(T& a, T& b) { T tmp = a; a = b; b = tmp; } 365 template<typename T> static inline T ImAddClampOverflow(T a, T b, T mn, T mx) { if (b < 0 && (a < mn - b)) return mn; if (b > 0 && (a > mx - b)) return mx; return a + b; } 366 template<typename T> static inline T ImSubClampOverflow(T a, T b, T mn, T mx) { if (b > 0 && (a < mn + b)) return mn; if (b < 0 && (a > mx + b)) return mx; return a - b; } 367 // - Misc maths helpers 368 static 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); } 369 static 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); } 370 static 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); } 371 static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, float t) { return ImVec2(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t); } 372 static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); } 373 static inline ImVec4 ImLerp(const ImVec4& a, const ImVec4& b, float t) { return ImVec4(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t); } 374 static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; } 375 static inline float ImLengthSqr(const ImVec2& lhs) { return (lhs.x * lhs.x) + (lhs.y * lhs.y); } 376 static inline float ImLengthSqr(const ImVec4& lhs) { return (lhs.x * lhs.x) + (lhs.y * lhs.y) + (lhs.z * lhs.z) + (lhs.w * lhs.w); } 377 static inline float ImInvLength(const ImVec2& lhs, float fail_value) { float d = (lhs.x * lhs.x) + (lhs.y * lhs.y); if (d > 0.0f) return 1.0f / ImSqrt(d); return fail_value; } 378 static inline float ImFloor(float f) { return (float)(int)(f); } 379 static inline ImVec2 ImFloor(const ImVec2& v) { return ImVec2((float)(int)(v.x), (float)(int)(v.y)); } 380 static inline int ImModPositive(int a, int b) { return (a + b) % b; } 381 static inline float ImDot(const ImVec2& a, const ImVec2& b) { return a.x * b.x + a.y * b.y; } 382 static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) { return ImVec2(v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a); } 383 static inline float ImLinearSweep(float current, float target, float speed) { if (current < target) return ImMin(current + speed, target); if (current > target) return ImMax(current - speed, target); return current; } 384 static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } 385 386 // Helpers: Geometry 387 IMGUI_API ImVec2 ImBezierCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float t); // Cubic Bezier 388 IMGUI_API ImVec2 ImBezierClosestPoint(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& p, int num_segments); // For curves with explicit number of segments 389 IMGUI_API ImVec2 ImBezierClosestPointCasteljau(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& p, float tess_tol);// For auto-tessellated curves you can use tess_tol = style.CurveTessellationTol 390 IMGUI_API ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p); 391 IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); 392 IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); 393 IMGUI_API void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w); 394 inline float ImTriangleArea(const ImVec2& a, const ImVec2& b, const ImVec2& c) { return ImFabs((a.x * (b.y - c.y)) + (b.x * (c.y - a.y)) + (c.x * (a.y - b.y))) * 0.5f; } 395 IMGUI_API ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy); 396 397 // Helper: ImVec1 (1D vector) 398 // (this odd construct is used to facilitate the transition between 1D and 2D, and the maintenance of some branches/patches) 399 struct ImVec1 400 { 401 float x; 402 ImVec1() { x = 0.0f; } 403 ImVec1(float _x) { x = _x; } 404 }; 405 406 // Helper: ImVec2ih (2D vector, half-size integer, for long-term packed storage) 407 struct ImVec2ih 408 { 409 short x, y; 410 ImVec2ih() { x = y = 0; } 411 ImVec2ih(short _x, short _y) { x = _x; y = _y; } 412 explicit ImVec2ih(const ImVec2& rhs) { x = (short)rhs.x; y = (short)rhs.y; } 413 }; 414 415 // Helper: ImRect (2D axis aligned bounding-box) 416 // NB: we can't rely on ImVec2 math operators being available here! 301 417 struct IMGUI_API ImRect 302 418 { 303 ImVec2 Min; // Upper-left 304 ImVec2 Max; // Lower-right 305 306 ImRect() : Min(FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX) {} 307 ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {} 308 ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {} 309 ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {} 310 311 ImVec2 GetCenter() const { return ImVec2((Min.x + Max.x) * 0.5f, (Min.y + Max.y) * 0.5f); } 312 ImVec2 GetSize() const { return ImVec2(Max.x - Min.x, Max.y - Min.y); } 313 float GetWidth() const { return Max.x - Min.x; } 314 float GetHeight() const { return Max.y - Min.y; } 315 ImVec2 GetTL() const { return Min; } // Top-left 316 ImVec2 GetTR() const { return ImVec2(Max.x, Min.y); } // Top-right 317 ImVec2 GetBL() const { return ImVec2(Min.x, Max.y); } // Bottom-left 318 ImVec2 GetBR() const { return Max; } // Bottom-right 319 bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; } 320 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; } 321 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; } 322 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; } 323 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; } 324 void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; } 325 void Expand(const ImVec2& amount) { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; } 326 void Translate(const ImVec2& d) { Min.x += d.x; Min.y += d.y; Max.x += d.x; Max.y += d.y; } 327 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. 328 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. 329 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; } 330 bool IsInverted() const { return Min.x > Max.x || Min.y > Max.y; } 331 }; 332 333 // Stacked color modifier, backup of modified data so we can restore it 334 struct ImGuiColMod 335 { 336 ImGuiCol Col; 337 ImVec4 BackupValue; 338 }; 339 340 // Stacked style modifier, backup of modified data so we can restore it. Data type inferred from the variable. 341 struct ImGuiStyleMod 342 { 343 ImGuiStyleVar VarIdx; 344 union { int BackupInt[2]; float BackupFloat[2]; }; 345 ImGuiStyleMod(ImGuiStyleVar idx, int v) { VarIdx = idx; BackupInt[0] = v; } 346 ImGuiStyleMod(ImGuiStyleVar idx, float v) { VarIdx = idx; BackupFloat[0] = v; } 347 ImGuiStyleMod(ImGuiStyleVar idx, ImVec2 v) { VarIdx = idx; BackupFloat[0] = v.x; BackupFloat[1] = v.y; } 348 }; 349 350 // Stacked data for BeginGroup()/EndGroup() 351 struct ImGuiGroupData 352 { 353 ImVec2 BackupCursorPos; 354 ImVec2 BackupCursorMaxPos; 355 float BackupIndentX; 356 float BackupGroupOffsetX; 357 float BackupCurrentLineHeight; 358 float BackupCurrentLineTextBaseOffset; 359 float BackupLogLinePosY; 360 bool BackupActiveIdIsAlive; 361 bool AdvanceCursor; 362 }; 363 364 // Simple column measurement currently used for MenuItem() only. This is very short-sighted/throw-away code and NOT a generic helper. 365 struct IMGUI_API ImGuiMenuColumns 366 { 367 int Count; 368 float Spacing; 369 float Width, NextWidth; 370 float Pos[4], NextWidths[4]; 371 372 ImGuiMenuColumns(); 373 void Update(int count, float spacing, bool clear); 374 float DeclColumns(float w0, float w1, float w2); 375 float CalcExtraSpace(float avail_w); 376 }; 377 378 // Internal state of the currently focused/edited text input box 379 struct IMGUI_API ImGuiTextEditState 380 { 381 ImGuiID Id; // widget id owning the text state 382 ImVector<ImWchar> Text; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer. 383 ImVector<char> InitialText; // backup of end-user buffer at the time of focus (in UTF-8, unaltered) 384 ImVector<char> TempTextBuffer; 385 int CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format. 386 int BufSizeA; // end-user buffer size 387 float ScrollX; 388 ImGuiStb::STB_TexteditState StbState; 389 float CursorAnim; 390 bool CursorFollow; 391 bool SelectedAllMouseLock; 392 393 ImGuiTextEditState() { memset(this, 0, sizeof(*this)); } 394 void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking 395 void CursorClamp() { StbState.cursor = ImMin(StbState.cursor, CurLenW); StbState.select_start = ImMin(StbState.select_start, CurLenW); StbState.select_end = ImMin(StbState.select_end, CurLenW); } 396 bool HasSelection() const { return StbState.select_start != StbState.select_end; } 397 void ClearSelection() { StbState.select_start = StbState.select_end = StbState.cursor; } 398 void SelectAll() { StbState.select_start = 0; StbState.cursor = StbState.select_end = CurLenW; StbState.has_preferred_x = false; } 399 void OnKeyPressed(int key); 400 }; 401 402 // Data saved in imgui.ini file 403 struct ImGuiWindowSettings 404 { 405 char* Name; 406 ImGuiID Id; 407 ImVec2 Pos; 408 ImVec2 Size; 409 bool Collapsed; 410 411 ImGuiWindowSettings() { Name = NULL; Id = 0; Pos = Size = ImVec2(0, 0); Collapsed = false; } 412 }; 413 414 struct ImGuiSettingsHandler 415 { 416 const char* TypeName; // Short description stored in .ini file. Disallowed characters: '[' ']' 417 ImGuiID TypeHash; // == ImHash(TypeName, 0, 0) 418 void* (*ReadOpenFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name); // Read: Called when entering into a new ini entry e.g. "[Window][Name]" 419 void(*ReadLineFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line); // Read: Called for every line of text within an ini entry 420 void(*WriteAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf); // Write: Output every entries into 'out_buf' 421 void* UserData; 422 423 ImGuiSettingsHandler() { memset(this, 0, sizeof(*this)); } 424 }; 425 426 // Storage for current popup stack 427 struct ImGuiPopupRef 428 { 429 ImGuiID PopupId; // Set on OpenPopup() 430 ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup() 431 ImGuiWindow* ParentWindow; // Set on OpenPopup() 432 int OpenFrameCount; // Set on OpenPopup() 433 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) 434 ImVec2 OpenPopupPos; // Set on OpenPopup(), preferred popup position (typically == OpenMousePos when using mouse) 435 ImVec2 OpenMousePos; // Set on OpenPopup(), copy of mouse position at the time of opening popup 436 }; 437 438 struct ImGuiColumnData 439 { 440 float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right) 441 float OffsetNormBeforeResize; 442 ImGuiColumnsFlags Flags; // Not exposed 443 ImRect ClipRect; 444 445 ImGuiColumnData() { OffsetNorm = OffsetNormBeforeResize = 0.0f; Flags = 0; } 446 }; 447 448 struct ImGuiColumnsSet 449 { 450 ImGuiID ID; 451 ImGuiColumnsFlags Flags; 452 bool IsFirstFrame; 453 bool IsBeingResized; 454 int Current; 455 int Count; 456 float MinX, MaxX; 457 float LineMinY, LineMaxY; 458 float StartPosY; // Copy of CursorPos 459 float StartMaxPosX; // Copy of CursorMaxPos 460 ImVector<ImGuiColumnData> Columns; 461 462 ImGuiColumnsSet() { Clear(); } 463 void Clear() 464 { 465 ID = 0; 466 Flags = 0; 467 IsFirstFrame = false; 468 IsBeingResized = false; 469 Current = 0; 470 Count = 1; 471 MinX = MaxX = 0.0f; 472 LineMinY = LineMaxY = 0.0f; 473 StartPosY = 0.0f; 474 StartMaxPosX = 0.0f; 475 Columns.clear(); 476 } 477 }; 478 419 ImVec2 Min; // Upper-left 420 ImVec2 Max; // Lower-right 421 422 ImRect() : Min(0.0f, 0.0f), Max(0.0f, 0.0f) {} 423 ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {} 424 ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {} 425 ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {} 426 427 ImVec2 GetCenter() const { return ImVec2((Min.x + Max.x) * 0.5f, (Min.y + Max.y) * 0.5f); } 428 ImVec2 GetSize() const { return ImVec2(Max.x - Min.x, Max.y - Min.y); } 429 float GetWidth() const { return Max.x - Min.x; } 430 float GetHeight() const { return Max.y - Min.y; } 431 ImVec2 GetTL() const { return Min; } // Top-left 432 ImVec2 GetTR() const { return ImVec2(Max.x, Min.y); } // Top-right 433 ImVec2 GetBL() const { return ImVec2(Min.x, Max.y); } // Bottom-left 434 ImVec2 GetBR() const { return Max; } // Bottom-right 435 bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; } 436 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; } 437 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; } 438 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; } 439 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; } 440 void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; } 441 void Expand(const ImVec2& amount) { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; } 442 void Translate(const ImVec2& d) { Min.x += d.x; Min.y += d.y; Max.x += d.x; Max.y += d.y; } 443 void TranslateX(float dx) { Min.x += dx; Max.x += dx; } 444 void TranslateY(float dy) { Min.y += dy; Max.y += dy; } 445 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. 446 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. 447 void Floor() { Min.x = IM_FLOOR(Min.x); Min.y = IM_FLOOR(Min.y); Max.x = IM_FLOOR(Max.x); Max.y = IM_FLOOR(Max.y); } 448 bool IsInverted() const { return Min.x > Max.x || Min.y > Max.y; } 449 ImVec4 ToVec4() const { return ImVec4(Min.x, Min.y, Max.x, Max.y); } 450 }; 451 452 // Helper: ImBitArray 453 inline bool ImBitArrayTestBit(const ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); return (arr[n >> 5] & mask) != 0; } 454 inline void ImBitArrayClearBit(ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); arr[n >> 5] &= ~mask; } 455 inline void ImBitArraySetBit(ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); arr[n >> 5] |= mask; } 456 inline void ImBitArraySetBitRange(ImU32* arr, int n, int n2) 457 { 458 while (n <= n2) 459 { 460 int a_mod = (n & 31); 461 int b_mod = ((n2 >= n + 31) ? 31 : (n2 & 31)) + 1; 462 ImU32 mask = (ImU32)(((ImU64)1 << b_mod) - 1) & ~(ImU32)(((ImU64)1 << a_mod) - 1); 463 arr[n >> 5] |= mask; 464 n = (n + 32) & ~31; 465 } 466 } 467 468 // Helper: ImBitVector 469 // Store 1-bit per value. 470 struct IMGUI_API ImBitVector 471 { 472 ImVector<ImU32> Storage; 473 void Create(int sz) { Storage.resize((sz + 31) >> 5); memset(Storage.Data, 0, (size_t)Storage.Size * sizeof(Storage.Data[0])); } 474 void Clear() { Storage.clear(); } 475 bool TestBit(int n) const { IM_ASSERT(n < (Storage.Size << 5)); return ImBitArrayTestBit(Storage.Data, n); } 476 void SetBit(int n) { IM_ASSERT(n < (Storage.Size << 5)); ImBitArraySetBit(Storage.Data, n); } 477 void ClearBit(int n) { IM_ASSERT(n < (Storage.Size << 5)); ImBitArrayClearBit(Storage.Data, n); } 478 }; 479 480 // Helper: ImPool<> 481 // Basic keyed storage for contiguous instances, slow/amortized insertion, O(1) indexable, O(Log N) queries by ID over a dense/hot buffer, 482 // Honor constructor/destructor. Add/remove invalidate all pointers. Indexes have the same lifetime as the associated object. 483 typedef int ImPoolIdx; 484 template<typename T> 485 struct IMGUI_API ImPool 486 { 487 ImVector<T> Buf; // Contiguous data 488 ImGuiStorage Map; // ID->Index 489 ImPoolIdx FreeIdx; // Next free idx to use 490 491 ImPool() { FreeIdx = 0; } 492 ~ImPool() { Clear(); } 493 T* GetByKey(ImGuiID key) { int idx = Map.GetInt(key, -1); return (idx != -1) ? &Buf[idx] : NULL; } 494 T* GetByIndex(ImPoolIdx n) { return &Buf[n]; } 495 ImPoolIdx GetIndex(const T* p) const { IM_ASSERT(p >= Buf.Data && p < Buf.Data + Buf.Size); return (ImPoolIdx)(p - Buf.Data); } 496 T* GetOrAddByKey(ImGuiID key) { int* p_idx = Map.GetIntRef(key, -1); if (*p_idx != -1) return &Buf[*p_idx]; *p_idx = FreeIdx; return Add(); } 497 bool Contains(const T* p) const { return (p >= Buf.Data && p < Buf.Data + Buf.Size); } 498 void Clear() { for (int n = 0; n < Map.Data.Size; n++) { int idx = Map.Data[n].val_i; if (idx != -1) Buf[idx].~T(); } Map.Clear(); Buf.clear(); FreeIdx = 0; } 499 T* Add() { int idx = FreeIdx; if (idx == Buf.Size) { Buf.resize(Buf.Size + 1); FreeIdx++; } else { FreeIdx = *(int*)&Buf[idx]; } IM_PLACEMENT_NEW(&Buf[idx]) T(); return &Buf[idx]; } 500 void Remove(ImGuiID key, const T* p) { Remove(key, GetIndex(p)); } 501 void Remove(ImGuiID key, ImPoolIdx idx) { Buf[idx].~T(); *(int*)&Buf[idx] = FreeIdx; FreeIdx = idx; Map.SetInt(key, -1); } 502 void Reserve(int capacity) { Buf.reserve(capacity); Map.Data.reserve(capacity); } 503 int GetSize() const { return Buf.Size; } 504 }; 505 506 // Helper: ImChunkStream<> 507 // Build and iterate a contiguous stream of variable-sized structures. 508 // This is used by Settings to store persistent data while reducing allocation count. 509 // We store the chunk size first, and align the final size on 4 bytes boundaries (this what the '(X + 3) & ~3' statement is for) 510 // The tedious/zealous amount of casting is to avoid -Wcast-align warnings. 511 template<typename T> 512 struct IMGUI_API ImChunkStream 513 { 514 ImVector<char> Buf; 515 516 void clear() { Buf.clear(); } 517 bool empty() const { return Buf.Size == 0; } 518 int size() const { return Buf.Size; } 519 T* alloc_chunk(size_t sz) { size_t HDR_SZ = 4; sz = ((HDR_SZ + sz) + 3u) & ~3u; int off = Buf.Size; Buf.resize(off + (int)sz); ((int*)(void*)(Buf.Data + off))[0] = (int)sz; return (T*)(void*)(Buf.Data + off + (int)HDR_SZ); } 520 T* begin() { size_t HDR_SZ = 4; if (!Buf.Data) return NULL; return (T*)(void*)(Buf.Data + HDR_SZ); } 521 T* next_chunk(T* p) { size_t HDR_SZ = 4; IM_ASSERT(p >= begin() && p < end()); p = (T*)(void*)((char*)(void*)p + chunk_size(p)); if (p == (T*)(void*)((char*)end() + HDR_SZ)) return (T*)0; IM_ASSERT(p < end()); return p; } 522 int chunk_size(const T* p) { return ((const int*)p)[-1]; } 523 T* end() { return (T*)(void*)(Buf.Data + Buf.Size); } 524 int offset_from_ptr(const T* p) { IM_ASSERT(p >= begin() && p < end()); const ptrdiff_t off = (const char*)p - Buf.Data; return (int)off; } 525 T* ptr_from_offset(int off) { IM_ASSERT(off >= 4 && off < Buf.Size); return (T*)(void*)(Buf.Data + off); } 526 }; 527 528 //----------------------------------------------------------------------------- 529 // [SECTION] ImDrawList support 530 //----------------------------------------------------------------------------- 531 532 // ImDrawList: Helper function to calculate a circle's segment count given its radius and a "maximum error" value. 533 #define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MIN 12 534 #define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX 512 535 #define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(_RAD,_MAXERROR) ImClamp((int)((IM_PI * 2.0f) / ImAcos(((_RAD) - (_MAXERROR)) / (_RAD))), IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MIN, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX) 536 537 // ImDrawList: You may set this to higher values (e.g. 2 or 3) to increase tessellation of fast rounded corners path. 538 #ifndef IM_DRAWLIST_ARCFAST_TESSELLATION_MULTIPLIER 539 #define IM_DRAWLIST_ARCFAST_TESSELLATION_MULTIPLIER 1 540 #endif 541 542 // Data shared between all ImDrawList instances 543 // You may want to create your own instance of this if you want to use ImDrawList completely without ImGui. In that case, watch out for future changes to this structure. 479 544 struct IMGUI_API ImDrawListSharedData 480 545 { 481 ImVec2 TexUvWhitePixel; // UV of white pixel in the atlas 482 ImFont* Font; // Current/default font (optional, for simplified AddText overload) 483 float FontSize; // Current/default font size (optional, for simplified AddText overload) 484 float CurveTessellationTol; 485 ImVec4 ClipRectFullscreen; // Value for PushClipRectFullscreen() 486 487 // Const data 488 // FIXME: Bake rounded corners fill/borders in atlas 489 ImVec2 CircleVtx12[12]; 490 491 ImDrawListSharedData(); 546 ImVec2 TexUvWhitePixel; // UV of white pixel in the atlas 547 ImFont* Font; // Current/default font (optional, for simplified AddText overload) 548 float FontSize; // Current/default font size (optional, for simplified AddText overload) 549 float CurveTessellationTol; // Tessellation tolerance when using PathBezierCurveTo() 550 float CircleSegmentMaxError; // Number of circle segments to use per pixel of radius for AddCircle() etc 551 ImVec4 ClipRectFullscreen; // Value for PushClipRectFullscreen() 552 ImDrawListFlags InitialFlags; // Initial flags at the beginning of the frame (it is possible to alter flags on a per-drawlist basis afterwards) 553 554 // [Internal] Lookup tables 555 ImVec2 ArcFastVtx[12 * IM_DRAWLIST_ARCFAST_TESSELLATION_MULTIPLIER]; // FIXME: Bake rounded corners fill/borders in atlas 556 ImU8 CircleSegmentCounts[64]; // Precomputed segment count for given radius (array index + 1) before we calculate it dynamically (to avoid calculation overhead) 557 const ImVec4* TexUvLines; // UV of anti-aliased lines in the atlas 558 559 ImDrawListSharedData(); 560 void SetCircleSegmentMaxError(float max_error); 492 561 }; 493 562 494 563 struct ImDrawDataBuilder 495 564 { 496 ImVector<ImDrawList*> Layers[2]; // Global layers for: regular, tooltip 497 498 void Clear() { for (int n = 0; n < IM_ARRAYSIZE(Layers); n++) Layers[n].resize(0); } 499 void ClearFreeMemory() { for (int n = 0; n < IM_ARRAYSIZE(Layers); n++) Layers[n].clear(); } 500 IMGUI_API void FlattenIntoSingleLayer(); 501 }; 502 503 struct ImGuiNavMoveResult 504 { 505 ImGuiID ID; // Best candidate 506 ImGuiID ParentID; // Best candidate window->IDStack.back() - to compare context 507 ImGuiWindow* Window; // Best candidate window 508 float DistBox; // Best candidate box distance to current NavId 509 float DistCenter; // Best candidate center distance to current NavId 510 float DistAxial; 511 ImRect RectRel; // Best candidate bounding box in window relative space 512 513 ImGuiNavMoveResult() { Clear(); } 514 void Clear() { ID = ParentID = 0; Window = NULL; DistBox = DistCenter = DistAxial = FLT_MAX; RectRel = ImRect(); } 515 }; 516 517 // Storage for SetNexWindow** functions 518 struct ImGuiNextWindowData 519 { 520 ImGuiCond PosCond; 521 ImGuiCond SizeCond; 522 ImGuiCond ContentSizeCond; 523 ImGuiCond CollapsedCond; 524 ImGuiCond SizeConstraintCond; 525 ImGuiCond FocusCond; 526 ImGuiCond BgAlphaCond; 527 ImVec2 PosVal; 528 ImVec2 PosPivotVal; 529 ImVec2 SizeVal; 530 ImVec2 ContentSizeVal; 531 bool CollapsedVal; 532 ImRect SizeConstraintRect; 533 ImGuiSizeCallback SizeCallback; 534 void* SizeCallbackUserData; 535 float BgAlphaVal; 536 ImVec2 MenuBarOffsetMinVal; // This is not exposed publicly, so we don't clear it. 537 538 ImGuiNextWindowData() 539 { 540 PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = BgAlphaCond = 0; 541 PosVal = PosPivotVal = SizeVal = ImVec2(0.0f, 0.0f); 542 ContentSizeVal = ImVec2(0.0f, 0.0f); 543 CollapsedVal = false; 544 SizeConstraintRect = ImRect(); 545 SizeCallback = NULL; 546 SizeCallbackUserData = NULL; 547 BgAlphaVal = FLT_MAX; 548 MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f); 549 } 550 551 void Clear() 552 { 553 PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = BgAlphaCond = 0; 554 } 555 }; 556 557 // Main state for ImGui 558 struct ImGuiContext 559 { 560 bool Initialized; 561 bool FontAtlasOwnedByContext; // Io.Fonts-> is owned by the ImGuiContext and will be destructed along with it. 562 ImGuiIO IO; 563 ImGuiStyle Style; 564 ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back() 565 float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize(). Text height for current window. 566 float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Base text height. 567 ImDrawListSharedData DrawListSharedData; 568 569 float Time; 570 int FrameCount; 571 int FrameCountEnded; 572 int FrameCountRendered; 573 ImVector<ImGuiWindow*> Windows; 574 ImVector<ImGuiWindow*> WindowsSortBuffer; 575 ImVector<ImGuiWindow*> CurrentWindowStack; 576 ImGuiStorage WindowsById; 577 int WindowsActiveCount; 578 ImGuiWindow* CurrentWindow; // Being drawn into 579 ImGuiWindow* HoveredWindow; // Will catch mouse inputs 580 ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only) 581 ImGuiID HoveredId; // Hovered widget 582 bool HoveredIdAllowOverlap; 583 ImGuiID HoveredIdPreviousFrame; 584 float HoveredIdTimer; 585 ImGuiID ActiveId; // Active widget 586 ImGuiID ActiveIdPreviousFrame; 587 float ActiveIdTimer; 588 bool ActiveIdIsAlive; // Active widget has been seen this frame 589 bool ActiveIdIsJustActivated; // Set at the time of activation for one frame 590 bool ActiveIdAllowOverlap; // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always) 591 int ActiveIdAllowNavDirFlags; // Active widget allows using directional navigation (e.g. can activate a button and move away from it) 592 ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) 593 ImGuiWindow* ActiveIdWindow; 594 ImGuiInputSource ActiveIdSource; // Activating with mouse or nav (gamepad/keyboard) 595 ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actually window that is moved is generally MovingWindow->RootWindow. 596 ImVector<ImGuiColMod> ColorModifiers; // Stack for PushStyleColor()/PopStyleColor() 597 ImVector<ImGuiStyleMod> StyleModifiers; // Stack for PushStyleVar()/PopStyleVar() 598 ImVector<ImFont*> FontStack; // Stack for PushFont()/PopFont() 599 ImVector<ImGuiPopupRef> OpenPopupStack; // Which popups are open (persistent) 600 ImVector<ImGuiPopupRef> CurrentPopupStack; // Which level of BeginPopup() we are in (reset every frame) 601 ImGuiNextWindowData NextWindowData; // Storage for SetNextWindow** functions 602 bool NextTreeNodeOpenVal; // Storage for SetNextTreeNode** functions 603 ImGuiCond NextTreeNodeOpenCond; 604 605 // Navigation data (for gamepad/keyboard) 606 ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusWindow' 607 ImGuiID NavId; // Focused item for navigation 608 ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0, also set when calling ActivateItem() 609 ImGuiID NavActivateDownId; // ~~ IsNavInputDown(ImGuiNavInput_Activate) ? NavId : 0 610 ImGuiID NavActivatePressedId; // ~~ IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0 611 ImGuiID NavInputId; // ~~ IsNavInputPressed(ImGuiNavInput_Input) ? NavId : 0 612 ImGuiID NavJustTabbedId; // Just tabbed to this id. 613 ImGuiID NavJustMovedToId; // Just navigated to this id (result of a successfully MoveRequest) 614 ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame 615 ImGuiInputSource NavInputSource; // Keyboard or Gamepad mode? 616 ImRect NavScoringRectScreen; // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring. 617 int NavScoringCount; // Metrics for debugging 618 ImGuiWindow* NavWindowingTarget; // When selecting a window (holding Menu+FocusPrev/Next, or equivalent of CTRL-TAB) this window is temporarily displayed front-most. 619 float NavWindowingHighlightTimer; 620 float NavWindowingHighlightAlpha; 621 bool NavWindowingToggleLayer; 622 int 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. 623 int NavIdTabCounter; // == NavWindow->DC.FocusIdxTabCounter at time of NavId processing 624 bool NavIdIsAlive; // Nav widget has been seen this frame ~~ NavRefRectRel is valid 625 bool NavMousePosDirty; // When set we will update mouse position if (io.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos) if set (NB: this not enabled by default) 626 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) 627 bool NavDisableMouseHover; // When user starts using gamepad/keyboard, we hide mouse hovering highlight until mouse is touched again. 628 bool NavAnyRequest; // ~~ NavMoveRequest || NavInitRequest 629 bool NavInitRequest; // Init request for appearing window to select first item 630 bool NavInitRequestFromMove; 631 ImGuiID NavInitResultId; 632 ImRect NavInitResultRectRel; 633 bool NavMoveFromClampedRefRect; // Set by manual scrolling, if we scroll to a point where NavId isn't visible we reset navigation from visible items 634 bool NavMoveRequest; // Move request for this frame 635 ImGuiNavForward NavMoveRequestForward; // None / ForwardQueued / ForwardActive (this is used to navigate sibling parent menus from a child menu) 636 ImGuiDir NavMoveDir, NavMoveDirLast; // Direction of the move request (left/right/up/down), direction of the previous move request 637 ImGuiNavMoveResult NavMoveResultLocal; // Best move request candidate within NavWindow 638 ImGuiNavMoveResult NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using the NavFlattened flag) 639 640 // Render 641 ImDrawData DrawData; // Main ImDrawData instance to pass render information to the user 642 ImDrawDataBuilder DrawDataBuilder; 643 float ModalWindowDarkeningRatio; 644 ImDrawList OverlayDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays 645 ImGuiMouseCursor MouseCursor; 646 647 // Drag and Drop 648 bool DragDropActive; 649 ImGuiDragDropFlags DragDropSourceFlags; 650 int DragDropMouseButton; 651 ImGuiPayload DragDropPayload; 652 ImRect DragDropTargetRect; 653 ImGuiID DragDropTargetId; 654 float DragDropAcceptIdCurrRectSurface; 655 ImGuiID DragDropAcceptIdCurr; // Target item id (set at the time of accepting the payload) 656 ImGuiID DragDropAcceptIdPrev; // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets) 657 int DragDropAcceptFrameCount; // Last time a target expressed a desire to accept the source 658 ImVector<unsigned char> DragDropPayloadBufHeap; // We don't expose the ImVector<> directly 659 unsigned char DragDropPayloadBufLocal[8]; // Local buffer for small payloads 660 661 // Widget state 662 ImGuiTextEditState InputTextState; 663 ImFont InputTextPasswordFont; 664 ImGuiID ScalarAsInputTextId; // Temporary text input when CTRL+clicking on a slider, etc. 665 ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets 666 ImVec4 ColorPickerRef; 667 float DragCurrentValue; // Currently dragged value, always float, not rounded by end-user precision settings 668 ImVec2 DragLastMouseDelta; 669 float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio 670 float DragSpeedScaleSlow; 671 float DragSpeedScaleFast; 672 ImVec2 ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage? 673 int TooltipOverrideCount; 674 ImVector<char> PrivateClipboard; // If no custom clipboard handler is defined 675 ImVec2 PlatformImePos, PlatformImeLastPos; // Cursor position request & last passed to the OS Input Method Editor 676 677 // Settings 678 bool SettingsLoaded; 679 float SettingsDirtyTimer; // Save .ini Settings on disk when time reaches zero 680 ImVector<ImGuiWindowSettings> SettingsWindows; // .ini settings for ImGuiWindow 681 ImVector<ImGuiSettingsHandler> SettingsHandlers; // List of .ini settings handlers 682 683 // Logging 684 bool LogEnabled; 685 FILE* LogFile; // If != NULL log to stdout/ file 686 ImGuiTextBuffer* LogClipboard; // Else log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators. 687 int LogStartDepth; 688 int LogAutoExpandMaxDepth; 689 690 // Misc 691 float FramerateSecPerFrame[120]; // Calculate estimate of framerate for user over the last 2 seconds. 692 int FramerateSecPerFrameIdx; 693 float FramerateSecPerFrameAccum; 694 int WantCaptureMouseNextFrame; // Explicit capture via CaptureKeyboardFromApp()/CaptureMouseFromApp() sets those flags 695 int WantCaptureKeyboardNextFrame; 696 int WantTextInputNextFrame; 697 char TempBuffer[1024 * 3 + 1]; // Temporary text buffer 698 699 ImGuiContext(ImFontAtlas* shared_font_atlas) : OverlayDrawList(NULL) 700 { 701 Initialized = false; 702 Font = NULL; 703 FontSize = FontBaseSize = 0.0f; 704 FontAtlasOwnedByContext = shared_font_atlas ? false : true; 705 IO.Fonts = shared_font_atlas ? shared_font_atlas : IM_NEW(ImFontAtlas)(); 706 707 Time = 0.0f; 708 FrameCount = 0; 709 FrameCountEnded = FrameCountRendered = -1; 710 WindowsActiveCount = 0; 711 CurrentWindow = NULL; 712 HoveredWindow = NULL; 713 HoveredRootWindow = NULL; 714 HoveredId = 0; 715 HoveredIdAllowOverlap = false; 716 HoveredIdPreviousFrame = 0; 717 HoveredIdTimer = 0.0f; 718 ActiveId = 0; 719 ActiveIdPreviousFrame = 0; 720 ActiveIdTimer = 0.0f; 721 ActiveIdIsAlive = false; 722 ActiveIdIsJustActivated = false; 723 ActiveIdAllowOverlap = false; 724 ActiveIdAllowNavDirFlags = 0; 725 ActiveIdClickOffset = ImVec2(-1, -1); 726 ActiveIdWindow = NULL; 727 ActiveIdSource = ImGuiInputSource_None; 728 MovingWindow = NULL; 729 NextTreeNodeOpenVal = false; 730 NextTreeNodeOpenCond = 0; 731 732 NavWindow = NULL; 733 NavId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0; 734 NavJustTabbedId = NavJustMovedToId = NavNextActivateId = 0; 735 NavInputSource = ImGuiInputSource_None; 736 NavScoringRectScreen = ImRect(); 737 NavScoringCount = 0; 738 NavWindowingTarget = NULL; 739 NavWindowingHighlightTimer = NavWindowingHighlightAlpha = 0.0f; 740 NavWindowingToggleLayer = false; 741 NavLayer = 0; 742 NavIdTabCounter = INT_MAX; 743 NavIdIsAlive = false; 744 NavMousePosDirty = false; 745 NavDisableHighlight = true; 746 NavDisableMouseHover = false; 747 NavAnyRequest = false; 748 NavInitRequest = false; 749 NavInitRequestFromMove = false; 750 NavInitResultId = 0; 751 NavMoveFromClampedRefRect = false; 752 NavMoveRequest = false; 753 NavMoveRequestForward = ImGuiNavForward_None; 754 NavMoveDir = NavMoveDirLast = ImGuiDir_None; 755 756 ModalWindowDarkeningRatio = 0.0f; 757 OverlayDrawList._Data = &DrawListSharedData; 758 OverlayDrawList._OwnerName = "##Overlay"; // Give it a name for debugging 759 MouseCursor = ImGuiMouseCursor_Arrow; 760 761 DragDropActive = false; 762 DragDropSourceFlags = 0; 763 DragDropMouseButton = -1; 764 DragDropTargetId = 0; 765 DragDropAcceptIdCurrRectSurface = 0.0f; 766 DragDropAcceptIdPrev = DragDropAcceptIdCurr = 0; 767 DragDropAcceptFrameCount = -1; 768 memset(DragDropPayloadBufLocal, 0, sizeof(DragDropPayloadBufLocal)); 769 770 ScalarAsInputTextId = 0; 771 ColorEditOptions = ImGuiColorEditFlags__OptionsDefault; 772 DragCurrentValue = 0.0f; 773 DragLastMouseDelta = ImVec2(0.0f, 0.0f); 774 DragSpeedDefaultRatio = 1.0f / 100.0f; 775 DragSpeedScaleSlow = 1.0f / 100.0f; 776 DragSpeedScaleFast = 10.0f; 777 ScrollbarClickDeltaToGrabCenter = ImVec2(0.0f, 0.0f); 778 TooltipOverrideCount = 0; 779 PlatformImePos = PlatformImeLastPos = ImVec2(FLT_MAX, FLT_MAX); 780 781 SettingsLoaded = false; 782 SettingsDirtyTimer = 0.0f; 783 784 LogEnabled = false; 785 LogFile = NULL; 786 LogClipboard = NULL; 787 LogStartDepth = 0; 788 LogAutoExpandMaxDepth = 2; 789 790 memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame)); 791 FramerateSecPerFrameIdx = 0; 792 FramerateSecPerFrameAccum = 0.0f; 793 WantCaptureMouseNextFrame = WantCaptureKeyboardNextFrame = WantTextInputNextFrame = -1; 794 memset(TempBuffer, 0, sizeof(TempBuffer)); 795 } 796 }; 565 ImVector<ImDrawList*> Layers[2]; // Global layers for: regular, tooltip 566 567 void Clear() { for (int n = 0; n < IM_ARRAYSIZE(Layers); n++) Layers[n].resize(0); } 568 void ClearFreeMemory() { for (int n = 0; n < IM_ARRAYSIZE(Layers); n++) Layers[n].clear(); } 569 IMGUI_API void FlattenIntoSingleLayer(); 570 }; 571 572 //----------------------------------------------------------------------------- 573 // [SECTION] Widgets support: flags, enums, data structures 574 //----------------------------------------------------------------------------- 797 575 798 576 // Transient per-window flags, reset at the beginning of the frame. For child window, inherited from parent on first Begin(). … … 800 578 enum ImGuiItemFlags_ 801 579 { 802 ImGuiItemFlags_AllowKeyboardFocus = 1 << 0, // true 803 ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings. 804 ImGuiItemFlags_Disabled = 1 << 2, // false // FIXME-WIP: Disable interactions but doesn't affect visuals. Should be: grey out and disable interactions with widgets that affect data + view widgets (WIP) 805 ImGuiItemFlags_NoNav = 1 << 3, // false 806 ImGuiItemFlags_NoNavDefaultFocus = 1 << 4, // false 807 ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, // false // MenuItem/Selectable() automatically closes current Popup window 808 ImGuiItemFlags_Default_ = ImGuiItemFlags_AllowKeyboardFocus 809 }; 810 811 // Transient per-window data, reset at the beginning of the frame 812 // FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiDrawContext is quite tenuous and could be reconsidered. 813 struct IMGUI_API ImGuiDrawContext 814 { 815 ImVec2 CursorPos; 816 ImVec2 CursorPosPrevLine; 817 ImVec2 CursorStartPos; 818 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 819 float CurrentLineHeight; 820 float CurrentLineTextBaseOffset; 821 float PrevLineHeight; 822 float PrevLineTextBaseOffset; 823 float LogLinePosY; 824 int TreeDepth; 825 ImU32 TreeDepthMayJumpToParentOnPop; // Store a copy of !g.NavIdIsAlive for TreeDepth 0..31 826 ImGuiID LastItemId; 827 ImGuiItemStatusFlags LastItemStatusFlags; 828 ImRect LastItemRect; // Interaction rect 829 ImRect LastItemDisplayRect; // End-user display rect (only valid if LastItemStatusFlags & ImGuiItemStatusFlags_HasDisplayRect) 830 bool NavHideHighlightOneFrame; 831 bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f) 832 int NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1) 833 int NavLayerCurrentMask; // = (1 << NavLayerCurrent) used by ItemAdd prior to clipping. 834 int NavLayerActiveMask; // Which layer have been written to (result from previous frame) 835 int NavLayerActiveMaskNext; // Which layer have been written to (buffer for current frame) 836 bool MenuBarAppending; // FIXME: Remove this 837 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. 838 ImVector<ImGuiWindow*> ChildWindows; 839 ImGuiStorage* StateStorage; 840 ImGuiLayoutType LayoutType; 841 ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin() 842 843 // 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. 844 ImGuiItemFlags ItemFlags; // == ItemFlagsStack.back() [empty == ImGuiItemFlags_Default] 845 float ItemWidth; // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window 846 float TextWrapPos; // == TextWrapPosStack.back() [empty == -1.0f] 847 ImVector<ImGuiItemFlags>ItemFlagsStack; 848 ImVector<float> ItemWidthStack; 849 ImVector<float> TextWrapPosStack; 850 ImVector<ImGuiGroupData>GroupStack; 851 int StackSizesBackup[6]; // Store size of various stacks for asserting 852 853 float IndentX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.) 854 float GroupOffsetX; 855 float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API. 856 ImGuiColumnsSet* ColumnsSet; // Current columns set 857 858 ImGuiDrawContext() 859 { 860 CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f); 861 CurrentLineHeight = PrevLineHeight = 0.0f; 862 CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f; 863 LogLinePosY = -1.0f; 864 TreeDepth = 0; 865 TreeDepthMayJumpToParentOnPop = 0x00; 866 LastItemId = 0; 867 LastItemStatusFlags = 0; 868 LastItemRect = LastItemDisplayRect = ImRect(); 869 NavHideHighlightOneFrame = false; 870 NavHasScroll = false; 871 NavLayerActiveMask = NavLayerActiveMaskNext = 0x00; 872 NavLayerCurrent = 0; 873 NavLayerCurrentMask = 1 << 0; 874 MenuBarAppending = false; 875 MenuBarOffset = ImVec2(0.0f, 0.0f); 876 StateStorage = NULL; 877 LayoutType = ParentLayoutType = ImGuiLayoutType_Vertical; 878 ItemWidth = 0.0f; 879 ItemFlags = ImGuiItemFlags_Default_; 880 TextWrapPos = -1.0f; 881 memset(StackSizesBackup, 0, sizeof(StackSizesBackup)); 882 883 IndentX = 0.0f; 884 GroupOffsetX = 0.0f; 885 ColumnsOffsetX = 0.0f; 886 ColumnsSet = NULL; 887 } 888 }; 889 890 // Windows data 580 ImGuiItemFlags_None = 0, 581 ImGuiItemFlags_NoTabStop = 1 << 0, // false 582 ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings. 583 ImGuiItemFlags_Disabled = 1 << 2, // false // [BETA] Disable interactions but doesn't affect visuals yet. See github.com/ocornut/imgui/issues/211 584 ImGuiItemFlags_NoNav = 1 << 3, // false 585 ImGuiItemFlags_NoNavDefaultFocus = 1 << 4, // false 586 ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, // false // MenuItem/Selectable() automatically closes current Popup window 587 ImGuiItemFlags_MixedValue = 1 << 6, // false // [BETA] Represent a mixed/indeterminate value, generally multi-selection where values differ. Currently only supported by Checkbox() (later should support all sorts of widgets) 588 ImGuiItemFlags_ReadOnly = 1 << 7, // false // [ALPHA] Allow hovering interactions but underlying value is not changed. 589 ImGuiItemFlags_Default_ = 0 590 }; 591 592 // Storage for LastItem data 593 enum ImGuiItemStatusFlags_ 594 { 595 ImGuiItemStatusFlags_None = 0, 596 ImGuiItemStatusFlags_HoveredRect = 1 << 0, 597 ImGuiItemStatusFlags_HasDisplayRect = 1 << 1, 598 ImGuiItemStatusFlags_Edited = 1 << 2, // Value exposed by item was edited in the current frame (should match the bool return value of most widgets) 599 ImGuiItemStatusFlags_ToggledSelection = 1 << 3, // Set when Selectable(), TreeNode() reports toggling a selection. We can't report "Selected" because reporting the change allows us to handle clipping with less issues. 600 ImGuiItemStatusFlags_ToggledOpen = 1 << 4, // Set when TreeNode() reports toggling their open state. 601 ImGuiItemStatusFlags_HasDeactivated = 1 << 5, // Set if the widget/group is able to provide data for the ImGuiItemStatusFlags_Deactivated flag. 602 ImGuiItemStatusFlags_Deactivated = 1 << 6 // Only valid if ImGuiItemStatusFlags_HasDeactivated is set. 603 604 #ifdef IMGUI_ENABLE_TEST_ENGINE 605 , // [imgui_tests only] 606 ImGuiItemStatusFlags_Openable = 1 << 10, // 607 ImGuiItemStatusFlags_Opened = 1 << 11, // 608 ImGuiItemStatusFlags_Checkable = 1 << 12, // 609 ImGuiItemStatusFlags_Checked = 1 << 13 // 610 #endif 611 }; 612 613 // Extend ImGuiButtonFlags_ 614 enum ImGuiButtonFlagsPrivate_ 615 { 616 ImGuiButtonFlags_PressedOnClick = 1 << 4, // return true on click (mouse down event) 617 ImGuiButtonFlags_PressedOnClickRelease = 1 << 5, // [Default] return true on click + release on same item <-- this is what the majority of Button are using 618 ImGuiButtonFlags_PressedOnClickReleaseAnywhere = 1 << 6, // return true on click + release even if the release event is not done while hovering the item 619 ImGuiButtonFlags_PressedOnRelease = 1 << 7, // return true on release (default requires click+release) 620 ImGuiButtonFlags_PressedOnDoubleClick = 1 << 8, // return true on double-click (default requires click+release) 621 ImGuiButtonFlags_PressedOnDragDropHold = 1 << 9, // return true when held into while we are drag and dropping another item (used by e.g. tree nodes, collapsing headers) 622 ImGuiButtonFlags_Repeat = 1 << 10, // hold to repeat 623 ImGuiButtonFlags_FlattenChildren = 1 << 11, // allow interactions even if a child window is overlapping 624 ImGuiButtonFlags_AllowItemOverlap = 1 << 12, // require previous frame HoveredId to either match id or be null before being usable, use along with SetItemAllowOverlap() 625 ImGuiButtonFlags_DontClosePopups = 1 << 13, // disable automatically closing parent popup on press // [UNUSED] 626 ImGuiButtonFlags_Disabled = 1 << 14, // disable interactions 627 ImGuiButtonFlags_AlignTextBaseLine = 1 << 15, // vertically align button to match text baseline - ButtonEx() only // FIXME: Should be removed and handled by SmallButton(), not possible currently because of DC.CursorPosPrevLine 628 ImGuiButtonFlags_NoKeyModifiers = 1 << 16, // disable mouse interaction if a key modifier is held 629 ImGuiButtonFlags_NoHoldingActiveId = 1 << 17, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) 630 ImGuiButtonFlags_NoNavFocus = 1 << 18, // don't override navigation focus when activated 631 ImGuiButtonFlags_NoHoveredOnFocus = 1 << 19, // don't report as hovered when nav focus is on this item 632 ImGuiButtonFlags_PressedOnMask_ = ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_PressedOnDragDropHold, 633 ImGuiButtonFlags_PressedOnDefault_ = ImGuiButtonFlags_PressedOnClickRelease 634 }; 635 636 // Extend ImGuiSliderFlags_ 637 enum ImGuiSliderFlagsPrivate_ 638 { 639 ImGuiSliderFlags_Vertical = 1 << 20, // Should this slider be orientated vertically? 640 ImGuiSliderFlags_ReadOnly = 1 << 21 641 }; 642 643 // Extend ImGuiSelectableFlags_ 644 enum ImGuiSelectableFlagsPrivate_ 645 { 646 // NB: need to be in sync with last value of ImGuiSelectableFlags_ 647 ImGuiSelectableFlags_NoHoldingActiveID = 1 << 20, 648 ImGuiSelectableFlags_SelectOnClick = 1 << 21, // Override button behavior to react on Click (default is Click+Release) 649 ImGuiSelectableFlags_SelectOnRelease = 1 << 22, // Override button behavior to react on Release (default is Click+Release) 650 ImGuiSelectableFlags_SpanAvailWidth = 1 << 23, // Span all avail width even if we declared less for layout purpose. FIXME: We may be able to remove this (added in 6251d379, 2bcafc86 for menus) 651 ImGuiSelectableFlags_DrawHoveredWhenHeld = 1 << 24, // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow. 652 ImGuiSelectableFlags_SetNavIdOnHover = 1 << 25, // Set Nav/Focus ID on mouse hover (used by MenuItem) 653 ImGuiSelectableFlags_NoPadWithHalfSpacing = 1 << 26 // Disable padding each side with ItemSpacing * 0.5f 654 }; 655 656 // Extend ImGuiTreeNodeFlags_ 657 enum ImGuiTreeNodeFlagsPrivate_ 658 { 659 ImGuiTreeNodeFlags_ClipLabelForTrailingButton = 1 << 20 660 }; 661 662 enum ImGuiSeparatorFlags_ 663 { 664 ImGuiSeparatorFlags_None = 0, 665 ImGuiSeparatorFlags_Horizontal = 1 << 0, // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar 666 ImGuiSeparatorFlags_Vertical = 1 << 1, 667 ImGuiSeparatorFlags_SpanAllColumns = 1 << 2 668 }; 669 670 enum ImGuiTextFlags_ 671 { 672 ImGuiTextFlags_None = 0, 673 ImGuiTextFlags_NoWidthForLargeClippedText = 1 << 0 674 }; 675 676 enum ImGuiTooltipFlags_ 677 { 678 ImGuiTooltipFlags_None = 0, 679 ImGuiTooltipFlags_OverridePreviousTooltip = 1 << 0 // Override will clear/ignore previously submitted tooltip (defaults to append) 680 }; 681 682 // FIXME: this is in development, not exposed/functional as a generic feature yet. 683 // Horizontal/Vertical enums are fixed to 0/1 so they may be used to index ImVec2 684 enum ImGuiLayoutType_ 685 { 686 ImGuiLayoutType_Horizontal = 0, 687 ImGuiLayoutType_Vertical = 1 688 }; 689 690 enum ImGuiLogType 691 { 692 ImGuiLogType_None = 0, 693 ImGuiLogType_TTY, 694 ImGuiLogType_File, 695 ImGuiLogType_Buffer, 696 ImGuiLogType_Clipboard 697 }; 698 699 // X/Y enums are fixed to 0/1 so they may be used to index ImVec2 700 enum ImGuiAxis 701 { 702 ImGuiAxis_None = -1, 703 ImGuiAxis_X = 0, 704 ImGuiAxis_Y = 1 705 }; 706 707 enum ImGuiPlotType 708 { 709 ImGuiPlotType_Lines, 710 ImGuiPlotType_Histogram 711 }; 712 713 enum ImGuiInputSource 714 { 715 ImGuiInputSource_None = 0, 716 ImGuiInputSource_Mouse, 717 ImGuiInputSource_Nav, 718 ImGuiInputSource_NavKeyboard, // Only used occasionally for storage, not tested/handled by most code 719 ImGuiInputSource_NavGamepad, // " 720 ImGuiInputSource_COUNT 721 }; 722 723 // FIXME-NAV: Clarify/expose various repeat delay/rate 724 enum ImGuiInputReadMode 725 { 726 ImGuiInputReadMode_Down, 727 ImGuiInputReadMode_Pressed, 728 ImGuiInputReadMode_Released, 729 ImGuiInputReadMode_Repeat, 730 ImGuiInputReadMode_RepeatSlow, 731 ImGuiInputReadMode_RepeatFast 732 }; 733 734 enum ImGuiNavHighlightFlags_ 735 { 736 ImGuiNavHighlightFlags_None = 0, 737 ImGuiNavHighlightFlags_TypeDefault = 1 << 0, 738 ImGuiNavHighlightFlags_TypeThin = 1 << 1, 739 ImGuiNavHighlightFlags_AlwaysDraw = 1 << 2, // Draw rectangular highlight if (g.NavId == id) _even_ when using the mouse. 740 ImGuiNavHighlightFlags_NoRounding = 1 << 3 741 }; 742 743 enum ImGuiNavDirSourceFlags_ 744 { 745 ImGuiNavDirSourceFlags_None = 0, 746 ImGuiNavDirSourceFlags_Keyboard = 1 << 0, 747 ImGuiNavDirSourceFlags_PadDPad = 1 << 1, 748 ImGuiNavDirSourceFlags_PadLStick = 1 << 2 749 }; 750 751 enum ImGuiNavMoveFlags_ 752 { 753 ImGuiNavMoveFlags_None = 0, 754 ImGuiNavMoveFlags_LoopX = 1 << 0, // On failed request, restart from opposite side 755 ImGuiNavMoveFlags_LoopY = 1 << 1, 756 ImGuiNavMoveFlags_WrapX = 1 << 2, // On failed request, request from opposite side one line down (when NavDir==right) or one line up (when NavDir==left) 757 ImGuiNavMoveFlags_WrapY = 1 << 3, // This is not super useful for provided for completeness 758 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) 759 ImGuiNavMoveFlags_AlsoScoreVisibleSet = 1 << 5, // Store alternate result in NavMoveResultLocalVisibleSet that only comprise elements that are already fully visible. 760 ImGuiNavMoveFlags_ScrollToEdge = 1 << 6 761 }; 762 763 enum ImGuiNavForward 764 { 765 ImGuiNavForward_None, 766 ImGuiNavForward_ForwardQueued, 767 ImGuiNavForward_ForwardActive 768 }; 769 770 enum ImGuiNavLayer 771 { 772 ImGuiNavLayer_Main = 0, // Main scrolling layer 773 ImGuiNavLayer_Menu = 1, // Menu layer (access with Alt/ImGuiNavInput_Menu) 774 ImGuiNavLayer_COUNT 775 }; 776 777 enum ImGuiPopupPositionPolicy 778 { 779 ImGuiPopupPositionPolicy_Default, 780 ImGuiPopupPositionPolicy_ComboBox, 781 ImGuiPopupPositionPolicy_Tooltip 782 }; 783 784 struct ImGuiDataTypeTempStorage 785 { 786 ImU8 Data[8]; // Can fit any data up to ImGuiDataType_COUNT 787 }; 788 789 // Type information associated to one ImGuiDataType. Retrieve with DataTypeGetInfo(). 790 struct ImGuiDataTypeInfo 791 { 792 size_t Size; // Size in bytes 793 const char* Name; // Short descriptive name for the type, for debugging 794 const char* PrintFmt; // Default printf format for the type 795 const char* ScanFmt; // Default scanf format for the type 796 }; 797 798 // Extend ImGuiDataType_ 799 enum ImGuiDataTypePrivate_ 800 { 801 ImGuiDataType_String = ImGuiDataType_COUNT + 1, 802 ImGuiDataType_Pointer, 803 ImGuiDataType_ID 804 }; 805 806 // Stacked color modifier, backup of modified data so we can restore it 807 struct ImGuiColorMod 808 { 809 ImGuiCol Col; 810 ImVec4 BackupValue; 811 }; 812 813 // Stacked style modifier, backup of modified data so we can restore it. Data type inferred from the variable. 814 struct ImGuiStyleMod 815 { 816 ImGuiStyleVar VarIdx; 817 union { int BackupInt[2]; float BackupFloat[2]; }; 818 ImGuiStyleMod(ImGuiStyleVar idx, int v) { VarIdx = idx; BackupInt[0] = v; } 819 ImGuiStyleMod(ImGuiStyleVar idx, float v) { VarIdx = idx; BackupFloat[0] = v; } 820 ImGuiStyleMod(ImGuiStyleVar idx, ImVec2 v) { VarIdx = idx; BackupFloat[0] = v.x; BackupFloat[1] = v.y; } 821 }; 822 823 // Stacked storage data for BeginGroup()/EndGroup() 824 struct ImGuiGroupData 825 { 826 ImVec2 BackupCursorPos; 827 ImVec2 BackupCursorMaxPos; 828 ImVec1 BackupIndent; 829 ImVec1 BackupGroupOffset; 830 ImVec2 BackupCurrLineSize; 831 float BackupCurrLineTextBaseOffset; 832 ImGuiID BackupActiveIdIsAlive; 833 bool BackupActiveIdPreviousFrameIsAlive; 834 bool EmitItem; 835 }; 836 837 // Simple column measurement, currently used for MenuItem() only.. This is very short-sighted/throw-away code and NOT a generic helper. 838 struct IMGUI_API ImGuiMenuColumns 839 { 840 float Spacing; 841 float Width, NextWidth; 842 float Pos[3], NextWidths[3]; 843 844 ImGuiMenuColumns(); 845 void Update(int count, float spacing, bool clear); 846 float DeclColumns(float w0, float w1, float w2); 847 float CalcExtraSpace(float avail_w) const; 848 }; 849 850 // Internal state of the currently focused/edited text input box 851 // For a given item ID, access with ImGui::GetInputTextState() 852 struct IMGUI_API ImGuiInputTextState 853 { 854 ImGuiID ID; // widget id owning the text state 855 int CurLenW, CurLenA; // we need to maintain our buffer length in both UTF-8 and wchar format. UTF-8 length is valid even if TextA is not. 856 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. 857 ImVector<char> TextA; // temporary UTF8 buffer for callbacks and other operations. this is not updated in every code-path! size=capacity. 858 ImVector<char> InitialTextA; // backup of end-user buffer at the time of focus (in UTF-8, unaltered) 859 bool TextAIsValid; // temporary UTF8 buffer is not initially valid before we make the widget active (until then we pull the data from user argument) 860 int BufCapacityA; // end-user buffer capacity 861 float ScrollX; // horizontal scrolling/offset 862 ImStb::STB_TexteditState Stb; // state for stb_textedit.h 863 float CursorAnim; // timer for cursor blink, reset on every user action so the cursor reappears immediately 864 bool CursorFollow; // set when we want scrolling to follow the current cursor position (not always!) 865 bool SelectedAllMouseLock; // after a double-click to select all, we ignore further mouse drags to update selection 866 bool Edited; // edited this frame 867 ImGuiInputTextFlags UserFlags; // Temporarily set while we call user's callback 868 ImGuiInputTextCallback UserCallback; // " 869 void* UserCallbackData; // " 870 871 ImGuiInputTextState() { memset(this, 0, sizeof(*this)); } 872 void ClearText() { CurLenW = CurLenA = 0; TextW[0] = 0; TextA[0] = 0; CursorClamp(); } 873 void ClearFreeMemory() { TextW.clear(); TextA.clear(); InitialTextA.clear(); } 874 int GetUndoAvailCount() const { return Stb.undostate.undo_point; } 875 int GetRedoAvailCount() const { return STB_TEXTEDIT_UNDOSTATECOUNT - Stb.undostate.redo_point; } 876 void OnKeyPressed(int key); // Cannot be inline because we call in code in stb_textedit.h implementation 877 878 // Cursor & Selection 879 void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking 880 void CursorClamp() { Stb.cursor = ImMin(Stb.cursor, CurLenW); Stb.select_start = ImMin(Stb.select_start, CurLenW); Stb.select_end = ImMin(Stb.select_end, CurLenW); } 881 bool HasSelection() const { return Stb.select_start != Stb.select_end; } 882 void ClearSelection() { Stb.select_start = Stb.select_end = Stb.cursor; } 883 void SelectAll() { Stb.select_start = 0; Stb.cursor = Stb.select_end = CurLenW; Stb.has_preferred_x = 0; } 884 }; 885 886 // Storage for current popup stack 887 struct ImGuiPopupData 888 { 889 ImGuiID PopupId; // Set on OpenPopup() 890 ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup() 891 ImGuiWindow* SourceWindow; // Set on OpenPopup() copy of NavWindow at the time of opening the popup 892 int OpenFrameCount; // Set on OpenPopup() 893 ImGuiID OpenParentId; // Set on OpenPopup(), we need this to differentiate multiple menu sets from each others (e.g. inside menu bar vs loose menu items) 894 ImVec2 OpenPopupPos; // Set on OpenPopup(), preferred popup position (typically == OpenMousePos when using mouse) 895 ImVec2 OpenMousePos; // Set on OpenPopup(), copy of mouse position at the time of opening popup 896 897 ImGuiPopupData() { PopupId = 0; Window = SourceWindow = NULL; OpenFrameCount = -1; OpenParentId = 0; } 898 }; 899 900 struct ImGuiNavMoveResult 901 { 902 ImGuiWindow* Window; // Best candidate window 903 ImGuiID ID; // Best candidate ID 904 ImGuiID FocusScopeId; // Best candidate focus scope ID 905 float DistBox; // Best candidate box distance to current NavId 906 float DistCenter; // Best candidate center distance to current NavId 907 float DistAxial; 908 ImRect RectRel; // Best candidate bounding box in window relative space 909 910 ImGuiNavMoveResult() { Clear(); } 911 void Clear() { Window = NULL; ID = FocusScopeId = 0; DistBox = DistCenter = DistAxial = FLT_MAX; RectRel = ImRect(); } 912 }; 913 914 enum ImGuiNextWindowDataFlags_ 915 { 916 ImGuiNextWindowDataFlags_None = 0, 917 ImGuiNextWindowDataFlags_HasPos = 1 << 0, 918 ImGuiNextWindowDataFlags_HasSize = 1 << 1, 919 ImGuiNextWindowDataFlags_HasContentSize = 1 << 2, 920 ImGuiNextWindowDataFlags_HasCollapsed = 1 << 3, 921 ImGuiNextWindowDataFlags_HasSizeConstraint = 1 << 4, 922 ImGuiNextWindowDataFlags_HasFocus = 1 << 5, 923 ImGuiNextWindowDataFlags_HasBgAlpha = 1 << 6, 924 ImGuiNextWindowDataFlags_HasScroll = 1 << 7 925 }; 926 927 // Storage for SetNexWindow** functions 928 struct ImGuiNextWindowData 929 { 930 ImGuiNextWindowDataFlags Flags; 931 ImGuiCond PosCond; 932 ImGuiCond SizeCond; 933 ImGuiCond CollapsedCond; 934 ImVec2 PosVal; 935 ImVec2 PosPivotVal; 936 ImVec2 SizeVal; 937 ImVec2 ContentSizeVal; 938 ImVec2 ScrollVal; 939 bool CollapsedVal; 940 ImRect SizeConstraintRect; 941 ImGuiSizeCallback SizeCallback; 942 void* SizeCallbackUserData; 943 float BgAlphaVal; // Override background alpha 944 ImVec2 MenuBarOffsetMinVal; // *Always on* This is not exposed publicly, so we don't clear it. 945 946 ImGuiNextWindowData() { memset(this, 0, sizeof(*this)); } 947 inline void ClearFlags() { Flags = ImGuiNextWindowDataFlags_None; } 948 }; 949 950 enum ImGuiNextItemDataFlags_ 951 { 952 ImGuiNextItemDataFlags_None = 0, 953 ImGuiNextItemDataFlags_HasWidth = 1 << 0, 954 ImGuiNextItemDataFlags_HasOpen = 1 << 1 955 }; 956 957 struct ImGuiNextItemData 958 { 959 ImGuiNextItemDataFlags Flags; 960 float Width; // Set by SetNextItemWidth() 961 ImGuiID FocusScopeId; // Set by SetNextItemMultiSelectData() (!= 0 signify value has been set, so it's an alternate version of HasSelectionData, we don't use Flags for this because they are cleared too early. This is mostly used for debugging) 962 ImGuiCond OpenCond; 963 bool OpenVal; // Set by SetNextItemOpen() 964 965 ImGuiNextItemData() { memset(this, 0, sizeof(*this)); } 966 inline void ClearFlags() { Flags = ImGuiNextItemDataFlags_None; } // Also cleared manually by ItemAdd()! 967 }; 968 969 struct ImGuiShrinkWidthItem 970 { 971 int Index; 972 float Width; 973 }; 974 975 struct ImGuiPtrOrIndex 976 { 977 void* Ptr; // Either field can be set, not both. e.g. Dock node tab bars are loose while BeginTabBar() ones are in a pool. 978 int Index; // Usually index in a main pool. 979 980 ImGuiPtrOrIndex(void* ptr) { Ptr = ptr; Index = -1; } 981 ImGuiPtrOrIndex(int index) { Ptr = NULL; Index = index; } 982 }; 983 984 //----------------------------------------------------------------------------- 985 // [SECTION] Columns support 986 //----------------------------------------------------------------------------- 987 988 enum ImGuiColumnsFlags_ 989 { 990 // Default: 0 991 ImGuiColumnsFlags_None = 0, 992 ImGuiColumnsFlags_NoBorder = 1 << 0, // Disable column dividers 993 ImGuiColumnsFlags_NoResize = 1 << 1, // Disable resizing columns when clicking on the dividers 994 ImGuiColumnsFlags_NoPreserveWidths = 1 << 2, // Disable column width preservation when adjusting columns 995 ImGuiColumnsFlags_NoForceWithinWindow = 1 << 3, // Disable forcing columns to fit within window 996 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. 997 }; 998 999 struct ImGuiColumnData 1000 { 1001 float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right) 1002 float OffsetNormBeforeResize; 1003 ImGuiColumnsFlags Flags; // Not exposed 1004 ImRect ClipRect; 1005 1006 ImGuiColumnData() { OffsetNorm = OffsetNormBeforeResize = 0.0f; Flags = ImGuiColumnsFlags_None; } 1007 }; 1008 1009 struct ImGuiColumns 1010 { 1011 ImGuiID ID; 1012 ImGuiColumnsFlags Flags; 1013 bool IsFirstFrame; 1014 bool IsBeingResized; 1015 int Current; 1016 int Count; 1017 float OffMinX, OffMaxX; // Offsets from HostWorkRect.Min.x 1018 float LineMinY, LineMaxY; 1019 float HostCursorPosY; // Backup of CursorPos at the time of BeginColumns() 1020 float HostCursorMaxPosX; // Backup of CursorMaxPos at the time of BeginColumns() 1021 ImRect HostInitialClipRect; // Backup of ClipRect at the time of BeginColumns() 1022 ImRect HostBackupClipRect; // Backup of ClipRect during PushColumnsBackground()/PopColumnsBackground() 1023 ImRect HostBackupParentWorkRect;//Backup of WorkRect at the time of BeginColumns() 1024 ImVector<ImGuiColumnData> Columns; 1025 ImDrawListSplitter Splitter; 1026 1027 ImGuiColumns() { Clear(); } 1028 void Clear() 1029 { 1030 ID = 0; 1031 Flags = ImGuiColumnsFlags_None; 1032 IsFirstFrame = false; 1033 IsBeingResized = false; 1034 Current = 0; 1035 Count = 1; 1036 OffMinX = OffMaxX = 0.0f; 1037 LineMinY = LineMaxY = 0.0f; 1038 HostCursorPosY = 0.0f; 1039 HostCursorMaxPosX = 0.0f; 1040 Columns.clear(); 1041 } 1042 }; 1043 1044 //----------------------------------------------------------------------------- 1045 // [SECTION] Multi-select support 1046 //----------------------------------------------------------------------------- 1047 1048 #ifdef IMGUI_HAS_MULTI_SELECT 1049 // <this is filled in 'range_select' branch> 1050 #endif // #ifdef IMGUI_HAS_MULTI_SELECT 1051 1052 //----------------------------------------------------------------------------- 1053 // [SECTION] Docking support 1054 //----------------------------------------------------------------------------- 1055 1056 #ifdef IMGUI_HAS_DOCK 1057 // <this is filled in 'docking' branch> 1058 #endif // #ifdef IMGUI_HAS_DOCK 1059 1060 //----------------------------------------------------------------------------- 1061 // [SECTION] Viewport support 1062 //----------------------------------------------------------------------------- 1063 1064 #ifdef IMGUI_HAS_VIEWPORT 1065 // <this is filled in 'docking' branch> 1066 #endif // #ifdef IMGUI_HAS_VIEWPORT 1067 1068 //----------------------------------------------------------------------------- 1069 // [SECTION] Settings support 1070 //----------------------------------------------------------------------------- 1071 1072 // Windows data saved in imgui.ini file 1073 // Because we never destroy or rename ImGuiWindowSettings, we can store the names in a separate buffer easily. 1074 // (this is designed to be stored in a ImChunkStream buffer, with the variable-length Name following our structure) 1075 struct ImGuiWindowSettings 1076 { 1077 ImGuiID ID; 1078 ImVec2ih Pos; 1079 ImVec2ih Size; 1080 bool Collapsed; 1081 bool WantApply; // Set when loaded from .ini data (to enable merging/loading .ini data into an already running context) 1082 1083 ImGuiWindowSettings() { ID = 0; Pos = Size = ImVec2ih(0, 0); Collapsed = WantApply = false; } 1084 char* GetName() { return (char*)(this + 1); } 1085 }; 1086 1087 struct ImGuiSettingsHandler 1088 { 1089 const char* TypeName; // Short description stored in .ini file. Disallowed characters: '[' ']' 1090 ImGuiID TypeHash; // == ImHashStr(TypeName) 1091 void (*ClearAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler); // Clear all settings data 1092 void (*ReadInitFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler); // Read: Called before reading (in registration order) 1093 void* (*ReadOpenFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name); // Read: Called when entering into a new ini entry e.g. "[Window][Name]" 1094 void (*ReadLineFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line); // Read: Called for every line of text within an ini entry 1095 void (*ApplyAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler); // Read: Called after reading (in registration order) 1096 void (*WriteAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf); // Write: Output every entries into 'out_buf' 1097 void* UserData; 1098 1099 ImGuiSettingsHandler() { memset(this, 0, sizeof(*this)); } 1100 }; 1101 1102 //----------------------------------------------------------------------------- 1103 // [SECTION] ImGuiContext (main imgui context) 1104 //----------------------------------------------------------------------------- 1105 1106 struct ImGuiContext 1107 { 1108 bool Initialized; 1109 bool FontAtlasOwnedByContext; // IO.Fonts-> is owned by the ImGuiContext and will be destructed along with it. 1110 ImGuiIO IO; 1111 ImGuiStyle Style; 1112 ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back() 1113 float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize(). Text height for current window. 1114 float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Base text height. 1115 ImDrawListSharedData DrawListSharedData; 1116 double Time; 1117 int FrameCount; 1118 int FrameCountEnded; 1119 int FrameCountRendered; 1120 bool WithinFrameScope; // Set by NewFrame(), cleared by EndFrame() 1121 bool WithinFrameScopeWithImplicitWindow; // Set by NewFrame(), cleared by EndFrame() when the implicit debug window has been pushed 1122 bool WithinEndChild; // Set within EndChild() 1123 bool TestEngineHookItems; // Will call test engine hooks: ImGuiTestEngineHook_ItemAdd(), ImGuiTestEngineHook_ItemInfo(), ImGuiTestEngineHook_Log() 1124 ImGuiID TestEngineHookIdInfo; // Will call test engine hooks: ImGuiTestEngineHook_IdInfo() from GetID() 1125 void* TestEngine; // Test engine user data 1126 1127 // Windows state 1128 ImVector<ImGuiWindow*> Windows; // Windows, sorted in display order, back to front 1129 ImVector<ImGuiWindow*> WindowsFocusOrder; // Windows, sorted in focus order, back to front. (FIXME: We could only store root windows here! Need to sort out the Docking equivalent which is RootWindowDockStop and is unfortunately a little more dynamic) 1130 ImVector<ImGuiWindow*> WindowsTempSortBuffer; // Temporary buffer used in EndFrame() to reorder windows so parents are kept before their child 1131 ImVector<ImGuiWindow*> CurrentWindowStack; 1132 ImGuiStorage WindowsById; // Map window's ImGuiID to ImGuiWindow* 1133 int WindowsActiveCount; // Number of unique windows submitted by frame 1134 ImGuiWindow* CurrentWindow; // Window being drawn into 1135 ImGuiWindow* HoveredWindow; // Window the mouse is hovering. Will typically catch mouse inputs. 1136 ImGuiWindow* HoveredRootWindow; // == HoveredWindow ? HoveredWindow->RootWindow : NULL, merely a shortcut to avoid null test in some situation. 1137 ImGuiWindow* HoveredWindowUnderMovingWindow; // Hovered window ignoring MovingWindow. Only set if MovingWindow is set. 1138 ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actual window that is moved is generally MovingWindow->RootWindow. 1139 ImGuiWindow* WheelingWindow; // Track the window we started mouse-wheeling on. Until a timer elapse or mouse has moved, generally keep scrolling the same window even if during the course of scrolling the mouse ends up hovering a child window. 1140 ImVec2 WheelingWindowRefMousePos; 1141 float WheelingWindowTimer; 1142 1143 // Item/widgets state and tracking information 1144 ImGuiID HoveredId; // Hovered widget 1145 ImGuiID HoveredIdPreviousFrame; 1146 bool HoveredIdAllowOverlap; 1147 bool HoveredIdDisabled; // At least one widget passed the rect test, but has been discarded by disabled flag or popup inhibit. May be true even if HoveredId == 0. 1148 float HoveredIdTimer; // Measure contiguous hovering time 1149 float HoveredIdNotActiveTimer; // Measure contiguous hovering time where the item has not been active 1150 ImGuiID ActiveId; // Active widget 1151 ImGuiID ActiveIdIsAlive; // Active widget has been seen this frame (we can't use a bool as the ActiveId may change within the frame) 1152 float ActiveIdTimer; 1153 bool ActiveIdIsJustActivated; // Set at the time of activation for one frame 1154 bool ActiveIdAllowOverlap; // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always) 1155 bool ActiveIdNoClearOnFocusLoss; // Disable losing active id if the active id window gets unfocused. 1156 bool ActiveIdHasBeenPressedBefore; // 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. 1157 bool ActiveIdHasBeenEditedBefore; // Was the value associated to the widget Edited over the course of the Active state. 1158 bool ActiveIdHasBeenEditedThisFrame; 1159 ImU32 ActiveIdUsingNavDirMask; // Active widget will want to read those nav move requests (e.g. can activate a button and move away from it) 1160 ImU32 ActiveIdUsingNavInputMask; // Active widget will want to read those nav inputs. 1161 ImU64 ActiveIdUsingKeyInputMask; // Active widget will want to read those key inputs. When we grow the ImGuiKey enum we'll need to either to order the enum to make useful keys come first, either redesign this into e.g. a small array. 1162 ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) 1163 ImGuiWindow* ActiveIdWindow; 1164 ImGuiInputSource ActiveIdSource; // Activating with mouse or nav (gamepad/keyboard) 1165 int ActiveIdMouseButton; 1166 ImGuiID ActiveIdPreviousFrame; 1167 bool ActiveIdPreviousFrameIsAlive; 1168 bool ActiveIdPreviousFrameHasBeenEditedBefore; 1169 ImGuiWindow* ActiveIdPreviousFrameWindow; 1170 ImGuiID LastActiveId; // Store the last non-zero ActiveId, useful for animation. 1171 float LastActiveIdTimer; // Store the last non-zero ActiveId timer since the beginning of activation, useful for animation. 1172 1173 // Next window/item data 1174 ImGuiNextWindowData NextWindowData; // Storage for SetNextWindow** functions 1175 ImGuiNextItemData NextItemData; // Storage for SetNextItem** functions 1176 1177 // Shared stacks 1178 ImVector<ImGuiColorMod> ColorModifiers; // Stack for PushStyleColor()/PopStyleColor() 1179 ImVector<ImGuiStyleMod> StyleModifiers; // Stack for PushStyleVar()/PopStyleVar() 1180 ImVector<ImFont*> FontStack; // Stack for PushFont()/PopFont() 1181 ImVector<ImGuiPopupData>OpenPopupStack; // Which popups are open (persistent) 1182 ImVector<ImGuiPopupData>BeginPopupStack; // Which level of BeginPopup() we are in (reset every frame) 1183 1184 // Gamepad/keyboard Navigation 1185 ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusWindow' 1186 ImGuiID NavId; // Focused item for navigation 1187 ImGuiID NavFocusScopeId; // Identify a selection scope (selection code often wants to "clear other items" when landing on an item of the selection set) 1188 ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0, also set when calling ActivateItem() 1189 ImGuiID NavActivateDownId; // ~~ IsNavInputDown(ImGuiNavInput_Activate) ? NavId : 0 1190 ImGuiID NavActivatePressedId; // ~~ IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0 1191 ImGuiID NavInputId; // ~~ IsNavInputPressed(ImGuiNavInput_Input) ? NavId : 0 1192 ImGuiID NavJustTabbedId; // Just tabbed to this id. 1193 ImGuiID NavJustMovedToId; // Just navigated to this id (result of a successfully MoveRequest). 1194 ImGuiID NavJustMovedToFocusScopeId; // Just navigated to this focus scope id (result of a successfully MoveRequest). 1195 ImGuiKeyModFlags NavJustMovedToKeyMods; 1196 ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame. 1197 ImGuiInputSource NavInputSource; // Keyboard or Gamepad mode? THIS WILL ONLY BE None or NavGamepad or NavKeyboard. 1198 ImRect NavScoringRect; // Rectangle used for scoring, in screen space. Based of window->NavRectRel[], modified for directional navigation scoring. 1199 int NavScoringCount; // Metrics for debugging 1200 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. 1201 int NavIdTabCounter; // == NavWindow->DC.FocusIdxTabCounter at time of NavId processing 1202 bool NavIdIsAlive; // Nav widget has been seen this frame ~~ NavRectRel is valid 1203 bool NavMousePosDirty; // When set we will update mouse position if (io.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos) if set (NB: this not enabled by default) 1204 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) 1205 bool NavDisableMouseHover; // When user starts using gamepad/keyboard, we hide mouse hovering highlight until mouse is touched again. 1206 bool NavAnyRequest; // ~~ NavMoveRequest || NavInitRequest 1207 bool NavInitRequest; // Init request for appearing window to select first item 1208 bool NavInitRequestFromMove; 1209 ImGuiID NavInitResultId; // Init request result (first item of the window, or one for which SetItemDefaultFocus() was called) 1210 ImRect NavInitResultRectRel; // Init request result rectangle (relative to parent window) 1211 bool NavMoveRequest; // Move request for this frame 1212 ImGuiNavMoveFlags NavMoveRequestFlags; 1213 ImGuiNavForward NavMoveRequestForward; // None / ForwardQueued / ForwardActive (this is used to navigate sibling parent menus from a child menu) 1214 ImGuiKeyModFlags NavMoveRequestKeyMods; 1215 ImGuiDir NavMoveDir, NavMoveDirLast; // Direction of the move request (left/right/up/down), direction of the previous move request 1216 ImGuiDir NavMoveClipDir; // FIXME-NAV: Describe the purpose of this better. Might want to rename? 1217 ImGuiNavMoveResult NavMoveResultLocal; // Best move request candidate within NavWindow 1218 ImGuiNavMoveResult NavMoveResultLocalVisibleSet; // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag) 1219 ImGuiNavMoveResult NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag) 1220 ImGuiWindow* NavWrapRequestWindow; // Window which requested trying nav wrap-around. 1221 ImGuiNavMoveFlags NavWrapRequestFlags; // Wrap-around operation flags. 1222 1223 // Navigation: Windowing (CTRL+TAB for list, or Menu button + keys or directional pads to move/resize) 1224 ImGuiWindow* NavWindowingTarget; // Target window when doing CTRL+Tab (or Pad Menu + FocusPrev/Next), this window is temporarily displayed top-most! 1225 ImGuiWindow* NavWindowingTargetAnim; // Record of last valid NavWindowingTarget until DimBgRatio and NavWindowingHighlightAlpha becomes 0.0f, so the fade-out can stay on it. 1226 ImGuiWindow* NavWindowingListWindow; // Internal window actually listing the CTRL+Tab contents 1227 float NavWindowingTimer; 1228 float NavWindowingHighlightAlpha; 1229 bool NavWindowingToggleLayer; 1230 1231 // Legacy Focus/Tabbing system (older than Nav, active even if Nav is disabled, misnamed. FIXME-NAV: This needs a redesign!) 1232 ImGuiWindow* FocusRequestCurrWindow; // 1233 ImGuiWindow* FocusRequestNextWindow; // 1234 int FocusRequestCurrCounterRegular; // Any item being requested for focus, stored as an index (we on layout to be stable between the frame pressing TAB and the next frame, semi-ouch) 1235 int FocusRequestCurrCounterTabStop; // Tab item being requested for focus, stored as an index 1236 int FocusRequestNextCounterRegular; // Stored for next frame 1237 int FocusRequestNextCounterTabStop; // " 1238 bool FocusTabPressed; // 1239 1240 // Render 1241 ImDrawData DrawData; // Main ImDrawData instance to pass render information to the user 1242 ImDrawDataBuilder DrawDataBuilder; 1243 float DimBgRatio; // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list) 1244 ImDrawList BackgroundDrawList; // First draw list to be rendered. 1245 ImDrawList ForegroundDrawList; // Last draw list to be rendered. This is where we the render software mouse cursor (if io.MouseDrawCursor is set) and most debug overlays. 1246 ImGuiMouseCursor MouseCursor; 1247 1248 // Drag and Drop 1249 bool DragDropActive; 1250 bool DragDropWithinSource; // Set when within a BeginDragDropXXX/EndDragDropXXX block for a drag source. 1251 bool DragDropWithinTarget; // Set when within a BeginDragDropXXX/EndDragDropXXX block for a drag target. 1252 ImGuiDragDropFlags DragDropSourceFlags; 1253 int DragDropSourceFrameCount; 1254 int DragDropMouseButton; 1255 ImGuiPayload DragDropPayload; 1256 ImRect DragDropTargetRect; // Store rectangle of current target candidate (we favor small targets when overlapping) 1257 ImGuiID DragDropTargetId; 1258 ImGuiDragDropFlags DragDropAcceptFlags; 1259 float DragDropAcceptIdCurrRectSurface; // Target item surface (we resolve overlapping targets by prioritizing the smaller surface) 1260 ImGuiID DragDropAcceptIdCurr; // Target item id (set at the time of accepting the payload) 1261 ImGuiID DragDropAcceptIdPrev; // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets) 1262 int DragDropAcceptFrameCount; // Last time a target expressed a desire to accept the source 1263 ImGuiID DragDropHoldJustPressedId; // Set when holding a payload just made ButtonBehavior() return a press. 1264 ImVector<unsigned char> DragDropPayloadBufHeap; // We don't expose the ImVector<> directly, ImGuiPayload only holds pointer+size 1265 unsigned char DragDropPayloadBufLocal[16]; // Local buffer for small payloads 1266 1267 // Tab bars 1268 ImGuiTabBar* CurrentTabBar; 1269 ImPool<ImGuiTabBar> TabBars; 1270 ImVector<ImGuiPtrOrIndex> CurrentTabBarStack; 1271 ImVector<ImGuiShrinkWidthItem> ShrinkWidthBuffer; 1272 1273 // Widget state 1274 ImVec2 LastValidMousePos; 1275 ImGuiInputTextState InputTextState; 1276 ImFont InputTextPasswordFont; 1277 ImGuiID TempInputId; // Temporary text input when CTRL+clicking on a slider, etc. 1278 ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets 1279 float ColorEditLastHue; // Backup of last Hue associated to LastColor[3], so we can restore Hue in lossy RGB<>HSV round trips 1280 float ColorEditLastSat; // Backup of last Saturation associated to LastColor[3], so we can restore Saturation in lossy RGB<>HSV round trips 1281 float ColorEditLastColor[3]; 1282 ImVec4 ColorPickerRef; // Initial/reference color at the time of opening the color picker. 1283 float SliderCurrentAccum; // Accumulated slider delta when using navigation controls. 1284 bool SliderCurrentAccumDirty; // Has the accumulated slider delta changed since last time we tried to apply it? 1285 bool DragCurrentAccumDirty; 1286 float DragCurrentAccum; // Accumulator for dragging modification. Always high-precision, not rounded by end-user precision settings 1287 float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio 1288 float ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage? 1289 int TooltipOverrideCount; 1290 ImVector<char> ClipboardHandlerData; // If no custom clipboard handler is defined 1291 ImVector<ImGuiID> MenusIdSubmittedThisFrame; // A list of menu IDs that were rendered at least once 1292 1293 // Platform support 1294 ImVec2 PlatformImePos; // Cursor position request & last passed to the OS Input Method Editor 1295 ImVec2 PlatformImeLastPos; 1296 char PlatformLocaleDecimalPoint; // '.' or *localeconv()->decimal_point 1297 1298 // Settings 1299 bool SettingsLoaded; 1300 float SettingsDirtyTimer; // Save .ini Settings to memory when time reaches zero 1301 ImGuiTextBuffer SettingsIniData; // In memory .ini settings 1302 ImVector<ImGuiSettingsHandler> SettingsHandlers; // List of .ini settings handlers 1303 ImChunkStream<ImGuiWindowSettings> SettingsWindows; // ImGuiWindow .ini settings entries 1304 1305 // Capture/Logging 1306 bool LogEnabled; // Currently capturing 1307 ImGuiLogType LogType; // Capture target 1308 ImFileHandle LogFile; // If != NULL log to stdout/ file 1309 ImGuiTextBuffer LogBuffer; // Accumulation buffer when log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators. 1310 float LogLinePosY; 1311 bool LogLineFirstItem; 1312 int LogDepthRef; 1313 int LogDepthToExpand; 1314 int LogDepthToExpandDefault; // Default/stored value for LogDepthMaxExpand if not specified in the LogXXX function call. 1315 1316 // Debug Tools 1317 bool DebugItemPickerActive; // Item picker is active (started with DebugStartItemPicker()) 1318 ImGuiID DebugItemPickerBreakId; // Will call IM_DEBUG_BREAK() when encountering this id 1319 1320 // Misc 1321 float FramerateSecPerFrame[120]; // Calculate estimate of framerate for user over the last 2 seconds. 1322 int FramerateSecPerFrameIdx; 1323 float FramerateSecPerFrameAccum; 1324 int WantCaptureMouseNextFrame; // Explicit capture via CaptureKeyboardFromApp()/CaptureMouseFromApp() sets those flags 1325 int WantCaptureKeyboardNextFrame; 1326 int WantTextInputNextFrame; 1327 char TempBuffer[1024 * 3 + 1]; // Temporary text buffer 1328 1329 ImGuiContext(ImFontAtlas* shared_font_atlas) : BackgroundDrawList(&DrawListSharedData), ForegroundDrawList(&DrawListSharedData) 1330 { 1331 Initialized = false; 1332 FontAtlasOwnedByContext = shared_font_atlas ? false : true; 1333 Font = NULL; 1334 FontSize = FontBaseSize = 0.0f; 1335 IO.Fonts = shared_font_atlas ? shared_font_atlas : IM_NEW(ImFontAtlas)(); 1336 Time = 0.0f; 1337 FrameCount = 0; 1338 FrameCountEnded = FrameCountRendered = -1; 1339 WithinFrameScope = WithinFrameScopeWithImplicitWindow = WithinEndChild = false; 1340 TestEngineHookItems = false; 1341 TestEngineHookIdInfo = 0; 1342 TestEngine = NULL; 1343 1344 WindowsActiveCount = 0; 1345 CurrentWindow = NULL; 1346 HoveredWindow = NULL; 1347 HoveredRootWindow = NULL; 1348 HoveredWindowUnderMovingWindow = NULL; 1349 MovingWindow = NULL; 1350 WheelingWindow = NULL; 1351 WheelingWindowTimer = 0.0f; 1352 1353 HoveredId = HoveredIdPreviousFrame = 0; 1354 HoveredIdAllowOverlap = false; 1355 HoveredIdDisabled = false; 1356 HoveredIdTimer = HoveredIdNotActiveTimer = 0.0f; 1357 ActiveId = 0; 1358 ActiveIdIsAlive = 0; 1359 ActiveIdTimer = 0.0f; 1360 ActiveIdIsJustActivated = false; 1361 ActiveIdAllowOverlap = false; 1362 ActiveIdNoClearOnFocusLoss = false; 1363 ActiveIdHasBeenPressedBefore = false; 1364 ActiveIdHasBeenEditedBefore = false; 1365 ActiveIdHasBeenEditedThisFrame = false; 1366 ActiveIdUsingNavDirMask = 0x00; 1367 ActiveIdUsingNavInputMask = 0x00; 1368 ActiveIdUsingKeyInputMask = 0x00; 1369 ActiveIdClickOffset = ImVec2(-1, -1); 1370 ActiveIdWindow = NULL; 1371 ActiveIdSource = ImGuiInputSource_None; 1372 ActiveIdMouseButton = 0; 1373 ActiveIdPreviousFrame = 0; 1374 ActiveIdPreviousFrameIsAlive = false; 1375 ActiveIdPreviousFrameHasBeenEditedBefore = false; 1376 ActiveIdPreviousFrameWindow = NULL; 1377 LastActiveId = 0; 1378 LastActiveIdTimer = 0.0f; 1379 1380 NavWindow = NULL; 1381 NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0; 1382 NavJustTabbedId = NavJustMovedToId = NavJustMovedToFocusScopeId = NavNextActivateId = 0; 1383 NavJustMovedToKeyMods = ImGuiKeyModFlags_None; 1384 NavInputSource = ImGuiInputSource_None; 1385 NavScoringRect = ImRect(); 1386 NavScoringCount = 0; 1387 NavLayer = ImGuiNavLayer_Main; 1388 NavIdTabCounter = INT_MAX; 1389 NavIdIsAlive = false; 1390 NavMousePosDirty = false; 1391 NavDisableHighlight = true; 1392 NavDisableMouseHover = false; 1393 NavAnyRequest = false; 1394 NavInitRequest = false; 1395 NavInitRequestFromMove = false; 1396 NavInitResultId = 0; 1397 NavMoveRequest = false; 1398 NavMoveRequestFlags = ImGuiNavMoveFlags_None; 1399 NavMoveRequestForward = ImGuiNavForward_None; 1400 NavMoveRequestKeyMods = ImGuiKeyModFlags_None; 1401 NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None; 1402 NavWrapRequestWindow = NULL; 1403 NavWrapRequestFlags = ImGuiNavMoveFlags_None; 1404 1405 NavWindowingTarget = NavWindowingTargetAnim = NavWindowingListWindow = NULL; 1406 NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f; 1407 NavWindowingToggleLayer = false; 1408 1409 FocusRequestCurrWindow = FocusRequestNextWindow = NULL; 1410 FocusRequestCurrCounterRegular = FocusRequestCurrCounterTabStop = INT_MAX; 1411 FocusRequestNextCounterRegular = FocusRequestNextCounterTabStop = INT_MAX; 1412 FocusTabPressed = false; 1413 1414 DimBgRatio = 0.0f; 1415 BackgroundDrawList._OwnerName = "##Background"; // Give it a name for debugging 1416 ForegroundDrawList._OwnerName = "##Foreground"; // Give it a name for debugging 1417 MouseCursor = ImGuiMouseCursor_Arrow; 1418 1419 DragDropActive = DragDropWithinSource = DragDropWithinTarget = false; 1420 DragDropSourceFlags = ImGuiDragDropFlags_None; 1421 DragDropSourceFrameCount = -1; 1422 DragDropMouseButton = -1; 1423 DragDropTargetId = 0; 1424 DragDropAcceptFlags = ImGuiDragDropFlags_None; 1425 DragDropAcceptIdCurrRectSurface = 0.0f; 1426 DragDropAcceptIdPrev = DragDropAcceptIdCurr = 0; 1427 DragDropAcceptFrameCount = -1; 1428 DragDropHoldJustPressedId = 0; 1429 memset(DragDropPayloadBufLocal, 0, sizeof(DragDropPayloadBufLocal)); 1430 1431 CurrentTabBar = NULL; 1432 1433 LastValidMousePos = ImVec2(0.0f, 0.0f); 1434 TempInputId = 0; 1435 ColorEditOptions = ImGuiColorEditFlags__OptionsDefault; 1436 ColorEditLastHue = ColorEditLastSat = 0.0f; 1437 ColorEditLastColor[0] = ColorEditLastColor[1] = ColorEditLastColor[2] = FLT_MAX; 1438 SliderCurrentAccum = 0.0f; 1439 SliderCurrentAccumDirty = false; 1440 DragCurrentAccumDirty = false; 1441 DragCurrentAccum = 0.0f; 1442 DragSpeedDefaultRatio = 1.0f / 100.0f; 1443 ScrollbarClickDeltaToGrabCenter = 0.0f; 1444 TooltipOverrideCount = 0; 1445 1446 PlatformImePos = PlatformImeLastPos = ImVec2(FLT_MAX, FLT_MAX); 1447 PlatformLocaleDecimalPoint = '.'; 1448 1449 SettingsLoaded = false; 1450 SettingsDirtyTimer = 0.0f; 1451 1452 LogEnabled = false; 1453 LogType = ImGuiLogType_None; 1454 LogFile = NULL; 1455 LogLinePosY = FLT_MAX; 1456 LogLineFirstItem = false; 1457 LogDepthRef = 0; 1458 LogDepthToExpand = LogDepthToExpandDefault = 2; 1459 1460 DebugItemPickerActive = false; 1461 DebugItemPickerBreakId = 0; 1462 1463 memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame)); 1464 FramerateSecPerFrameIdx = 0; 1465 FramerateSecPerFrameAccum = 0.0f; 1466 WantCaptureMouseNextFrame = WantCaptureKeyboardNextFrame = WantTextInputNextFrame = -1; 1467 memset(TempBuffer, 0, sizeof(TempBuffer)); 1468 } 1469 }; 1470 1471 //----------------------------------------------------------------------------- 1472 // [SECTION] ImGuiWindowTempData, ImGuiWindow 1473 //----------------------------------------------------------------------------- 1474 1475 // Transient per-window data, reset at the beginning of the frame. This used to be called ImGuiDrawContext, hence the DC variable name in ImGuiWindow. 1476 // FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiWindowTempData is quite tenuous and could be reconsidered. 1477 struct IMGUI_API ImGuiWindowTempData 1478 { 1479 // Layout 1480 ImVec2 CursorPos; // Current emitting position, in absolute coordinates. 1481 ImVec2 CursorPosPrevLine; 1482 ImVec2 CursorStartPos; // Initial position after Begin(), generally ~ window position + WindowPadding. 1483 ImVec2 CursorMaxPos; // Used to implicitly calculate the size of our contents, always growing during the frame. Used to calculate window->ContentSize at the beginning of next frame 1484 ImVec2 CurrLineSize; 1485 ImVec2 PrevLineSize; 1486 float CurrLineTextBaseOffset; // Baseline offset (0.0f by default on a new line, generally == style.FramePadding.y when a framed item has been added). 1487 float PrevLineTextBaseOffset; 1488 ImVec1 Indent; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.) 1489 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. 1490 ImVec1 GroupOffset; 1491 1492 // Last item status 1493 ImGuiID LastItemId; // ID for last item 1494 ImGuiItemStatusFlags LastItemStatusFlags; // Status flags for last item (see ImGuiItemStatusFlags_) 1495 ImRect LastItemRect; // Interaction rect for last item 1496 ImRect LastItemDisplayRect; // End-user display rect for last item (only valid if LastItemStatusFlags & ImGuiItemStatusFlags_HasDisplayRect) 1497 1498 // Keyboard/Gamepad navigation 1499 ImGuiNavLayer NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1) 1500 int NavLayerActiveMask; // Which layers have been written to (result from previous frame) 1501 int NavLayerActiveMaskNext; // Which layers have been written to (accumulator for current frame) 1502 ImGuiID NavFocusScopeIdCurrent; // Current focus scope ID while appending 1503 bool NavHideHighlightOneFrame; 1504 bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f) 1505 1506 // Miscellaneous 1507 bool MenuBarAppending; // FIXME: Remove this 1508 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. 1509 ImGuiMenuColumns MenuColumns; // Simplified columns storage for menu items measurement 1510 int TreeDepth; // Current tree depth. 1511 ImU32 TreeJumpToParentOnPopMask; // Store a copy of !g.NavIdIsAlive for TreeDepth 0..31.. Could be turned into a ImU64 if necessary. 1512 ImVector<ImGuiWindow*> ChildWindows; 1513 ImGuiStorage* StateStorage; // Current persistent per-window storage (store e.g. tree node open/close state) 1514 ImGuiColumns* CurrentColumns; // Current columns set 1515 ImGuiLayoutType LayoutType; 1516 ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin() 1517 int FocusCounterRegular; // (Legacy Focus/Tabbing system) Sequential counter, start at -1 and increase as assigned via FocusableItemRegister() (FIXME-NAV: Needs redesign) 1518 int FocusCounterTabStop; // (Legacy Focus/Tabbing system) Same, but only count widgets which you can Tab through. 1519 1520 // Local parameters stacks 1521 // 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. 1522 ImGuiItemFlags ItemFlags; // == ItemFlagsStack.back() [empty == ImGuiItemFlags_Default] 1523 float ItemWidth; // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window 1524 float TextWrapPos; // == TextWrapPosStack.back() [empty == -1.0f] 1525 ImVector<ImGuiItemFlags>ItemFlagsStack; 1526 ImVector<float> ItemWidthStack; 1527 ImVector<float> TextWrapPosStack; 1528 ImVector<ImGuiGroupData>GroupStack; 1529 short StackSizesBackup[6]; // Store size of various stacks for asserting 1530 1531 ImGuiWindowTempData() 1532 { 1533 CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f); 1534 CurrLineSize = PrevLineSize = ImVec2(0.0f, 0.0f); 1535 CurrLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f; 1536 Indent = ImVec1(0.0f); 1537 ColumnsOffset = ImVec1(0.0f); 1538 GroupOffset = ImVec1(0.0f); 1539 1540 LastItemId = 0; 1541 LastItemStatusFlags = ImGuiItemStatusFlags_None; 1542 LastItemRect = LastItemDisplayRect = ImRect(); 1543 1544 NavLayerActiveMask = NavLayerActiveMaskNext = 0x00; 1545 NavLayerCurrent = ImGuiNavLayer_Main; 1546 NavFocusScopeIdCurrent = 0; 1547 NavHideHighlightOneFrame = false; 1548 NavHasScroll = false; 1549 1550 MenuBarAppending = false; 1551 MenuBarOffset = ImVec2(0.0f, 0.0f); 1552 TreeDepth = 0; 1553 TreeJumpToParentOnPopMask = 0x00; 1554 StateStorage = NULL; 1555 CurrentColumns = NULL; 1556 LayoutType = ParentLayoutType = ImGuiLayoutType_Vertical; 1557 FocusCounterRegular = FocusCounterTabStop = -1; 1558 1559 ItemFlags = ImGuiItemFlags_Default_; 1560 ItemWidth = 0.0f; 1561 TextWrapPos = -1.0f; 1562 memset(StackSizesBackup, 0, sizeof(StackSizesBackup)); 1563 } 1564 }; 1565 1566 // Storage for one window 891 1567 struct IMGUI_API ImGuiWindow 892 1568 { 893 char* Name; 894 ImGuiID ID; // == ImHash(Name) 895 ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_ 896 ImVec2 Pos; // Position (always rounded-up to nearest pixel) 897 ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) 898 ImVec2 SizeFull; // Size when non collapsed 899 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. 900 ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame. Include decoration, window title, border, menu, etc. 901 ImVec2 SizeContentsExplicit; // Size of contents explicitly set by the user via SetNextWindowContentSize() 902 ImRect ContentsRegionRect; // Maximum visible content position in window coordinates. ~~ (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis 903 ImVec2 WindowPadding; // Window padding at the time of begin. 904 float WindowRounding; // Window rounding at the time of begin. 905 float WindowBorderSize; // Window border size at the time of begin. 906 ImGuiID MoveId; // == window->GetID("#MOVE") 907 ImGuiID ChildId; // Id of corresponding item in parent window (for child windows) 908 ImVec2 Scroll; 909 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) 910 ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered 911 ImVec2 ScrollbarSizes; 912 bool ScrollbarX, ScrollbarY; 913 bool Active; // Set to true on Begin(), unless Collapsed 914 bool WasActive; 915 bool WriteAccessed; // Set to true when any widget access the current window 916 bool Collapsed; // Set when collapsing window to become only title-bar 917 bool CollapseToggleWanted; 918 bool SkipItems; // Set when items can safely be all clipped (e.g. window not visible or collapsed) 919 bool Appearing; // Set during the frame where the window is appearing (or re-appearing) 920 bool CloseButton; // Set when the window has a close button (p_open != NULL) 921 int BeginOrderWithinParent; // Order within immediate parent window, if we are a child window. Otherwise 0. 922 int BeginOrderWithinContext; // Order within entire imgui context. This is mostly used for debugging submission order related issues. 923 int BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs) 924 ImGuiID PopupId; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling) 925 int AutoFitFramesX, AutoFitFramesY; 926 bool AutoFitOnlyGrows; 927 int AutoFitChildAxises; 928 ImGuiDir AutoPosLastDirection; 929 int HiddenFrames; 930 ImGuiCond SetWindowPosAllowFlags; // store acceptable condition flags for SetNextWindowPos() use. 931 ImGuiCond SetWindowSizeAllowFlags; // store acceptable condition flags for SetNextWindowSize() use. 932 ImGuiCond SetWindowCollapsedAllowFlags; // store acceptable condition flags for SetNextWindowCollapsed() use. 933 ImVec2 SetWindowPosVal; // store window position when using a non-zero Pivot (position set needs to be processed when we know the window size) 934 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. 935 936 ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame 937 ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack 938 ImRect ClipRect; // = DrawList->clip_rect_stack.back(). Scissoring / clipping rectangle. x1, y1, x2, y2. 939 ImRect WindowRectClipped; // = WindowRect just after setup in Begin(). == window->Rect() for root window. 940 ImRect InnerRect, InnerClipRect; 941 int LastFrameActive; 942 float ItemWidthDefault; 943 ImGuiMenuColumns MenuColumns; // Simplified columns storage for menu items 944 ImGuiStorage StateStorage; 945 ImVector<ImGuiColumnsSet> ColumnsStorage; 946 float FontWindowScale; // User scale multiplier per-window 947 948 ImDrawList* DrawList; // == &DrawListInst (for backward compatibility reason with code using imgui_internal.h we keep this a pointer) 949 ImDrawList DrawListInst; 950 ImGuiWindow* ParentWindow; // If we are a child _or_ popup window, this is pointing to our parent. Otherwise NULL. 951 ImGuiWindow* RootWindow; // Point to ourself or first ancestor that is not a child window. 952 ImGuiWindow* RootWindowForTitleBarHighlight; // Point to ourself or first ancestor which will display TitleBgActive color when this window is active. 953 ImGuiWindow* RootWindowForTabbing; // Point to ourself or first ancestor which can be CTRL-Tabbed into. 954 ImGuiWindow* RootWindowForNav; // Point to ourself or first ancestor which doesn't have the NavFlattened flag. 955 956 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.) 957 ImGuiID NavLastIds[2]; // Last known NavId for this window, per layer (0/1) 958 ImRect NavRectRel[2]; // Reference rectangle, in window relative space 959 960 // Navigation / Focus 961 // FIXME-NAV: Merge all this with the new Nav system, at least the request variables should be moved to ImGuiContext 962 int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister() 963 int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through) 964 int FocusIdxAllRequestCurrent; // Item being requested for focus 965 int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus 966 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) 967 int FocusIdxTabRequestNext; // " 1569 char* Name; // Window name, owned by the window. 1570 ImGuiID ID; // == ImHashStr(Name) 1571 ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_ 1572 ImVec2 Pos; // Position (always rounded-up to nearest pixel) 1573 ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) 1574 ImVec2 SizeFull; // Size when non collapsed 1575 ImVec2 ContentSize; // Size of contents/scrollable client area (calculated from the extents reach of the cursor) from previous frame. Does not include window decoration or window padding. 1576 ImVec2 ContentSizeExplicit; // Size of contents/scrollable client area explicitly request by the user via SetNextWindowContentSize(). 1577 ImVec2 WindowPadding; // Window padding at the time of Begin(). 1578 float WindowRounding; // Window rounding at the time of Begin(). May be clamped lower to avoid rendering artifacts with title bar, menu bar etc. 1579 float WindowBorderSize; // Window border size at the time of Begin(). 1580 int NameBufLen; // Size of buffer storing Name. May be larger than strlen(Name)! 1581 ImGuiID MoveId; // == window->GetID("#MOVE") 1582 ImGuiID ChildId; // ID of corresponding item in parent window (for navigation to return from child window to parent window) 1583 ImVec2 Scroll; 1584 ImVec2 ScrollMax; 1585 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) 1586 ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered 1587 ImVec2 ScrollTargetEdgeSnapDist; // 0.0f = no snapping, >0.0f snapping threshold 1588 ImVec2 ScrollbarSizes; // Size taken by each scrollbars on their smaller axis. Pay attention! ScrollbarSizes.x == width of the vertical scrollbar, ScrollbarSizes.y = height of the horizontal scrollbar. 1589 bool ScrollbarX, ScrollbarY; // Are scrollbars visible? 1590 bool Active; // Set to true on Begin(), unless Collapsed 1591 bool WasActive; 1592 bool WriteAccessed; // Set to true when any widget access the current window 1593 bool Collapsed; // Set when collapsing window to become only title-bar 1594 bool WantCollapseToggle; 1595 bool SkipItems; // Set when items can safely be all clipped (e.g. window not visible or collapsed) 1596 bool Appearing; // Set during the frame where the window is appearing (or re-appearing) 1597 bool Hidden; // Do not display (== HiddenFrames*** > 0) 1598 bool IsFallbackWindow; // Set on the "Debug##Default" window. 1599 bool HasCloseButton; // Set when the window has a close button (p_open != NULL) 1600 signed char ResizeBorderHeld; // Current border being held for resize (-1: none, otherwise 0-3) 1601 short BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs) 1602 short BeginOrderWithinParent; // Order within immediate parent window, if we are a child window. Otherwise 0. 1603 short BeginOrderWithinContext; // Order within entire imgui context. This is mostly used for debugging submission order related issues. 1604 ImGuiID PopupId; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling) 1605 ImS8 AutoFitFramesX, AutoFitFramesY; 1606 ImS8 AutoFitChildAxises; 1607 bool AutoFitOnlyGrows; 1608 ImGuiDir AutoPosLastDirection; 1609 int HiddenFramesCanSkipItems; // Hide the window for N frames 1610 int HiddenFramesCannotSkipItems; // Hide the window for N frames while allowing items to be submitted so we can measure their size 1611 ImGuiCond SetWindowPosAllowFlags; // store acceptable condition flags for SetNextWindowPos() use. 1612 ImGuiCond SetWindowSizeAllowFlags; // store acceptable condition flags for SetNextWindowSize() use. 1613 ImGuiCond SetWindowCollapsedAllowFlags; // store acceptable condition flags for SetNextWindowCollapsed() use. 1614 ImVec2 SetWindowPosVal; // store window position when using a non-zero Pivot (position set needs to be processed when we know the window size) 1615 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. 1616 1617 ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack. (In theory this should be in the TempData structure) 1618 ImGuiWindowTempData DC; // Temporary per-window data, reset at the beginning of the frame. This used to be called ImGuiDrawContext, hence the "DC" variable name. 1619 1620 // The best way to understand what those rectangles are is to use the 'Metrics -> Tools -> Show windows rectangles' viewer. 1621 // The main 'OuterRect', omitted as a field, is window->Rect(). 1622 ImRect OuterRectClipped; // == Window->Rect() just after setup in Begin(). == window->Rect() for root window. 1623 ImRect InnerRect; // Inner rectangle (omit title bar, menu bar, scroll bar) 1624 ImRect InnerClipRect; // == InnerRect shrunk by WindowPadding*0.5f on each side, clipped within viewport or parent clip rect. 1625 ImRect WorkRect; // Initially covers the whole scrolling region. Reduced by containers e.g columns/tables when active. Shrunk by WindowPadding*1.0f on each side. This is meant to replace ContentRegionRect over time (from 1.71+ onward). 1626 ImRect ParentWorkRect; // Backup of WorkRect before entering a container such as columns/tables. Used by e.g. SpanAllColumns functions to easily access. Stacked containers are responsible for maintaining this. // FIXME-WORKRECT: Could be a stack? 1627 ImRect ClipRect; // Current clipping/scissoring rectangle, evolve as we are using PushClipRect(), etc. == DrawList->clip_rect_stack.back(). 1628 ImRect ContentRegionRect; // FIXME: This is currently confusing/misleading. It is essentially WorkRect but not handling of scrolling. We currently rely on it as right/bottom aligned sizing operation need some size to rely on. 1629 ImVec2ih HitTestHoleSize; // Define an optional rectangular hole where mouse will pass-through the window. 1630 ImVec2ih HitTestHoleOffset; 1631 1632 int LastFrameActive; // Last frame number the window was Active. 1633 float LastTimeActive; // Last timestamp the window was Active (using float as we don't need high precision there) 1634 float ItemWidthDefault; 1635 ImGuiStorage StateStorage; 1636 ImVector<ImGuiColumns> ColumnsStorage; 1637 float FontWindowScale; // User scale multiplier per-window, via SetWindowFontScale() 1638 int SettingsOffset; // Offset into SettingsWindows[] (offsets are always valid as we only grow the array from the back) 1639 1640 ImDrawList* DrawList; // == &DrawListInst (for backward compatibility reason with code using imgui_internal.h we keep this a pointer) 1641 ImDrawList DrawListInst; 1642 ImGuiWindow* ParentWindow; // If we are a child _or_ popup window, this is pointing to our parent. Otherwise NULL. 1643 ImGuiWindow* RootWindow; // Point to ourself or first ancestor that is not a child window == Top-level window. 1644 ImGuiWindow* RootWindowForTitleBarHighlight; // Point to ourself or first ancestor which will display TitleBgActive color when this window is active. 1645 ImGuiWindow* RootWindowForNav; // Point to ourself or first ancestor which doesn't have the NavFlattened flag. 1646 1647 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.) 1648 ImGuiID NavLastIds[ImGuiNavLayer_COUNT]; // Last known NavId for this window, per layer (0/1) 1649 ImRect NavRectRel[ImGuiNavLayer_COUNT]; // Reference rectangle, in window relative space 1650 1651 bool MemoryCompacted; // Set when window extraneous data have been garbage collected 1652 int MemoryDrawListIdxCapacity; // Backup of last idx/vtx count, so when waking up the window we can preallocate and avoid iterative alloc/copy 1653 int MemoryDrawListVtxCapacity; 968 1654 969 1655 public: 970 ImGuiWindow(ImGuiContext* context, const char* name); 971 ~ImGuiWindow(); 972 973 ImGuiID GetID(const char* str, const char* str_end = NULL); 974 ImGuiID GetID(const void* ptr); 975 ImGuiID GetIDNoKeepAlive(const char* str, const char* str_end = NULL); 976 ImGuiID GetIDFromRectangle(const ImRect& r_abs); 977 978 // We don't use g.FontSize because the window may be != g.CurrentWidow. 979 ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); } 980 float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; } 981 float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; } 982 ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); } 983 float MenuBarHeight() const { return (Flags & ImGuiWindowFlags_MenuBar) ? DC.MenuBarOffset.y + CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f : 0.0f; } 984 ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); } 985 }; 986 987 // 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. 988 struct ImGuiItemHoveredDataBackup 989 { 990 ImGuiID LastItemId; 991 ImGuiItemStatusFlags LastItemStatusFlags; 992 ImRect LastItemRect; 993 ImRect LastItemDisplayRect; 994 995 ImGuiItemHoveredDataBackup() { Backup(); } 996 void Backup() { ImGuiWindow* window = GImGui->CurrentWindow; LastItemId = window->DC.LastItemId; LastItemStatusFlags = window->DC.LastItemStatusFlags; LastItemRect = window->DC.LastItemRect; LastItemDisplayRect = window->DC.LastItemDisplayRect; } 997 void Restore() const { ImGuiWindow* window = GImGui->CurrentWindow; window->DC.LastItemId = LastItemId; window->DC.LastItemStatusFlags = LastItemStatusFlags; window->DC.LastItemRect = LastItemRect; window->DC.LastItemDisplayRect = LastItemDisplayRect; } 998 }; 999 1000 //----------------------------------------------------------------------------- 1001 // Internal API 1002 // No guarantee of forward compatibility here. 1656 ImGuiWindow(ImGuiContext* context, const char* name); 1657 ~ImGuiWindow(); 1658 1659 ImGuiID GetID(const char* str, const char* str_end = NULL); 1660 ImGuiID GetID(const void* ptr); 1661 ImGuiID GetID(int n); 1662 ImGuiID GetIDNoKeepAlive(const char* str, const char* str_end = NULL); 1663 ImGuiID GetIDNoKeepAlive(const void* ptr); 1664 ImGuiID GetIDNoKeepAlive(int n); 1665 ImGuiID GetIDFromRectangle(const ImRect& r_abs); 1666 1667 // We don't use g.FontSize because the window may be != g.CurrentWidow. 1668 ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); } 1669 float CalcFontSize() const { ImGuiContext& g = *GImGui; float scale = g.FontBaseSize * FontWindowScale; if (ParentWindow) scale *= ParentWindow->FontWindowScale; return scale; } 1670 float TitleBarHeight() const { ImGuiContext& g = *GImGui; return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + g.Style.FramePadding.y * 2.0f; } 1671 ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); } 1672 float MenuBarHeight() const { ImGuiContext& g = *GImGui; return (Flags & ImGuiWindowFlags_MenuBar) ? DC.MenuBarOffset.y + CalcFontSize() + g.Style.FramePadding.y * 2.0f : 0.0f; } 1673 ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); } 1674 }; 1675 1676 // 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. 1677 struct ImGuiLastItemDataBackup 1678 { 1679 ImGuiID LastItemId; 1680 ImGuiItemStatusFlags LastItemStatusFlags; 1681 ImRect LastItemRect; 1682 ImRect LastItemDisplayRect; 1683 1684 ImGuiLastItemDataBackup() { Backup(); } 1685 void Backup() { ImGuiWindow* window = GImGui->CurrentWindow; LastItemId = window->DC.LastItemId; LastItemStatusFlags = window->DC.LastItemStatusFlags; LastItemRect = window->DC.LastItemRect; LastItemDisplayRect = window->DC.LastItemDisplayRect; } 1686 void Restore() const { ImGuiWindow* window = GImGui->CurrentWindow; window->DC.LastItemId = LastItemId; window->DC.LastItemStatusFlags = LastItemStatusFlags; window->DC.LastItemRect = LastItemRect; window->DC.LastItemDisplayRect = LastItemDisplayRect; } 1687 }; 1688 1689 //----------------------------------------------------------------------------- 1690 // [SECTION] Tab bar, Tab item support 1691 //----------------------------------------------------------------------------- 1692 1693 // Extend ImGuiTabBarFlags_ 1694 enum ImGuiTabBarFlagsPrivate_ 1695 { 1696 ImGuiTabBarFlags_DockNode = 1 << 20, // Part of a dock node [we don't use this in the master branch but it facilitate branch syncing to keep this around] 1697 ImGuiTabBarFlags_IsFocused = 1 << 21, 1698 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 1699 }; 1700 1701 // Extend ImGuiTabItemFlags_ 1702 enum ImGuiTabItemFlagsPrivate_ 1703 { 1704 ImGuiTabItemFlags_NoCloseButton = 1 << 20, // Track whether p_open was set or not (we'll need this info on the next frame to recompute ContentWidth during layout) 1705 ImGuiTabItemFlags_Button = 1 << 21 // Used by TabItemButton, change the tab item behavior to mimic a button 1706 }; 1707 1708 // Storage for one active tab item (sizeof() 28~32 bytes) 1709 struct ImGuiTabItem 1710 { 1711 ImGuiID ID; 1712 ImGuiTabItemFlags Flags; 1713 int LastFrameVisible; 1714 int LastFrameSelected; // This allows us to infer an ordered list of the last activated tabs with little maintenance 1715 float Offset; // Position relative to beginning of tab 1716 float Width; // Width currently displayed 1717 float ContentWidth; // Width of label, stored during BeginTabItem() call 1718 ImS16 NameOffset; // When Window==NULL, offset to name within parent ImGuiTabBar::TabsNames 1719 ImS8 BeginOrder; // BeginTabItem() order, used to re-order tabs after toggling ImGuiTabBarFlags_Reorderable 1720 ImS8 IndexDuringLayout; // Index only used during TabBarLayout() 1721 bool WantClose; // Marked as closed by SetTabItemClosed() 1722 1723 ImGuiTabItem() { ID = 0; Flags = ImGuiTabItemFlags_None; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = ContentWidth = 0.0f; BeginOrder = -1; IndexDuringLayout = -1; WantClose = false; } 1724 }; 1725 1726 // Storage for a tab bar (sizeof() 92~96 bytes) 1727 struct ImGuiTabBar 1728 { 1729 ImVector<ImGuiTabItem> Tabs; 1730 ImGuiID ID; // Zero for tab-bars used by docking 1731 ImGuiID SelectedTabId; // Selected tab/window 1732 ImGuiID NextSelectedTabId; 1733 ImGuiID VisibleTabId; // Can occasionally be != SelectedTabId (e.g. when previewing contents for CTRL+TAB preview) 1734 int CurrFrameVisible; 1735 int PrevFrameVisible; 1736 ImRect BarRect; 1737 float LastTabContentHeight; // Record the height of contents submitted below the tab bar 1738 float WidthAllTabs; // Actual width of all tabs (locked during layout) 1739 float WidthAllTabsIdeal; // Ideal width if all tabs were visible and not clipped 1740 float ScrollingAnim; 1741 float ScrollingTarget; 1742 float ScrollingTargetDistToVisibility; 1743 float ScrollingSpeed; 1744 float ScrollingRectMinX; 1745 float ScrollingRectMaxX; 1746 ImGuiTabBarFlags Flags; 1747 ImGuiID ReorderRequestTabId; 1748 ImS8 ReorderRequestDir; 1749 ImS8 TabsActiveCount; // Number of tabs submitted this frame. 1750 bool WantLayout; 1751 bool VisibleTabWasSubmitted; 1752 bool TabsAddedNew; // Set to true when a new tab item or button has been added to the tab bar during last frame 1753 short LastTabItemIdx; // Index of last BeginTabItem() tab for use by EndTabItem() 1754 ImVec2 FramePadding; // style.FramePadding locked at the time of BeginTabBar() 1755 ImGuiTextBuffer TabsNames; // For non-docking tab bar we re-append names in a contiguous buffer. 1756 1757 ImGuiTabBar(); 1758 int GetTabOrder(const ImGuiTabItem* tab) const { return Tabs.index_from_ptr(tab); } 1759 const char* GetTabName(const ImGuiTabItem* tab) const 1760 { 1761 IM_ASSERT(tab->NameOffset != -1 && (int)tab->NameOffset < TabsNames.Buf.Size); 1762 return TabsNames.Buf.Data + tab->NameOffset; 1763 } 1764 }; 1765 1766 //----------------------------------------------------------------------------- 1767 // [SECTION] Table support 1768 //----------------------------------------------------------------------------- 1769 1770 #ifdef IMGUI_HAS_TABLE 1771 // <this is filled in 'tables' branch> 1772 #endif // #ifdef IMGUI_HAS_TABLE 1773 1774 //----------------------------------------------------------------------------- 1775 // [SECTION] Internal API 1776 // No guarantee of forward compatibility here! 1003 1777 //----------------------------------------------------------------------------- 1004 1778 1005 1779 namespace ImGui 1006 1780 { 1007 // We should always have a CurrentWindow in the stack (there is an implicit "Debug" window) 1008 // If this ever crash because g.CurrentWindow is NULL it means that either 1009 // - ImGui::NewFrame() has never been called, which is illegal. 1010 // - You are calling ImGui functions after ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal. 1011 inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; } 1012 inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; } 1013 IMGUI_API ImGuiWindow* FindWindowByName(const char* name); 1014 IMGUI_API void FocusWindow(ImGuiWindow* window); 1015 IMGUI_API void BringWindowToFront(ImGuiWindow* window); 1016 IMGUI_API void BringWindowToBack(ImGuiWindow* window); 1017 IMGUI_API bool IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent); 1018 IMGUI_API bool IsWindowNavFocusable(ImGuiWindow* window); 1019 1020 IMGUI_API void Initialize(ImGuiContext* context); 1021 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(). 1022 1023 IMGUI_API void NewFrameUpdateHoveredWindowAndCaptureFlags(); 1024 1025 IMGUI_API void MarkIniSettingsDirty(); 1026 IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name); 1027 IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id); 1028 1029 IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window); 1030 IMGUI_API ImGuiID GetActiveID(); 1031 IMGUI_API void SetFocusID(ImGuiID id, ImGuiWindow* window); 1032 IMGUI_API void ClearActiveID(); 1033 IMGUI_API void SetHoveredID(ImGuiID id); 1034 IMGUI_API ImGuiID GetHoveredID(); 1035 IMGUI_API void KeepAliveID(ImGuiID id); 1036 1037 IMGUI_API void ItemSize(const ImVec2& size, float text_offset_y = 0.0f); 1038 IMGUI_API void ItemSize(const ImRect& bb, float text_offset_y = 0.0f); 1039 IMGUI_API bool ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb = NULL); 1040 IMGUI_API bool ItemHoverable(const ImRect& bb, ImGuiID id); 1041 IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged); 1042 IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop = true); // Return true if focus is requested 1043 IMGUI_API void FocusableItemUnregister(ImGuiWindow* window); 1044 IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_x, float default_y); 1045 IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x); 1046 IMGUI_API void PushMultiItemsWidths(int components, float width_full = 0.0f); 1047 IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled); 1048 IMGUI_API void PopItemFlag(); 1049 1050 IMGUI_API void SetCurrentFont(ImFont* font); 1051 1052 IMGUI_API void OpenPopupEx(ImGuiID id); 1053 IMGUI_API void ClosePopup(ImGuiID id); 1054 IMGUI_API void ClosePopupsOverWindow(ImGuiWindow* ref_window); 1055 IMGUI_API bool IsPopupOpen(ImGuiID id); 1056 IMGUI_API bool BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags); 1057 IMGUI_API void BeginTooltipEx(ImGuiWindowFlags extra_flags, bool override_previous_tooltip = true); 1058 IMGUI_API ImGuiWindow* GetFrontMostPopupModal(); 1059 1060 IMGUI_API void NavInitWindow(ImGuiWindow* window, bool force_reinit); 1061 IMGUI_API void NavMoveRequestCancel(); 1062 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. 1063 1064 IMGUI_API float GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode); 1065 IMGUI_API ImVec2 GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f); 1066 IMGUI_API int CalcTypematicPressedRepeatAmount(float t, float t_prev, float repeat_delay, float repeat_rate); 1067 1068 IMGUI_API void Scrollbar(ImGuiLayoutType direction); 1069 IMGUI_API void VerticalSeparator(); // Vertical separator, for menu bars (use current line height). not exposed because it is misleading what it doesn't have an effect on regular layout. 1070 IMGUI_API bool SplitterBehavior(ImGuiID id, const ImRect& bb, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend = 0.0f); 1071 1072 IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id); 1073 IMGUI_API void ClearDragDrop(); 1074 IMGUI_API bool IsDragDropPayloadBeingAccepted(); 1075 1076 // FIXME-WIP: New Columns API 1077 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(). 1078 IMGUI_API void EndColumns(); // close columns 1079 IMGUI_API void PushColumnClipRect(int column_index = -1); 1080 1081 // NB: All position are in absolute pixels coordinates (never using window coordinates internally) 1082 // 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. 1083 IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); 1084 IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width); 1085 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); 1086 IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); 1087 IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f); 1088 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); 1089 IMGUI_API void RenderArrow(ImVec2 pos, ImGuiDir dir, float scale = 1.0f); 1090 IMGUI_API void RenderBullet(ImVec2 pos); 1091 IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col, float sz); 1092 IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight 1093 IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); 1094 IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. 1095 1096 IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0); 1097 IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0); 1098 IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos, float radius); 1099 1100 IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, const char* format, float power, ImGuiSliderFlags flags = 0); 1101 IMGUI_API bool SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* format, float power); 1102 IMGUI_API bool SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* format); 1103 1104 IMGUI_API bool DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, const char* format, float power); 1105 IMGUI_API bool DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* format, float power); 1106 IMGUI_API bool DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* format); 1107 1108 IMGUI_API bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback = NULL, void* user_data = NULL); 1109 IMGUI_API bool InputFloatN(const char* label, float* v, int components, const char* format, ImGuiInputTextFlags extra_flags); 1110 IMGUI_API bool InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags); 1111 IMGUI_API bool InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* format, ImGuiInputTextFlags extra_flags = 0); 1112 IMGUI_API bool InputScalarAsWidgetReplacement(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* data_ptr, const char* format); 1113 1114 IMGUI_API void ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags); 1115 IMGUI_API void ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags); 1116 1117 IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL); 1118 IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging 1119 IMGUI_API void TreePushRawID(ImGuiID id); 1120 1121 IMGUI_API void PlotEx(ImGuiPlotType plot_type, const char* label, float(*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size); 1122 1123 IMGUI_API const char* ParseFormatTrimDecorationsLeading(const char* format); 1124 IMGUI_API const char* ParseFormatTrimDecorations(const char* format, char* buf, int buf_size); 1125 IMGUI_API int ParseFormatPrecision(const char* format, int default_value); 1126 IMGUI_API float RoundScalarWithFormat(const char* format, float value); 1127 1128 // Shade functions (write over already created vertices) 1129 IMGUI_API void ShadeVertsLinearColorGradientKeepAlpha(ImDrawVert* vert_start, ImDrawVert* vert_end, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1); 1130 IMGUI_API void ShadeVertsLinearAlphaGradientForLeftToRightText(ImDrawVert* vert_start, ImDrawVert* vert_end, float gradient_p0_x, float gradient_p1_x); 1131 IMGUI_API void ShadeVertsLinearUV(ImDrawVert* vert_start, ImDrawVert* vert_end, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, bool clamp); 1781 // Windows 1782 // We should always have a CurrentWindow in the stack (there is an implicit "Debug" window) 1783 // If this ever crash because g.CurrentWindow is NULL it means that either 1784 // - ImGui::NewFrame() has never been called, which is illegal. 1785 // - You are calling ImGui functions after ImGui::EndFrame()/ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal. 1786 inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; } 1787 inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; } 1788 IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id); 1789 IMGUI_API ImGuiWindow* FindWindowByName(const char* name); 1790 IMGUI_API void UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window); 1791 IMGUI_API ImVec2 CalcWindowExpectedSize(ImGuiWindow* window); 1792 IMGUI_API bool IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent); 1793 IMGUI_API bool IsWindowNavFocusable(ImGuiWindow* window); 1794 IMGUI_API ImRect GetWindowAllowedExtentRect(ImGuiWindow* window); 1795 IMGUI_API void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond = 0); 1796 IMGUI_API void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond = 0); 1797 IMGUI_API void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond = 0); 1798 IMGUI_API void SetWindowHitTestHole(ImGuiWindow* window, const ImVec2& pos, const ImVec2& size); 1799 1800 // Windows: Display Order and Focus Order 1801 IMGUI_API void FocusWindow(ImGuiWindow* window); 1802 IMGUI_API void FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window); 1803 IMGUI_API void BringWindowToFocusFront(ImGuiWindow* window); 1804 IMGUI_API void BringWindowToDisplayFront(ImGuiWindow* window); 1805 IMGUI_API void BringWindowToDisplayBack(ImGuiWindow* window); 1806 1807 // Fonts, drawing 1808 IMGUI_API void SetCurrentFont(ImFont* font); 1809 inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; } 1810 inline ImDrawList* GetForegroundDrawList(ImGuiWindow* window) { IM_UNUSED(window); ImGuiContext& g = *GImGui; return &g.ForegroundDrawList; } // This seemingly unnecessary wrapper simplifies compatibility between the 'master' and 'docking' branches. 1811 1812 // Init 1813 IMGUI_API void Initialize(ImGuiContext* context); 1814 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(). 1815 1816 // NewFrame 1817 IMGUI_API void UpdateHoveredWindowAndCaptureFlags(); 1818 IMGUI_API void StartMouseMovingWindow(ImGuiWindow* window); 1819 IMGUI_API void UpdateMouseMovingWindowNewFrame(); 1820 IMGUI_API void UpdateMouseMovingWindowEndFrame(); 1821 1822 // Settings 1823 IMGUI_API void MarkIniSettingsDirty(); 1824 IMGUI_API void MarkIniSettingsDirty(ImGuiWindow* window); 1825 IMGUI_API void ClearIniSettings(); 1826 IMGUI_API ImGuiWindowSettings* CreateNewWindowSettings(const char* name); 1827 IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id); 1828 IMGUI_API ImGuiWindowSettings* FindOrCreateWindowSettings(const char* name); 1829 IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name); 1830 1831 // Scrolling 1832 IMGUI_API void SetNextWindowScroll(const ImVec2& scroll); // Use -1.0f on one axis to leave as-is 1833 IMGUI_API void SetScrollX(ImGuiWindow* window, float scroll_x); 1834 IMGUI_API void SetScrollY(ImGuiWindow* window, float scroll_y); 1835 IMGUI_API void SetScrollFromPosX(ImGuiWindow* window, float local_x, float center_x_ratio); 1836 IMGUI_API void SetScrollFromPosY(ImGuiWindow* window, float local_y, float center_y_ratio); 1837 IMGUI_API ImVec2 ScrollToBringRectIntoView(ImGuiWindow* window, const ImRect& item_rect); 1838 1839 // Basic Accessors 1840 inline ImGuiID GetItemID() { ImGuiContext& g = *GImGui; return g.CurrentWindow->DC.LastItemId; } // Get ID of last item (~~ often same ImGui::GetID(label) beforehand) 1841 inline ImGuiItemStatusFlags GetItemStatusFlags() { ImGuiContext& g = *GImGui; return g.CurrentWindow->DC.LastItemStatusFlags; } 1842 inline ImGuiID GetActiveID() { ImGuiContext& g = *GImGui; return g.ActiveId; } 1843 inline ImGuiID GetFocusID() { ImGuiContext& g = *GImGui; return g.NavId; } 1844 IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window); 1845 IMGUI_API void SetFocusID(ImGuiID id, ImGuiWindow* window); 1846 IMGUI_API void ClearActiveID(); 1847 IMGUI_API ImGuiID GetHoveredID(); 1848 IMGUI_API void SetHoveredID(ImGuiID id); 1849 IMGUI_API void KeepAliveID(ImGuiID id); 1850 IMGUI_API void MarkItemEdited(ImGuiID id); // Mark data associated to given item as "edited", used by IsItemDeactivatedAfterEdit() function. 1851 IMGUI_API void PushOverrideID(ImGuiID id); // Push given value as-is at the top of the ID stack (whereas PushID combines old and new hashes) 1852 IMGUI_API ImGuiID GetIDWithSeed(const char* str_id_begin, const char* str_id_end, ImGuiID seed); 1853 1854 // Basic Helpers for widget code 1855 IMGUI_API void ItemSize(const ImVec2& size, float text_baseline_y = -1.0f); 1856 IMGUI_API void ItemSize(const ImRect& bb, float text_baseline_y = -1.0f); 1857 IMGUI_API bool ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb = NULL); 1858 IMGUI_API bool ItemHoverable(const ImRect& bb, ImGuiID id); 1859 IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged); 1860 IMGUI_API void SetLastItemData(ImGuiWindow* window, ImGuiID item_id, ImGuiItemStatusFlags status_flags, const ImRect& item_rect); 1861 IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id); // Return true if focus is requested 1862 IMGUI_API void FocusableItemUnregister(ImGuiWindow* window); 1863 IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_w, float default_h); 1864 IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x); 1865 IMGUI_API void PushMultiItemsWidths(int components, float width_full); 1866 IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled); 1867 IMGUI_API void PopItemFlag(); 1868 IMGUI_API bool IsItemToggledSelection(); // Was the last item selection toggled? (after Selectable(), TreeNode() etc. We only returns toggle _event_ in order to handle clipping correctly) 1869 IMGUI_API ImVec2 GetContentRegionMaxAbs(); 1870 IMGUI_API void ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_excess); 1871 1872 // Logging/Capture 1873 IMGUI_API void LogBegin(ImGuiLogType type, int auto_open_depth); // -> BeginCapture() when we design v2 api, for now stay under the radar by using the old name. 1874 IMGUI_API void LogToBuffer(int auto_open_depth = -1); // Start logging/capturing to internal buffer 1875 1876 // Popups, Modals, Tooltips 1877 IMGUI_API bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags); 1878 IMGUI_API void OpenPopupEx(ImGuiID id, ImGuiPopupFlags popup_flags = ImGuiPopupFlags_None); 1879 IMGUI_API void ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_popup); 1880 IMGUI_API void ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to_window_under_popup); 1881 IMGUI_API bool IsPopupOpen(ImGuiID id, ImGuiPopupFlags popup_flags); 1882 IMGUI_API bool BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags); 1883 IMGUI_API void BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags tooltip_flags); 1884 IMGUI_API ImGuiWindow* GetTopMostPopupModal(); 1885 IMGUI_API ImVec2 FindBestWindowPosForPopup(ImGuiWindow* window); 1886 IMGUI_API ImVec2 FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& size, ImGuiDir* last_dir, const ImRect& r_outer, const ImRect& r_avoid, ImGuiPopupPositionPolicy policy); 1887 1888 // Gamepad/Keyboard Navigation 1889 IMGUI_API void NavInitWindow(ImGuiWindow* window, bool force_reinit); 1890 IMGUI_API bool NavMoveRequestButNoResultYet(); 1891 IMGUI_API void NavMoveRequestCancel(); 1892 IMGUI_API void NavMoveRequestForward(ImGuiDir move_dir, ImGuiDir clip_dir, const ImRect& bb_rel, ImGuiNavMoveFlags move_flags); 1893 IMGUI_API void NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags); 1894 IMGUI_API float GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode); 1895 IMGUI_API ImVec2 GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f); 1896 IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate); 1897 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. 1898 IMGUI_API void SetNavID(ImGuiID id, int nav_layer, ImGuiID focus_scope_id); 1899 IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel); 1900 1901 // Focus Scope (WIP) 1902 // This is generally used to identify a selection set (multiple of which may be in the same window), as selection 1903 // patterns generally need to react (e.g. clear selection) when landing on an item of the set. 1904 IMGUI_API void PushFocusScope(ImGuiID id); 1905 IMGUI_API void PopFocusScope(); 1906 inline ImGuiID GetFocusScopeID() { ImGuiContext& g = *GImGui; return g.NavFocusScopeId; } 1907 1908 // Inputs 1909 // FIXME: Eventually we should aim to move e.g. IsActiveIdUsingKey() into IsKeyXXX functions. 1910 inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; } 1911 inline bool IsActiveIdUsingNavInput(ImGuiNavInput input) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavInputMask & (1 << input)) != 0; } 1912 inline bool IsActiveIdUsingKey(ImGuiKey key) { ImGuiContext& g = *GImGui; IM_ASSERT(key < 64); return (g.ActiveIdUsingKeyInputMask & ((ImU64)1 << key)) != 0; } 1913 IMGUI_API bool IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold = -1.0f); 1914 inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { ImGuiContext& g = *GImGui; const int key_index = g.IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; } 1915 inline bool IsNavInputDown(ImGuiNavInput n) { ImGuiContext& g = *GImGui; return g.IO.NavInputs[n] > 0.0f; } 1916 inline bool IsNavInputTest(ImGuiNavInput n, ImGuiInputReadMode rm) { return (GetNavInputAmount(n, rm) > 0.0f); } 1917 IMGUI_API ImGuiKeyModFlags GetMergedKeyModFlags(); 1918 1919 // Drag and Drop 1920 IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id); 1921 IMGUI_API void ClearDragDrop(); 1922 IMGUI_API bool IsDragDropPayloadBeingAccepted(); 1923 1924 // Internal Columns API (this is not exposed because we will encourage transitioning to the Tables API) 1925 IMGUI_API void SetWindowClipRectBeforeSetChannel(ImGuiWindow* window, const ImRect& clip_rect); 1926 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(). 1927 IMGUI_API void EndColumns(); // close columns 1928 IMGUI_API void PushColumnClipRect(int column_index); 1929 IMGUI_API void PushColumnsBackground(); 1930 IMGUI_API void PopColumnsBackground(); 1931 IMGUI_API ImGuiID GetColumnsID(const char* str_id, int count); 1932 IMGUI_API ImGuiColumns* FindOrCreateColumns(ImGuiWindow* window, ImGuiID id); 1933 IMGUI_API float GetColumnOffsetFromNorm(const ImGuiColumns* columns, float offset_norm); 1934 IMGUI_API float GetColumnNormFromOffset(const ImGuiColumns* columns, float offset); 1935 1936 // Tab Bars 1937 IMGUI_API bool BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& bb, ImGuiTabBarFlags flags); 1938 IMGUI_API ImGuiTabItem* TabBarFindTabByID(ImGuiTabBar* tab_bar, ImGuiID tab_id); 1939 IMGUI_API void TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id); 1940 IMGUI_API void TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab); 1941 IMGUI_API void TabBarQueueReorder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, int dir); 1942 IMGUI_API bool TabBarProcessReorder(ImGuiTabBar* tab_bar); 1943 IMGUI_API bool TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags); 1944 IMGUI_API ImVec2 TabItemCalcSize(const char* label, bool has_close_button); 1945 IMGUI_API void TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col); 1946 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, bool is_contents_visible); 1947 1948 // Render helpers 1949 // 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. 1950 // NB: All position are in absolute pixels coordinates (we are never using window coordinates internally) 1951 IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); 1952 IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width); 1953 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); 1954 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); 1955 IMGUI_API void RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end, const ImVec2* text_size_if_known); 1956 IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); 1957 IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f); 1958 IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0); 1959 IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight 1960 IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. 1961 IMGUI_API void LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL); 1962 1963 // Render helpers (those functions don't access any ImGui state!) 1964 IMGUI_API void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale = 1.0f); 1965 IMGUI_API void RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col); 1966 IMGUI_API void RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz); 1967 IMGUI_API void RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow); 1968 IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col); 1969 IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); 1970 IMGUI_API void RenderRectFilledWithHole(ImDrawList* draw_list, ImRect outer, ImRect inner, ImU32 col, float rounding); 1971 1972 #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS 1973 // [1.71: 2019/06/07: Updating prototypes of some of the internal functions. Leaving those for reference for a short while] 1974 inline void RenderArrow(ImVec2 pos, ImGuiDir dir, float scale=1.0f) { ImGuiWindow* window = GetCurrentWindow(); RenderArrow(window->DrawList, pos, GetColorU32(ImGuiCol_Text), dir, scale); } 1975 inline void RenderBullet(ImVec2 pos) { ImGuiWindow* window = GetCurrentWindow(); RenderBullet(window->DrawList, pos, GetColorU32(ImGuiCol_Text)); } 1976 #endif 1977 1978 // Widgets 1979 IMGUI_API void TextEx(const char* text, const char* text_end = NULL, ImGuiTextFlags flags = 0); 1980 IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0); 1981 IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos); 1982 IMGUI_API bool CollapseButton(ImGuiID id, const ImVec2& pos); 1983 IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags = 0); 1984 IMGUI_API void Scrollbar(ImGuiAxis axis); 1985 IMGUI_API bool ScrollbarEx(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* p_scroll_v, float avail_v, float contents_v, ImDrawCornerFlags rounding_corners); 1986 IMGUI_API bool ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec2& padding, const ImVec4& bg_col, const ImVec4& tint_col); 1987 IMGUI_API ImRect GetWindowScrollbarRect(ImGuiWindow* window, ImGuiAxis axis); 1988 IMGUI_API ImGuiID GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis); 1989 IMGUI_API ImGuiID GetWindowResizeID(ImGuiWindow* window, int n); // 0..3: corners, 4..7: borders 1990 IMGUI_API void SeparatorEx(ImGuiSeparatorFlags flags); 1991 1992 // Widgets low-level behaviors 1993 IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0); 1994 IMGUI_API bool DragBehavior(ImGuiID id, ImGuiDataType data_type, void* p_v, float v_speed, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags); 1995 IMGUI_API bool SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* p_v, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags, ImRect* out_grab_bb); 1996 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); 1997 IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL); 1998 IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextItemOpen() data, if any. May return true when logging 1999 IMGUI_API void TreePushOverrideID(ImGuiID id); 2000 2001 // Template functions are instantiated in imgui_widgets.cpp for a finite number of types. 2002 // 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). 2003 // e.g. " extern template IMGUI_API float RoundScalarWithFormatT<float, float>(const char* format, ImGuiDataType data_type, float v); " 2004 template<typename T, typename SIGNED_T, typename FLOAT_T> IMGUI_API float ScaleRatioFromValueT(ImGuiDataType data_type, T v, T v_min, T v_max, bool is_logarithmic, float logarithmic_zero_epsilon, float zero_deadzone_size); 2005 template<typename T, typename SIGNED_T, typename FLOAT_T> IMGUI_API T ScaleValueFromRatioT(ImGuiDataType data_type, float t, T v_min, T v_max, bool is_logarithmic, float logarithmic_zero_epsilon, float zero_deadzone_size); 2006 template<typename T, typename SIGNED_T, typename FLOAT_T> IMGUI_API bool DragBehaviorT(ImGuiDataType data_type, T* v, float v_speed, T v_min, T v_max, const char* format, ImGuiSliderFlags flags); 2007 template<typename T, typename SIGNED_T, typename FLOAT_T> IMGUI_API bool SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, T* v, T v_min, T v_max, const char* format, ImGuiSliderFlags flags, ImRect* out_grab_bb); 2008 template<typename T, typename SIGNED_T> IMGUI_API T RoundScalarWithFormatT(const char* format, ImGuiDataType data_type, T v); 2009 2010 // Data type helpers 2011 IMGUI_API const ImGuiDataTypeInfo* DataTypeGetInfo(ImGuiDataType data_type); 2012 IMGUI_API int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* p_data, const char* format); 2013 IMGUI_API void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, const void* arg_1, const void* arg_2); 2014 IMGUI_API bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* p_data, const char* format); 2015 IMGUI_API int DataTypeCompare(ImGuiDataType data_type, const void* arg_1, const void* arg_2); 2016 IMGUI_API bool DataTypeClamp(ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max); 2017 2018 // InputText 2019 IMGUI_API bool InputTextEx(const char* label, const char* hint, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); 2020 IMGUI_API bool TempInputText(const ImRect& bb, ImGuiID id, const char* label, char* buf, int buf_size, ImGuiInputTextFlags flags); 2021 IMGUI_API bool TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format, const void* p_clamp_min = NULL, const void* p_clamp_max = NULL); 2022 inline bool TempInputIsActive(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.ActiveId == id && g.TempInputId == id); } 2023 inline ImGuiInputTextState* GetInputTextState(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.InputTextState.ID == id) ? &g.InputTextState : NULL; } // Get input text state if active 2024 2025 // Color 2026 IMGUI_API void ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags); 2027 IMGUI_API void ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags); 2028 IMGUI_API void ColorPickerOptionsPopup(const float* ref_col, ImGuiColorEditFlags flags); 2029 2030 // Plot 2031 IMGUI_API int 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); 2032 2033 // Shade functions (write over already created vertices) 2034 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); 2035 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); 2036 2037 // Garbage collection 2038 IMGUI_API void GcCompactTransientWindowBuffers(ImGuiWindow* window); 2039 IMGUI_API void GcAwakeTransientWindowBuffers(ImGuiWindow* window); 2040 2041 // Debug Tools 2042 inline void DebugDrawItemRect(ImU32 col = IM_COL32(255,0,0,255)) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; GetForegroundDrawList(window)->AddRect(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max, col); } 2043 inline void DebugStartItemPicker() { ImGuiContext& g = *GImGui; g.DebugItemPickerActive = true; } 1132 2044 1133 2045 } // namespace ImGui 1134 2046 1135 2047 // ImFontAtlas internals 1136 2048 IMGUI_API bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas); 1137 IMGUI_API void ImFontAtlasBuild RegisterDefaultCustomRects(ImFontAtlas* atlas);2049 IMGUI_API void ImFontAtlasBuildInit(ImFontAtlas* atlas); 1138 2050 IMGUI_API void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent); 1139 IMGUI_API void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* s pc);2051 IMGUI_API void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opaque); 1140 2052 IMGUI_API void ImFontAtlasBuildFinish(ImFontAtlas* atlas); 2053 IMGUI_API void ImFontAtlasBuildRender1bppRectFromString(ImFontAtlas* atlas, int atlas_x, int atlas_y, int w, int h, const char* in_str, char in_marker_char, unsigned char in_marker_pixel_value); 1141 2054 IMGUI_API void ImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256], float in_multiply_factor); 1142 2055 IMGUI_API void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride); 1143 2056 1144 #ifdef __clang__ 2057 //----------------------------------------------------------------------------- 2058 // [SECTION] Test Engine Hooks (imgui_test_engine) 2059 //----------------------------------------------------------------------------- 2060 2061 #ifdef IMGUI_ENABLE_TEST_ENGINE 2062 extern void ImGuiTestEngineHook_Shutdown(ImGuiContext* ctx); 2063 extern void ImGuiTestEngineHook_PreNewFrame(ImGuiContext* ctx); 2064 extern void ImGuiTestEngineHook_PostNewFrame(ImGuiContext* ctx); 2065 extern void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, const ImRect& bb, ImGuiID id); 2066 extern void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* label, ImGuiItemStatusFlags flags); 2067 extern void ImGuiTestEngineHook_IdInfo(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id); 2068 extern void ImGuiTestEngineHook_IdInfo(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id, const void* data_id_end); 2069 extern void ImGuiTestEngineHook_Log(ImGuiContext* ctx, const char* fmt, ...); 2070 #define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemAdd(&g, _BB, _ID) // Register item bounding box 2071 #define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional) 2072 #define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log 2073 #define IMGUI_TEST_ENGINE_ID_INFO(_ID,_TYPE,_DATA) if (g.TestEngineHookIdInfo == id) ImGuiTestEngineHook_IdInfo(&g, _TYPE, _ID, (const void*)(_DATA)); 2074 #define IMGUI_TEST_ENGINE_ID_INFO2(_ID,_TYPE,_DATA,_DATA2) if (g.TestEngineHookIdInfo == id) ImGuiTestEngineHook_IdInfo(&g, _TYPE, _ID, (const void*)(_DATA), (const void*)(_DATA2)); 2075 #else 2076 #define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) do { } while (0) 2077 #define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) do { } while (0) 2078 #define IMGUI_TEST_ENGINE_LOG(_FMT,...) do { } while (0) 2079 #define IMGUI_TEST_ENGINE_ID_INFO(_ID,_TYPE,_DATA) do { } while (0) 2080 #define IMGUI_TEST_ENGINE_ID_INFO2(_ID,_TYPE,_DATA,_DATA2) do { } while (0) 2081 #endif 2082 2083 #if defined(__clang__) 1145 2084 #pragma clang diagnostic pop 2085 #elif defined(__GNUC__) 2086 #pragma GCC diagnostic pop 1146 2087 #endif 1147 2088 … … 1149 2090 #pragma warning (pop) 1150 2091 #endif 2092 2093 #endif // #ifndef IMGUI_DISABLE
Note:
See TracChangeset
for help on using the changeset viewer.