VR-Vantage 2.5 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
imgui_internal.h
Go to the documentation of this file.
1 // dear imgui, v1.51
2 // (internals)
3 
4 // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility!
5 // Implement maths operators for ImVec2 (disabled by default to not collide with using IM_VEC2_CLASS_EXTRA along with your own math types+operators)
6 // #define IMGUI_DEFINE_MATH_OPERATORS
7 // Define IM_PLACEMENT_NEW() macro helper.
8 // #define IMGUI_DEFINE_PLACEMENT_NEW
9 
10 #pragma once
11 
12 #ifndef IMGUI_VERSION
13 #error Must include imgui.h before imgui_internal.h
14 #endif
15 
16 #include <stdio.h> // FILE*
17 #include <math.h> // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf
18 
19 #ifdef _MSC_VER
20 #pragma warning (push)
21 #pragma warning (disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of struct 'xxx' // when IMGUI_API is set to__declspec(dllexport)
22 #endif
23 
24 #ifdef __clang__
25 #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
28 #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 ImGuiSimpleColumns;
40 struct ImGuiDrawContext;
41 struct ImGuiTextEditState;
42 struct ImGuiIniData;
44 struct ImGuiPopupRef;
45 struct ImGuiWindow;
46 
47 typedef int ImGuiLayoutType; // enum ImGuiLayoutType_
48 typedef int ImGuiButtonFlags; // enum ImGuiButtonFlags_
49 typedef int ImGuiTreeNodeFlags; // enum ImGuiTreeNodeFlags_
50 typedef int ImGuiSliderFlags; // enum ImGuiSliderFlags_
51 
52 //-------------------------------------------------------------------------
53 // STB libraries
54 //-------------------------------------------------------------------------
55 
56 namespace ImGuiStb
57 {
58 
59 #undef STB_TEXTEDIT_STRING
60 #undef STB_TEXTEDIT_CHARTYPE
61 #define STB_TEXTEDIT_STRING ImGuiTextEditState
62 #define STB_TEXTEDIT_CHARTYPE ImWchar
63 #define STB_TEXTEDIT_GETWIDTH_NEWLINE -1.0f
64 #include "stb_textedit.h"
65 
66 } // namespace ImGuiStb
67 
68 //-----------------------------------------------------------------------------
69 // Context
70 //-----------------------------------------------------------------------------
71 
72 #ifndef GImGui
73 extern IMGUI_API ImGuiContext* GImGui; // Current implicit ImGui context pointer
74 #endif
75 
76 //-----------------------------------------------------------------------------
77 // Helpers
78 //-----------------------------------------------------------------------------
79 
80 #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
81 #define IM_PI 3.14159265358979323846f
82 #define IM_OFFSETOF(_TYPE,_ELM) ((size_t)&(((_TYPE*)0)->_ELM))
83 
84 // Helpers: UTF-8 <> wchar
85 IMGUI_API int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count
86 IMGUI_API int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
87 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
88 IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count)
89 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
90 
91 // Helpers: Misc
92 IMGUI_API ImU32 ImHash(const void* data, int data_size, ImU32 seed = 0); // Pass data_size==0 for zero-terminated strings
93 IMGUI_API void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, int* out_file_size = NULL, int padding_bytes = 0);
94 IMGUI_API FILE* ImFileOpen(const char* filename, const char* file_open_mode);
95 static inline bool ImCharIsSpace(int c) { return c == ' ' || c == '\t' || c == 0x3000; }
96 static inline bool ImIsPowerOfTwo(int v) { return v != 0 && (v & (v - 1)) == 0; }
97 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; }
98 
99 // Helpers: Geometry
100 IMGUI_API ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p);
101 IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p);
102 IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p);
103 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);
104 
105 // Helpers: String
106 IMGUI_API int ImStricmp(const char* str1, const char* str2);
107 IMGUI_API int ImStrnicmp(const char* str1, const char* str2, int count);
108 IMGUI_API char* ImStrdup(const char* str);
109 IMGUI_API int ImStrlenW(const ImWchar* str);
110 IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line
111 IMGUI_API const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end);
112 IMGUI_API int ImFormatString(char* buf, int buf_size, const char* fmt, ...) IM_PRINTFARGS(3);
113 IMGUI_API int ImFormatStringV(char* buf, int buf_size, const char* fmt, va_list args);
114 
115 // Helpers: Math
116 // We are keeping those not leaking to the user by default, in the case the user has implicit cast operators between ImVec2 and its own types (when IM_VEC2_CLASS_EXTRA is defined)
117 #ifdef IMGUI_DEFINE_MATH_OPERATORS
118 static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
119 static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
120 static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
121 static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
122 static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
123 static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
124 static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
125 static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
126 static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
127 static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
128 static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z, lhs.w-rhs.w); }
129 #endif
130 
131 static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; }
132 static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; }
133 static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; }
134 static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; }
135 static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); }
136 static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); }
137 static inline int ImClamp(int v, int mn, int mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
138 static inline float ImClamp(float v, float mn, float mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
139 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)); }
140 static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
141 static inline int ImLerp(int a, int b, float t) { return (int)(a + (b - a) * t); }
142 static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; }
143 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); }
144 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); }
145 static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; }
146 static inline float ImLengthSqr(const ImVec4& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y + lhs.z*lhs.z + lhs.w*lhs.w; }
147 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; }
148 static inline float ImFloor(float f) { return (float)(int)f; }
149 static inline ImVec2 ImFloor(const ImVec2& v) { return ImVec2((float)(int)v.x, (float)(int)v.y); }
150 static inline float ImDot(const ImVec2& a, const ImVec2& b) { return a.x * b.x + a.y * b.y; }
151 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); }
152 
153 // We call C++ constructor on own allocated memory via the placement "new(ptr) Type()" syntax.
154 // Defining a custom placement new() with a dummy parameter allows us to bypass including <new> which on some platforms complains when user has disabled exceptions.
155 #ifdef IMGUI_DEFINE_PLACEMENT_NEW
156 struct ImPlacementNewDummy {};
157 inline void* operator new(size_t, ImPlacementNewDummy, void* ptr) { return ptr; }
158 inline void operator delete(void*, ImPlacementNewDummy, void*) {}
159 #define IM_PLACEMENT_NEW(_PTR) new(ImPlacementNewDummy(), _PTR)
160 #endif
161 
162 //-----------------------------------------------------------------------------
163 // Types
164 //-----------------------------------------------------------------------------
165 
167 {
168  ImGuiButtonFlags_Repeat = 1 << 0, // hold to repeat
169  ImGuiButtonFlags_PressedOnClickRelease = 1 << 1, // (default) return pressed on click+release on same item (default if no PressedOn** flag is set)
170  ImGuiButtonFlags_PressedOnClick = 1 << 2, // return pressed on click (default requires click+release)
171  ImGuiButtonFlags_PressedOnRelease = 1 << 3, // return pressed on release (default requires click+release)
172  ImGuiButtonFlags_PressedOnDoubleClick = 1 << 4, // return pressed on double-click (default requires click+release)
173  ImGuiButtonFlags_FlattenChilds = 1 << 5, // allow interaction even if a child window is overlapping
174  ImGuiButtonFlags_DontClosePopups = 1 << 6, // disable automatically closing parent popup on press
175  ImGuiButtonFlags_Disabled = 1 << 7, // disable interaction
176  ImGuiButtonFlags_AlignTextBaseLine = 1 << 8, // vertically align button to match text baseline - ButtonEx() only
177  ImGuiButtonFlags_NoKeyModifiers = 1 << 9, // disable interaction if a key modifier is held
178  ImGuiButtonFlags_AllowOverlapMode = 1 << 10 // require previous frame HoveredId to either match id or be null before being usable
179 };
180 
182 {
184 };
185 
187 {
188  // Default: 0
189  ImGuiColumnsFlags_NoBorder = 1 << 0, // Disable column dividers
190  ImGuiColumnsFlags_NoResize = 1 << 1, // Disable resizing columns when clicking on the dividers
191  ImGuiColumnsFlags_NoPreserveWidths = 1 << 2, // Disable column width preservation when adjusting columns
192  ImGuiColumnsFlags_NoForceWithinWindow = 1 << 3 // Disable forcing columns to fit within window
193 };
194 
196 {
197  // NB: need to be in sync with last value of ImGuiSelectableFlags_
202 };
203 
204 // FIXME: this is in development, not exposed/functional as a generic feature yet.
206 {
209 };
210 
212 {
215 };
216 
218 {
222 };
223 
225 {
231 };
232 
234 {
235  ImGuiCorner_TopLeft = 1 << 0, // 1
236  ImGuiCorner_TopRight = 1 << 1, // 2
237  ImGuiCorner_BottomRight = 1 << 2, // 4
238  ImGuiCorner_BottomLeft = 1 << 3, // 8
240 };
241 
242 // 2D axis aligned bounding-box
243 // NB: we can't rely on ImVec2 math operators being available here
245 {
246  ImVec2 Min; // Upper-left
247  ImVec2 Max; // Lower-right
248 
249  ImRect() : Min(FLT_MAX,FLT_MAX), Max(-FLT_MAX,-FLT_MAX) {}
250  ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {}
251  ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {}
252  ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {}
253 
254  ImVec2 GetCenter() const { return ImVec2((Min.x+Max.x)*0.5f, (Min.y+Max.y)*0.5f); }
255  ImVec2 GetSize() const { return ImVec2(Max.x-Min.x, Max.y-Min.y); }
256  float GetWidth() const { return Max.x-Min.x; }
257  float GetHeight() const { return Max.y-Min.y; }
258  ImVec2 GetTL() const { return Min; } // Top-left
259  ImVec2 GetTR() const { return ImVec2(Max.x, Min.y); } // Top-right
260  ImVec2 GetBL() const { return ImVec2(Min.x, Max.y); } // Bottom-left
261  ImVec2 GetBR() const { return Max; } // Bottom-right
262  bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; }
263  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; }
264  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; }
265  void Add(const ImVec2& rhs) { if (Min.x > rhs.x) Min.x = rhs.x; if (Min.y > rhs.y) Min.y = rhs.y; if (Max.x < rhs.x) Max.x = rhs.x; if (Max.y < rhs.y) Max.y = rhs.y; }
266  void Add(const ImRect& rhs) { if (Min.x > rhs.Min.x) Min.x = rhs.Min.x; if (Min.y > rhs.Min.y) Min.y = rhs.Min.y; if (Max.x < rhs.Max.x) Max.x = rhs.Max.x; if (Max.y < rhs.Max.y) Max.y = rhs.Max.y; }
267  void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; }
268  void Expand(const ImVec2& amount) { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; }
269  void Translate(const ImVec2& v) { Min.x += v.x; Min.y += v.y; Max.x += v.x; Max.y += v.y; }
270  void ClipWith(const ImRect& clip) { if (Min.x < clip.Min.x) Min.x = clip.Min.x; if (Min.y < clip.Min.y) Min.y = clip.Min.y; if (Max.x > clip.Max.x) Max.x = clip.Max.x; if (Max.y > clip.Max.y) Max.y = clip.Max.y; }
271  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; }
272  ImVec2 GetClosestPoint(ImVec2 p, bool on_edge) const
273  {
274  if (!on_edge && Contains(p))
275  return p;
276  if (p.x > Max.x) p.x = Max.x;
277  else if (p.x < Min.x) p.x = Min.x;
278  if (p.y > Max.y) p.y = Max.y;
279  else if (p.y < Min.y) p.y = Min.y;
280  return p;
281  }
282 };
283 
284 // Stacked color modifier, backup of modified data so we can restore it
286 {
289 };
290 
291 // Stacked style modifier, backup of modified data so we can restore it. Data type inferred from the variable.
293 {
295  union { int BackupInt[2]; float BackupFloat[2]; };
296  ImGuiStyleMod(ImGuiStyleVar idx, int v) { VarIdx = idx; BackupInt[0] = v; }
297  ImGuiStyleMod(ImGuiStyleVar idx, float v) { VarIdx = idx; BackupFloat[0] = v; }
299 };
301 // Stacked data for BeginGroup()/EndGroup()
303 {
313 };
314 
315 // Per column data for Columns()
317 {
318  float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right)
320  //float IndentX;
321 };
323 // Simple column measurement currently used for MenuItem() only. This is very short-sighted/throw-away code and NOT a generic helper.
325 {
326  int Count;
327  float Spacing;
328  float Width, NextWidth;
329  float Pos[8], NextWidths[8];
330 
332  void Update(int count, float spacing, bool clear);
333  float DeclColumns(float w0, float w1, float w2);
334  float CalcExtraSpace(float avail_w);
335 };
336 
337 // Internal state of the currently focused/edited text input box
339 {
340  ImGuiID Id; // widget id owning the text state
341  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.
342  ImVector<char> InitialText; // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
344  int CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format.
345  int BufSizeA; // end-user buffer size
346  float ScrollX;
348  float CursorAnim;
351 
352  ImGuiTextEditState() { memset(this, 0, sizeof(*this)); }
353  void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
354  void CursorClamp() { StbState.cursor = ImMin(StbState.cursor, CurLenW); StbState.select_start = ImMin(StbState.select_start, CurLenW); StbState.select_end = ImMin(StbState.select_end, CurLenW); }
355  bool HasSelection() const { return StbState.select_start != StbState.select_end; }
356  void ClearSelection() { StbState.select_start = StbState.select_end = StbState.cursor; }
357  void SelectAll() { StbState.select_start = 0; StbState.select_end = CurLenW; StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
358  void OnKeyPressed(int key);
359 };
361 // Data saved in imgui.ini file
363 {
364  char* Name;
368  bool Collapsed;
369 };
370 
371 // Mouse cursor data (used when io.MouseDrawCursor is set)
373 {
379 };
380 
381 // Storage for current popup stack
383 {
384  ImGuiID PopupId; // Set on OpenPopup()
385  ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup()
386  ImGuiWindow* ParentWindow; // Set on OpenPopup()
387  ImGuiID ParentMenuSet; // Set on OpenPopup()
388  ImVec2 MousePosOnOpen; // Copy of mouse position at the time of opening popup
389 
390  ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& mouse_pos) { PopupId = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; MousePosOnOpen = mouse_pos; }
391 };
392 
393 // Main state for ImGui
395 {
399  ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
400  float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize(). Text height for current window.
401  float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Base text height.
402  ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvWhitePixel
403 
404  float Time;
411  ImGuiWindow* CurrentWindow; // Being drawn into
412  ImGuiWindow* NavWindow; // Nav/focused window for navigation
413  ImGuiWindow* HoveredWindow; // Will catch mouse inputs
414  ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
415  ImGuiID HoveredId; // Hovered widget
418  ImGuiID ActiveId; // Active widget
420  bool ActiveIdIsAlive; // Active widget has been seen this frame
421  bool ActiveIdIsJustActivated; // Set at the time of activation for one frame
422  bool ActiveIdAllowOverlap; // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always)
423 
424  ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior)
426  ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window.
427  ImGuiID MovedWindowMoveId; // == MovedWindow->RootWindow->MoveId
429  float SettingsDirtyTimer; // Save .ini Settings on disk when time reaches zero
430  ImVector<ImGuiColMod> ColorModifiers; // Stack for PushStyleColor()/PopStyleColor()
431  ImVector<ImGuiStyleMod> StyleModifiers; // Stack for PushStyleVar()/PopStyleVar()
432  ImVector<ImFont*> FontStack; // Stack for PushFont()/PopFont()
433  ImVector<ImGuiPopupRef> OpenPopupStack; // Which popups are open (persistent)
434  ImVector<ImGuiPopupRef> CurrentPopupStack; // Which level of BeginPopup() we are in (reset every frame)
435 
436  // Storage for SetNexWindow** and SetNextTreeNode*** functions
445  ImRect SetNextWindowSizeConstraintRect; // Valid if 'SetNextWindowSizeConstraint' is true
452 
453  // Render
454  ImDrawData RenderDrawData; // Main ImDrawData instance to pass render information to the user
457  ImDrawList OverlayDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays
460 
461  // Widget state
464  ImGuiID ScalarAsInputTextId; // Temporary text input when CTRL+clicking on a slider, etc.
465  ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets
467  float DragCurrentValue; // Currently dragged value, always float, not rounded by end-user precision settings
469  float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
472  ImVec2 ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage?
474  ImVector<char> PrivateClipboard; // If no custom clipboard handler is defined
475  ImVec2 OsImePosRequest, OsImePosSet; // Cursor position request & last passed to the OS Input Method Editor
476 
477  // Logging
479  FILE* LogFile; // If != NULL log to stdout/ file
480  ImGuiTextBuffer* LogClipboard; // Else log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators.
483 
484  // Misc
485  float FramerateSecPerFrame[120]; // calculate estimate of framerate for user
488  int CaptureMouseNextFrame; // explicit capture via CaptureInputs() sets those flags
490  char TempBuffer[1024*3+1]; // temporary text buffer
491 
493  {
494  Initialized = false;
495  Font = NULL;
496  FontSize = FontBaseSize = 0.0f;
497  FontTexUvWhitePixel = ImVec2(0.0f, 0.0f);
498 
499  Time = 0.0f;
500  FrameCount = 0;
502  CurrentWindow = NULL;
503  NavWindow = NULL;
504  HoveredWindow = NULL;
505  HoveredRootWindow = NULL;
506  HoveredId = 0;
507  HoveredIdAllowOverlap = false;
509  ActiveId = 0;
511  ActiveIdIsAlive = false;
512  ActiveIdIsJustActivated = false;
513  ActiveIdAllowOverlap = false;
514  ActiveIdClickOffset = ImVec2(-1,-1);
515  ActiveIdWindow = NULL;
516  MovedWindow = NULL;
517  MovedWindowMoveId = 0;
518  SettingsDirtyTimer = 0.0f;
519 
520  SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
521  SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
531  SetNextWindowFocus = false;
532  SetNextTreeNodeOpenVal = false;
534 
537  DragCurrentValue = 0.0f;
538  DragLastMouseDelta = ImVec2(0.0f, 0.0f);
539  DragSpeedDefaultRatio = 1.0f / 100.0f;
540  DragSpeedScaleSlow = 0.01f;
541  DragSpeedScaleFast = 10.0f;
544  OsImePosRequest = OsImePosSet = ImVec2(-1.0f, -1.0f);
545 
547  OverlayDrawList._OwnerName = "##Overlay"; // Give it a name for debugging
549  memset(MouseCursorData, 0, sizeof(MouseCursorData));
550 
551  LogEnabled = false;
552  LogFile = NULL;
553  LogClipboard = NULL;
554  LogStartDepth = 0;
556 
557  memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
561  memset(TempBuffer, 0, sizeof(TempBuffer));
562  }
563 };
564 
565 // Transient per-window data, reset at the beginning of the frame
566 // FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiDrawContext is quite tenuous and could be reconsidered.
568 {
572  ImVec2 CursorMaxPos; // Implicitly calculate the size of our contents, always extending. Saved into window->SizeContents at the end of the frame
577  float LogLinePosY;
581  bool LastItemHoveredAndUsable; // Item rectangle is hovered, and its window is currently interactable with (not blocked by a popup preventing access to the window)
582  bool LastItemHoveredRect; // Item rectangle is hovered, but its window may or not be currently interactable with (might be blocked by a popup preventing access to the window)
588 
589  // 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.
590  float ItemWidth; // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
591  float TextWrapPos; // == TextWrapPosStack.back() [empty == -1.0f]
592  bool AllowKeyboardFocus; // == AllowKeyboardFocusStack.back() [empty == true]
593  bool ButtonRepeat; // == ButtonRepeatStack.back() [empty == false]
599  int StackSizesBackup[6]; // Store size of various stacks for asserting
600 
601  float IndentX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
603  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.
606  float ColumnsMinX;
607  float ColumnsMaxX;
609  float ColumnsStartMaxPosX; // Backup of CursorMaxPos
615 
617  {
618  CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f);
619  CurrentLineHeight = PrevLineHeight = 0.0f;
620  CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f;
621  LogLinePosY = -1.0f;
622  TreeDepth = 0;
623  LastItemId = 0;
624  LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f);
625  LastItemHoveredAndUsable = LastItemHoveredRect = false;
626  MenuBarAppending = false;
627  MenuBarOffsetX = 0.0f;
628  StateStorage = NULL;
629  LayoutType = ImGuiLayoutType_Vertical;
630  ItemWidth = 0.0f;
631  ButtonRepeat = false;
632  AllowKeyboardFocus = true;
633  TextWrapPos = -1.0f;
634  memset(StackSizesBackup, 0, sizeof(StackSizesBackup));
635 
636  IndentX = 0.0f;
637  GroupOffsetX = 0.0f;
638  ColumnsOffsetX = 0.0f;
639  ColumnsCurrent = 0;
640  ColumnsCount = 1;
641  ColumnsMinX = ColumnsMaxX = 0.0f;
642  ColumnsStartPosY = 0.0f;
643  ColumnsStartMaxPosX = 0.0f;
644  ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
645  ColumnsFlags = 0;
646  ColumnsSetId = 0;
647  }
648 };
649 
650 // Windows data
652 {
653  char* Name;
654  ImGuiID ID; // == ImHash(Name)
655  ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_
656  int OrderWithinParent; // Order within immediate parent window, if we are a child window. Otherwise 0.
658  ImVec2 Pos; // Position rounded-up to nearest pixel
659  ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
660  ImVec2 SizeFull; // Size when non collapsed
661  ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame
662  ImVec2 SizeContentsExplicit; // Size of contents explicitly set by the user via SetNextWindowContentSize()
663  ImRect ContentsRegionRect; // Maximum visible content position in window coordinates. ~~ (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis
664  ImVec2 WindowPadding; // Window padding at the time of begin. We need to lock it, in particular manipulation of the ShowBorder would have an effect
665  ImGuiID MoveId; // == window->GetID("#MOVE")
667  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)
668  ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered
669  bool ScrollbarX, ScrollbarY;
671  float BorderSize;
672  bool Active; // Set to true on Begin()
673  bool WasActive;
674  bool Accessed; // Set to true when any widget access the current window
675  bool Collapsed; // Set when collapsing window to become only title-bar
676  bool SkipItems; // == Visible && !Collapsed
677  int BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs)
678  ImGuiID PopupId; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling)
679  int AutoFitFramesX, AutoFitFramesY;
684  ImGuiCond SetWindowPosAllowFlags; // store condition flags for next SetWindowPos() call.
685  ImGuiCond SetWindowSizeAllowFlags; // store condition flags for next SetWindowSize() call.
686  ImGuiCond SetWindowCollapsedAllowFlags; // store condition flags for next SetWindowCollapsed() call.
688 
689  ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame
690  ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack
691  ImRect ClipRect; // = DrawList->clip_rect_stack.back(). Scissoring / clipping rectangle. x1, y1, x2, y2.
692  ImRect WindowRectClipped; // = WindowRect just after setup in Begin(). == window->Rect() for root window.
695  ImGuiSimpleColumns MenuColumns; // Simplified columns storage for menu items
697  float FontWindowScale; // Scale multiplier per-window
699  ImGuiWindow* RootWindow; // If we are a child window, this is pointing to the first non-child parent window. Else point to ourself.
700  ImGuiWindow* RootNonPopupWindow; // If we are a child window, this is pointing to the first non-child non-popup parent window. Else point to ourself.
701  ImGuiWindow* ParentWindow; // If we are a child window, this is pointing to our parent window. Else point to NULL.
702 
703  // Navigation / Focus
704  int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
705  int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
706  int FocusIdxAllRequestCurrent; // Item being requested for focus
707  int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus
708  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)
710 
711 public:
712  ImGuiWindow(const char* name);
713  ~ImGuiWindow();
714 
715  ImGuiID GetID(const char* str, const char* str_end = NULL);
716  ImGuiID GetID(const void* ptr);
717  ImGuiID GetIDNoKeepAlive(const char* str, const char* str_end = NULL);
718 
719  ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x+Size.x, Pos.y+Size.y); }
720  float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; }
721  float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; }
722  ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); }
723  float MenuBarHeight() const { return (Flags & ImGuiWindowFlags_MenuBar) ? CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f : 0.0f; }
724  ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); }
725 };
726 
727 //-----------------------------------------------------------------------------
728 // Internal API
729 // No guarantee of forward compatibility here.
730 //-----------------------------------------------------------------------------
731 
732 namespace ImGui
733 {
734  // We should always have a CurrentWindow in the stack (there is an implicit "Debug" window)
735  // If this ever crash because g.CurrentWindow is NULL it means that either
736  // - ImGui::NewFrame() has never been called, which is illegal.
737  // - You are calling ImGui functions after ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal.
742  IMGUI_API void FocusWindow(ImGuiWindow* window);
743 
744  IMGUI_API void EndFrame(); // Ends the ImGui frame. Automatically called by Render()! you most likely don't need to ever call that yourself directly. If you don't need to render you can call EndFrame() but you'll have wasted CPU already. If you don't need to render, don't create any windows instead!
745 
746  IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window);
747  IMGUI_API void ClearActiveID();
748  IMGUI_API void SetHoveredID(ImGuiID id);
749  IMGUI_API void KeepAliveID(ImGuiID id);
750 
751  IMGUI_API void ItemSize(const ImVec2& size, float text_offset_y = 0.0f);
752  IMGUI_API void ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
753  IMGUI_API bool ItemAdd(const ImRect& bb, const ImGuiID* id);
754  IMGUI_API bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged);
755  IMGUI_API bool IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs = false);
756  IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, bool is_active, bool tab_stop = true); // Return true if focus is requested
758  IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_x, float default_y);
759  IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
760 
761  IMGUI_API void OpenPopupEx(ImGuiID id, bool reopen_existing);
762  IMGUI_API bool IsPopupOpen(ImGuiID id);
763 
764  // New Columns API
765  IMGUI_API void BeginColumns(const char* id, int count, ImGuiColumnsFlags flags = 0); // setup number of columns. use an identifier to distinguish multiple column sets. close with EndColumns().
766  IMGUI_API void EndColumns(); // close columns
767  IMGUI_API void PushColumnClipRect(int column_index = -1);
768 
769  // NB: All position are in absolute pixels coordinates (never using window coordinates internally)
770  // 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.
771  IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
772  IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width);
773  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);
774  IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
775  IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f);
776  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);
777  IMGUI_API void RenderCollapseTriangle(ImVec2 pos, bool is_open, float scale = 1.0f);
778  IMGUI_API void RenderBullet(ImVec2 pos);
779  IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col);
780  IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text.
781 
782  IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0);
783  IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0);
784  IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos, float radius);
785 
786  IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags = 0);
787  IMGUI_API bool SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power);
788  IMGUI_API bool SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format);
789 
790  IMGUI_API bool DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power);
791  IMGUI_API bool DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power);
792  IMGUI_API bool DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format);
793 
794  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);
795  IMGUI_API bool InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags);
796  IMGUI_API bool InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags);
797  IMGUI_API bool InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags);
798  IMGUI_API bool InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision);
799 
800  IMGUI_API void ColorTooltip(const char* text, const float col[4], ImGuiColorEditFlags flags);
801 
802  IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL);
803  IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging
805 
806  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);
807 
808  IMGUI_API int ParseFormatPrecision(const char* fmt, int default_value);
809  IMGUI_API float RoundScalar(float value, int decimal_precision);
810 
811 } // namespace ImGui
812 
813 // ImFontAtlas internals
816 IMGUI_API void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent);
819 
820 #ifdef __clang__
821 #pragma clang diagnostic pop
822 #endif
823 
824 #ifdef _MSC_VER
825 #pragma warning (pop)
826 #endif


Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)