Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

imgui.h 61KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. // ImGui library v1.31 wip
  2. // See .cpp file for commentary.
  3. // See ImGui::ShowTestWindow() for sample code.
  4. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
  5. // Get latest version at https://github.com/ocornut/imgui
  6. #pragma once
  7. struct ImDrawCmd;
  8. struct ImDrawList;
  9. struct ImFont;
  10. struct ImFontAtlas;
  11. struct ImGuiAabb;
  12. struct ImGuiIO;
  13. struct ImGuiStorage;
  14. struct ImGuiStyle;
  15. struct ImGuiWindow;
  16. #include "imconfig.h"
  17. #include <float.h> // FLT_MAX
  18. #include <stdarg.h> // va_list
  19. #include <stddef.h> // ptrdiff_t
  20. #include <stdlib.h> // NULL, malloc
  21. #include <string.h> // memset, memmove
  22. #ifndef IM_ASSERT
  23. #include <assert.h>
  24. #define IM_ASSERT(_EXPR) assert(_EXPR)
  25. #endif
  26. #ifndef IMGUI_API
  27. #define IMGUI_API
  28. #endif
  29. typedef unsigned int ImU32;
  30. typedef unsigned short ImWchar; // character for display
  31. typedef void* ImTextureID; // user data to refer to a texture (e.g. store your texture handle/id)
  32. typedef ImU32 ImGuiID; // unique ID used by widgets (typically hashed from a stack of string)
  33. typedef int ImGuiCol; // enum ImGuiCol_
  34. typedef int ImGuiStyleVar; // enum ImGuiStyleVar_
  35. typedef int ImGuiKey; // enum ImGuiKey_
  36. typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_
  37. typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_
  38. typedef int ImGuiSetCondition; // enum ImGuiSetCondition_
  39. typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_
  40. struct ImGuiTextEditCallbackData; // for advanced uses of InputText()
  41. struct ImVec2
  42. {
  43. float x, y;
  44. ImVec2() {}
  45. ImVec2(float _x, float _y) { x = _x; y = _y; }
  46. #ifdef IM_VEC2_CLASS_EXTRA
  47. IM_VEC2_CLASS_EXTRA
  48. #endif
  49. };
  50. struct ImVec4
  51. {
  52. float x, y, z, w;
  53. ImVec4() {}
  54. ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; }
  55. #ifdef IM_VEC4_CLASS_EXTRA
  56. IM_VEC4_CLASS_EXTRA
  57. #endif
  58. };
  59. namespace ImGui
  60. {
  61. // Proxy functions to access the MemAllocFn/MemFreeFn pointers in ImGui::GetIO(). The only reason they exist here is to allow ImVector<> to compile inline.
  62. IMGUI_API void* MemAlloc(size_t sz);
  63. IMGUI_API void MemFree(void* ptr);
  64. }
  65. // std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
  66. // Use '#define ImVector std::vector' if you want to use the STL type or your own type.
  67. // Our implementation does NOT call c++ constructors! because the data types we use don't need them (but that could be added as well). Only provide the minimum functionalities we need.
  68. #ifndef ImVector
  69. template<typename T>
  70. class ImVector
  71. {
  72. protected:
  73. size_t Size;
  74. size_t Capacity;
  75. T* Data;
  76. public:
  77. typedef T value_type;
  78. typedef value_type* iterator;
  79. typedef const value_type* const_iterator;
  80. ImVector() { Size = Capacity = 0; Data = NULL; }
  81. ~ImVector() { if (Data) ImGui::MemFree(Data); }
  82. inline bool empty() const { return Size == 0; }
  83. inline size_t size() const { return Size; }
  84. inline size_t capacity() const { return Capacity; }
  85. inline value_type& at(size_t i) { IM_ASSERT(i < Size); return Data[i]; }
  86. inline const value_type& at(size_t i) const { IM_ASSERT(i < Size); return Data[i]; }
  87. inline value_type& operator[](size_t i) { IM_ASSERT(i < Size); return Data[i]; }
  88. inline const value_type& operator[](size_t i) const { IM_ASSERT(i < Size); return Data[i]; }
  89. inline void clear() { if (Data) { Size = Capacity = 0; ImGui::MemFree(Data); Data = NULL; } }
  90. inline iterator begin() { return Data; }
  91. inline const_iterator begin() const { return Data; }
  92. inline iterator end() { return Data + Size; }
  93. inline const_iterator end() const { return Data + Size; }
  94. inline value_type& front() { IM_ASSERT(Size > 0); return Data[0]; }
  95. inline const value_type& front() const { IM_ASSERT(Size > 0); return Data[0]; }
  96. inline value_type& back() { IM_ASSERT(Size > 0); return Data[Size-1]; }
  97. inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size-1]; }
  98. inline void swap(ImVector<T>& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; }
  99. inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; }
  100. inline void reserve(size_t new_capacity)
  101. {
  102. if (new_capacity <= Capacity) return;
  103. T* new_data = (value_type*)ImGui::MemAlloc(new_capacity * sizeof(value_type));
  104. memcpy(new_data, Data, Size * sizeof(value_type));
  105. ImGui::MemFree(Data);
  106. Data = new_data;
  107. Capacity = new_capacity;
  108. }
  109. inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; }
  110. inline void pop_back() { IM_ASSERT(Size > 0); Size--; }
  111. inline iterator erase(const_iterator it) { IM_ASSERT(it >= begin() && it < end()); const ptrdiff_t off = it - begin(); memmove(Data + off, Data + off + 1, (Size - (size_t)off - 1) * sizeof(value_type)); Size--; return Data + off; }
  112. inline iterator insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= begin() && it <= end()); const ptrdiff_t off = it - begin(); if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); if (off < (int)Size) memmove(Data + off + 1, Data + off, (Size - (size_t)off) * sizeof(value_type)); Data[off] = v; Size++; return Data + off; }
  113. };
  114. #endif // #ifndef ImVector
  115. // Helpers at bottom of the file:
  116. // - IMGUI_ONCE_UPON_A_FRAME // Execute a block of code once per frame only (convenient for creating UI within deep-nested code that runs multiple times)
  117. // - struct ImGuiTextFilter // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
  118. // - struct ImGuiTextBuffer // Text buffer for logging/accumulating text
  119. // - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
  120. // - struct ImDrawList // Draw command list
  121. // - struct ImFont // TTF font loader, bake glyphs into bitmap
  122. // ImGui End-user API
  123. // In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types)
  124. namespace ImGui
  125. {
  126. // Main
  127. IMGUI_API ImGuiIO& GetIO();
  128. IMGUI_API ImGuiStyle& GetStyle();
  129. IMGUI_API void NewFrame();
  130. IMGUI_API void Render();
  131. IMGUI_API void Shutdown();
  132. IMGUI_API void ShowUserGuide();
  133. IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL);
  134. IMGUI_API void ShowTestWindow(bool* open = NULL);
  135. // Window
  136. IMGUI_API bool Begin(const char* name = "Debug", bool* p_opened = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0);// return false when window is collapsed, so you can early out in your code. passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
  137. IMGUI_API void End();
  138. IMGUI_API void BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). on each axis.
  139. IMGUI_API void EndChild();
  140. IMGUI_API bool GetWindowIsFocused();
  141. IMGUI_API ImVec2 GetContentRegionMax(); // window or current column boundaries
  142. IMGUI_API ImVec2 GetWindowContentRegionMin(); // window boundaries
  143. IMGUI_API ImVec2 GetWindowContentRegionMax();
  144. IMGUI_API ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives.
  145. IMGUI_API ImFont* GetWindowFont();
  146. IMGUI_API float GetWindowFontSize();
  147. IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows.
  148. IMGUI_API ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to do your own drawing.
  149. IMGUI_API ImVec2 GetWindowSize(); // get current window position.
  150. IMGUI_API float GetWindowWidth();
  151. IMGUI_API bool GetWindowCollapsed();
  152. IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set current window position - call within Begin()/End().
  153. IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set current window size. set to ImVec2(0,0) to force an auto-fit
  154. IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set current window collapsed state.
  155. IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set next window position - call before Begin().
  156. IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit
  157. IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set next window collapsed state.
  158. IMGUI_API void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position.
  159. IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget.
  160. IMGUI_API void SetStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
  161. IMGUI_API ImGuiStorage* GetStateStorage();
  162. // Parameters stacks (shared)
  163. IMGUI_API void PushFont(ImFont* font); // use NULL as a shortcut to push default font
  164. IMGUI_API void PopFont();
  165. IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4& col);
  166. IMGUI_API void PopStyleColor(int count = 1);
  167. IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val);
  168. IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val);
  169. IMGUI_API void PopStyleVar(int count = 1);
  170. // Parameters stacks (current window)
  171. IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case. default to ~2/3 of windows width.
  172. IMGUI_API void PopItemWidth();
  173. IMGUI_API float GetItemWidth();
  174. IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets.
  175. IMGUI_API void PopAllowKeyboardFocus();
  176. IMGUI_API void PushTextWrapPos(float wrap_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space.
  177. IMGUI_API void PopTextWrapPos();
  178. // Tooltip
  179. IMGUI_API void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins.
  180. IMGUI_API void SetTooltipV(const char* fmt, va_list args);
  181. IMGUI_API void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text.
  182. IMGUI_API void EndTooltip();
  183. // Layout
  184. IMGUI_API void Separator(); // horizontal line
  185. IMGUI_API void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets to layout them horizontally
  186. IMGUI_API void Spacing();
  187. IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns
  188. IMGUI_API void NextColumn(); // next column
  189. IMGUI_API float GetColumnOffset(int column_index = -1);
  190. IMGUI_API void SetColumnOffset(int column_index, float offset);
  191. IMGUI_API float GetColumnWidth(int column_index = -1);
  192. IMGUI_API ImVec2 GetCursorPos(); // cursor position is relative to window position
  193. IMGUI_API void SetCursorPos(const ImVec2& pos); // "
  194. IMGUI_API void SetCursorPosX(float x); // "
  195. IMGUI_API void SetCursorPosY(float y); // "
  196. IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in absolute screen coordinates (0..io.DisplaySize)
  197. IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute screen coordinates (0..io.DisplaySize)
  198. IMGUI_API void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets.
  199. IMGUI_API float GetTextLineSpacing();
  200. IMGUI_API float GetTextLineHeight();
  201. // ID scopes
  202. // If you are creating repeated widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them.
  203. // You can also use ## within your widget name to distinguish them from each others (see 'Programmer Guide')
  204. IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack!
  205. IMGUI_API void PushID(const void* ptr_id);
  206. IMGUI_API void PushID(const int int_id);
  207. IMGUI_API void PopID();
  208. IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). useful if you want to query into ImGuiStorage yourself. otherwise rarely needed.
  209. IMGUI_API ImGuiID GetID(const void* ptr_id);
  210. // Widgets
  211. IMGUI_API void Text(const char* fmt, ...);
  212. IMGUI_API void TextV(const char* fmt, va_list args);
  213. IMGUI_API void TextColored(const ImVec4& col, const char* fmt, ...); // shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
  214. IMGUI_API void TextColoredV(const ImVec4& col, const char* fmt, va_list args);
  215. IMGUI_API void TextWrapped(const char* fmt, ...); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();
  216. IMGUI_API void TextWrappedV(const char* fmt, va_list args);
  217. IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text.
  218. IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets
  219. IMGUI_API void LabelTextV(const char* label, const char* fmt, va_list args);
  220. IMGUI_API void BulletText(const char* fmt, ...);
  221. IMGUI_API void BulletTextV(const char* fmt, va_list args);
  222. IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0), bool repeat_when_held = false);
  223. IMGUI_API bool SmallButton(const char* label);
  224. IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size);
  225. IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
  226. IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,1)); // <0 frame_padding uses default frame padding settings. 0 for no paddnig.
  227. IMGUI_API bool CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false);
  228. IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders.
  229. IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
  230. IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
  231. IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
  232. IMGUI_API bool SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); // *v in radians
  233. IMGUI_API bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f");
  234. IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format = "%.0f");
  235. IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format = "%.0f");
  236. IMGUI_API bool SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format = "%.0f");
  237. IMGUI_API void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
  238. IMGUI_API void PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
  239. IMGUI_API void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
  240. IMGUI_API void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
  241. IMGUI_API bool Checkbox(const char* label, bool* v);
  242. IMGUI_API bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
  243. IMGUI_API bool RadioButton(const char* label, bool active);
  244. IMGUI_API bool RadioButton(const char* label, int* v, int v_button);
  245. IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, void (*callback)(ImGuiTextEditCallbackData*) = NULL, void* user_data = NULL);
  246. IMGUI_API bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0);
  247. IMGUI_API bool InputFloat2(const char* label, float v[2], int decimal_precision = -1);
  248. IMGUI_API bool InputFloat3(const char* label, float v[3], int decimal_precision = -1);
  249. IMGUI_API bool InputFloat4(const char* label, float v[4], int decimal_precision = -1);
  250. IMGUI_API bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100, ImGuiInputTextFlags extra_flags = 0);
  251. IMGUI_API bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items = 7);
  252. IMGUI_API bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items = 7); // separate items with \0, end item-list with \0\0
  253. IMGUI_API bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_height_items = 7);
  254. IMGUI_API bool ColorButton(const ImVec4& col, bool small_height = false, bool outline_border = true);
  255. IMGUI_API bool ColorEdit3(const char* label, float col[3]);
  256. IMGUI_API bool ColorEdit4(const char* label, float col[4], bool show_alpha = true);
  257. IMGUI_API void ColorEditMode(ImGuiColorEditMode mode);
  258. IMGUI_API bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop
  259. IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...); // "
  260. IMGUI_API bool TreeNode(const void* ptr_id, const char* fmt, ...); // "
  261. IMGUI_API bool TreeNodeV(const char* str_id, const char* fmt, va_list args); // "
  262. IMGUI_API bool TreeNodeV(const void* ptr_id, const char* fmt, va_list args); // "
  263. IMGUI_API void TreePush(const char* str_id = NULL); // already called by TreeNode(), but you can call Push/Pop yourself for layouting purpose
  264. IMGUI_API void TreePush(const void* ptr_id = NULL); // "
  265. IMGUI_API void TreePop();
  266. IMGUI_API void OpenNextNode(bool open); // force open/close the next TreeNode or CollapsingHeader
  267. // Value() Helpers: output single value in "name: value" format. Tip: freely declare your own within the ImGui namespace!
  268. IMGUI_API void Value(const char* prefix, bool b);
  269. IMGUI_API void Value(const char* prefix, int v);
  270. IMGUI_API void Value(const char* prefix, unsigned int v);
  271. IMGUI_API void Value(const char* prefix, float v, const char* float_format = NULL);
  272. IMGUI_API void Color(const char* prefix, const ImVec4& v);
  273. IMGUI_API void Color(const char* prefix, unsigned int v);
  274. // Logging: All text output from your interface are redirected to tty/file/clipboard. Tree nodes are automatically opened.
  275. IMGUI_API void LogToTTY(int max_depth = -1); // start logging to tty
  276. IMGUI_API void LogToFile(int max_depth = -1, const char* filename = NULL); // start logging to file
  277. IMGUI_API void LogToClipboard(int max_depth = -1); // start logging to OS clipboard
  278. IMGUI_API void LogFinish(); // stop logging (close file, etc.)
  279. IMGUI_API void LogButtons(); // helper to display buttons for logging to tty/file/clipboard
  280. IMGUI_API void LogText(const char* fmt, ...); // pass text data straight to log (without being displayed)
  281. // Utilities
  282. IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse?
  283. IMGUI_API bool IsItemActive(); // was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false)
  284. IMGUI_API ImVec2 GetItemBoxMin(); // get bounding box of last item
  285. IMGUI_API ImVec2 GetItemBoxMax(); // get bounding box of last item
  286. IMGUI_API bool IsClipped(const ImVec2& item_size); // to perform coarse clipping on user's side (as an optimization)
  287. IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry
  288. IMGUI_API bool IsMouseClicked(int button, bool repeat = false);
  289. IMGUI_API bool IsMouseDoubleClicked(int button);
  290. IMGUI_API bool IsMouseHoveringWindow(); // is mouse hovering current window ("window" in API names always refer to current window)
  291. IMGUI_API bool IsMouseHoveringAnyWindow(); // is mouse hovering any active imgui window
  292. IMGUI_API bool IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max); // is mouse hovering given bounding box
  293. IMGUI_API bool IsPosHoveringAnyWindow(const ImVec2& pos); // is given position hovering any active imgui window
  294. IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
  295. IMGUI_API float GetTime();
  296. IMGUI_API int GetFrameCount();
  297. IMGUI_API const char* GetStyleColName(ImGuiCol idx);
  298. IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f);
  299. IMGUI_API ImU32 ColorConvertFloat4ToU32(const ImVec4& in);
  300. IMGUI_API void ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v);
  301. IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b);
  302. // Obsolete (will be removed)
  303. IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
  304. } // namespace ImGui
  305. // Flags for ImGui::Begin()
  306. enum ImGuiWindowFlags_
  307. {
  308. // Default: 0
  309. ImGuiWindowFlags_NoTitleBar = 1 << 0, // Disable title-bar
  310. ImGuiWindowFlags_NoResize = 1 << 1, // Disable user resizing with the lower-right grip
  311. ImGuiWindowFlags_NoMove = 1 << 2, // Disable user moving the window
  312. ImGuiWindowFlags_NoScrollbar = 1 << 3, // Disable scroll bar (window can still scroll with mouse or programatically)
  313. ImGuiWindowFlags_NoScrollWithMouse = 1 << 4, // Disable user scrolling with mouse wheel
  314. ImGuiWindowFlags_NoCollapse = 1 << 5, // Disable user collapsing window by double-clicking on it
  315. ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame
  316. ImGuiWindowFlags_ShowBorders = 1 << 7, // Show borders around windows and items
  317. ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file
  318. // [Internal]
  319. ImGuiWindowFlags_ChildWindow = 1 << 9, // For internal use by BeginChild()
  320. ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 10, // For internal use by BeginChild()
  321. ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 11, // For internal use by BeginChild()
  322. ImGuiWindowFlags_ComboBox = 1 << 12, // For internal use by ComboBox()
  323. ImGuiWindowFlags_Tooltip = 1 << 13 // For internal use by BeginTooltip()
  324. };
  325. // Flags for ImGui::InputText()
  326. enum ImGuiInputTextFlags_
  327. {
  328. // Default: 0
  329. ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/
  330. ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef
  331. ImGuiInputTextFlags_AutoSelectAll = 1 << 2, // Select entire text when first taking focus
  332. ImGuiInputTextFlags_EnterReturnsTrue = 1 << 3, // Return 'true' when Enter is pressed (as opposed to when the value was modified)
  333. ImGuiInputTextFlags_CallbackCompletion = 1 << 4, // Call user function on pressing TAB (for completion handling)
  334. ImGuiInputTextFlags_CallbackHistory = 1 << 5, // Call user function on pressing Up/Down arrows (for history handling)
  335. ImGuiInputTextFlags_CallbackAlways = 1 << 6 // Call user function every time
  336. //ImGuiInputTextFlags_AlignCenter = 1 << 6,
  337. };
  338. // User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array
  339. enum ImGuiKey_
  340. {
  341. ImGuiKey_Tab,
  342. ImGuiKey_LeftArrow,
  343. ImGuiKey_RightArrow,
  344. ImGuiKey_UpArrow,
  345. ImGuiKey_DownArrow,
  346. ImGuiKey_Home,
  347. ImGuiKey_End,
  348. ImGuiKey_Delete,
  349. ImGuiKey_Backspace,
  350. ImGuiKey_Enter,
  351. ImGuiKey_Escape,
  352. ImGuiKey_A, // for CTRL+A: select all
  353. ImGuiKey_C, // for CTRL+C: copy
  354. ImGuiKey_V, // for CTRL+V: paste
  355. ImGuiKey_X, // for CTRL+X: cut
  356. ImGuiKey_Y, // for CTRL+Y: redo
  357. ImGuiKey_Z, // for CTRL+Z: undo
  358. ImGuiKey_COUNT
  359. };
  360. // Enumeration for PushStyleColor() / PopStyleColor()
  361. enum ImGuiCol_
  362. {
  363. ImGuiCol_Text,
  364. ImGuiCol_WindowBg,
  365. ImGuiCol_Border,
  366. ImGuiCol_BorderShadow,
  367. ImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input
  368. ImGuiCol_TitleBg,
  369. ImGuiCol_TitleBgCollapsed,
  370. ImGuiCol_ScrollbarBg,
  371. ImGuiCol_ScrollbarGrab,
  372. ImGuiCol_ScrollbarGrabHovered,
  373. ImGuiCol_ScrollbarGrabActive,
  374. ImGuiCol_ComboBg,
  375. ImGuiCol_CheckHovered,
  376. ImGuiCol_CheckActive,
  377. ImGuiCol_CheckMark,
  378. ImGuiCol_SliderGrab,
  379. ImGuiCol_SliderGrabActive,
  380. ImGuiCol_Button,
  381. ImGuiCol_ButtonHovered,
  382. ImGuiCol_ButtonActive,
  383. ImGuiCol_Header,
  384. ImGuiCol_HeaderHovered,
  385. ImGuiCol_HeaderActive,
  386. ImGuiCol_Column,
  387. ImGuiCol_ColumnHovered,
  388. ImGuiCol_ColumnActive,
  389. ImGuiCol_ResizeGrip,
  390. ImGuiCol_ResizeGripHovered,
  391. ImGuiCol_ResizeGripActive,
  392. ImGuiCol_CloseButton,
  393. ImGuiCol_CloseButtonHovered,
  394. ImGuiCol_CloseButtonActive,
  395. ImGuiCol_PlotLines,
  396. ImGuiCol_PlotLinesHovered,
  397. ImGuiCol_PlotHistogram,
  398. ImGuiCol_PlotHistogramHovered,
  399. ImGuiCol_TextSelectedBg,
  400. ImGuiCol_TooltipBg,
  401. ImGuiCol_COUNT
  402. };
  403. // Enumeration for PushStyleVar() / PopStyleVar()
  404. // NB: the enum only refers to fields of ImGuiStyle() which makes sense to be pushed/poped in UI code. Feel free to add others.
  405. enum ImGuiStyleVar_
  406. {
  407. ImGuiStyleVar_Alpha, // float
  408. ImGuiStyleVar_WindowPadding, // ImVec2
  409. ImGuiStyleVar_WindowRounding, // float
  410. ImGuiStyleVar_FramePadding, // ImVec2
  411. ImGuiStyleVar_FrameRounding, // float
  412. ImGuiStyleVar_ItemSpacing, // ImVec2
  413. ImGuiStyleVar_ItemInnerSpacing, // ImVec2
  414. ImGuiStyleVar_TreeNodeSpacing // float
  415. };
  416. // Enumeration for ColorEditMode()
  417. enum ImGuiColorEditMode_
  418. {
  419. ImGuiColorEditMode_UserSelect = -2,
  420. ImGuiColorEditMode_UserSelectShowButton = -1,
  421. ImGuiColorEditMode_RGB = 0,
  422. ImGuiColorEditMode_HSV = 1,
  423. ImGuiColorEditMode_HEX = 2
  424. };
  425. // Condition flags for ImGui::SetWindow***() and SetNextWindow***() functions
  426. // Those functions treat 0 as a shortcut to ImGuiSetCondition_Always
  427. enum ImGuiSetCondition_
  428. {
  429. ImGuiSetCondition_Always = 1 << 0, // Set the variable
  430. ImGuiSetCondition_FirstUseThisSession = 1 << 1, // Only set the variable on the first call for this window (once per session)
  431. ImGuiSetCondition_FirstUseEver = 1 << 2 // Only set the variable if the window doesn't exist in the .ini file
  432. };
  433. struct ImGuiStyle
  434. {
  435. float Alpha; // Global alpha applies to everything in ImGui
  436. ImVec2 WindowPadding; // Padding within a window
  437. ImVec2 WindowMinSize; // Minimum window size
  438. float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
  439. ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets)
  440. float FrameRounding; // Radius of frame corners rounding. Set to 0.0f to have rectangular frame (used by most widgets).
  441. ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines
  442. ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
  443. ImVec2 TouchExtraPadding; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much!
  444. ImVec2 AutoFitPadding; // Extra space after auto-fit (double-clicking on resize grip)
  445. float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin()
  446. float TreeNodeSpacing; // Horizontal spacing when entering a tree node
  447. float ColumnsMinSpacing; // Minimum horizontal spacing between two columns
  448. float ScrollBarWidth; // Width of the vertical scroll bar
  449. ImVec4 Colors[ImGuiCol_COUNT];
  450. IMGUI_API ImGuiStyle();
  451. };
  452. // This is where your app communicate with ImGui. Call ImGui::GetIO() to access.
  453. // Read 'Programmer guide' section in .cpp file for general usage.
  454. struct ImGuiIO
  455. {
  456. //------------------------------------------------------------------
  457. // Settings (fill once) // Default value:
  458. //------------------------------------------------------------------
  459. ImVec2 DisplaySize; // <unset> // Display size, in pixels. For clamping windows positions.
  460. float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds.
  461. float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds.
  462. const char* IniFilename; // = "imgui.ini" // Path to .ini file. NULL to disable .ini saving.
  463. const char* LogFilename; // = "imgui_log.txt" // Path to .log file (default parameter to ImGui::LogToFile when no file is specified).
  464. float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds.
  465. float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
  466. int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
  467. void* UserData; // = NULL // Store your own data for retrieval by callbacks.
  468. ImFontAtlas* Fonts; // <auto> // Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array.
  469. float FontGlobalScale; // = 1.0f // Global scale all fonts
  470. bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel.
  471. ImVec2 DisplayVisibleMin; // <unset> (0.0f,0.0f) // If you use DisplaySize as a virtual space larger than your screen, set DisplayVisibleMin/Max to the visible area.
  472. ImVec2 DisplayVisibleMax; // <unset> (0.0f,0.0f) // If the values are the same, we defaults to Min=(0.0f) and Max=DisplaySize
  473. //------------------------------------------------------------------
  474. // User Functions
  475. //------------------------------------------------------------------
  476. // REQUIRED: rendering function.
  477. // See example code if you are unsure of how to implement this.
  478. void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);
  479. // Optional: access OS clipboard (default to use native Win32 clipboard on Windows, otherwise use a ImGui private clipboard)
  480. // Override to access OS clipboard on other architectures.
  481. const char* (*GetClipboardTextFn)();
  482. void (*SetClipboardTextFn)(const char* text);
  483. // Optional: override memory allocations (default to posix malloc/free). MemFreeFn() may be called with a NULL pointer.
  484. void* (*MemAllocFn)(size_t sz);
  485. void (*MemFreeFn)(void* ptr);
  486. // Optional: notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese inputs in Windows)
  487. void (*ImeSetInputScreenPosFn)(int x, int y);
  488. //------------------------------------------------------------------
  489. // Input - Fill before calling NewFrame()
  490. //------------------------------------------------------------------
  491. ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
  492. bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience.
  493. float MouseWheel; // Mouse wheel: 1 unit scrolls about 5 lines text.
  494. bool MouseDrawCursor; // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor).
  495. bool KeyCtrl; // Keyboard modifier pressed: Control
  496. bool KeyShift; // Keyboard modifier pressed: Shift
  497. bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
  498. ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
  499. // Function
  500. IMGUI_API void AddInputCharacter(ImWchar c); // Helper to add a new character into InputCharacters[]
  501. //------------------------------------------------------------------
  502. // Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application
  503. //------------------------------------------------------------------
  504. bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
  505. bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input)
  506. //------------------------------------------------------------------
  507. // [Internal] ImGui will maintain those fields for you
  508. //------------------------------------------------------------------
  509. ImVec2 MousePosPrev; //
  510. ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are negative to allow mouse enabling/disabling.
  511. bool MouseClicked[5]; // Mouse button went from !Down to Down
  512. ImVec2 MouseClickedPos[5]; // Position at time of clicking
  513. float MouseClickedTime[5]; // Time of last click (used to figure out double-click)
  514. bool MouseDoubleClicked[5]; // Has mouse button been double-clicked?
  515. bool MouseDownOwned[5]; // Track if button was clicked inside a window. We don't request mouse capture from the application if click started outside ImGui bounds.
  516. float MouseDownTime[5]; // Time the mouse button has been down
  517. float KeysDownTime[512]; // Time the keyboard key has been down
  518. IMGUI_API ImGuiIO();
  519. };
  520. //-----------------------------------------------------------------------------
  521. // Helpers
  522. //-----------------------------------------------------------------------------
  523. // Helper: execute a block of code once a frame only
  524. // Convenient if you want to quickly create an UI within deep-nested code that runs multiple times every frame.
  525. // Usage:
  526. // IMGUI_ONCE_UPON_A_FRAME
  527. // {
  528. // // code block will be executed one per frame
  529. // }
  530. // Attention! the macro expands into 2 statement so make sure you don't use it within e.g. an if() statement without curly braces.
  531. #define IMGUI_ONCE_UPON_A_FRAME static ImGuiOnceUponAFrame imgui_oaf##__LINE__; if (imgui_oaf##__LINE__)
  532. struct ImGuiOnceUponAFrame
  533. {
  534. ImGuiOnceUponAFrame() { RefFrame = -1; }
  535. mutable int RefFrame;
  536. operator bool() const { const int current_frame = ImGui::GetFrameCount(); if (RefFrame == current_frame) return false; RefFrame = current_frame; return true; }
  537. };
  538. // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
  539. struct ImGuiTextFilter
  540. {
  541. struct TextRange
  542. {
  543. const char* b;
  544. const char* e;
  545. TextRange() { b = e = NULL; }
  546. TextRange(const char* _b, const char* _e) { b = _b; e = _e; }
  547. const char* begin() const { return b; }
  548. const char* end() const { return e; }
  549. bool empty() const { return b == e; }
  550. char front() const { return *b; }
  551. static bool isblank(char c) { return c == ' ' || c == '\t'; }
  552. void trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; }
  553. IMGUI_API void split(char separator, ImVector<TextRange>& out);
  554. };
  555. char InputBuf[256];
  556. ImVector<TextRange> Filters;
  557. int CountGrep;
  558. ImGuiTextFilter();
  559. void Clear() { InputBuf[0] = 0; Build(); }
  560. void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f); // Helper calling InputText+Build
  561. bool PassFilter(const char* val) const;
  562. bool IsActive() const { return !Filters.empty(); }
  563. IMGUI_API void Build();
  564. };
  565. // Helper: Text buffer for logging/accumulating text
  566. struct ImGuiTextBuffer
  567. {
  568. ImVector<char> Buf;
  569. ImGuiTextBuffer() { Buf.push_back(0); }
  570. ~ImGuiTextBuffer() { }
  571. const char* begin() const { return &Buf.front(); }
  572. const char* end() const { return &Buf.back(); } // Buf is zero-terminated, so end() will point on the zero-terminator
  573. size_t size() const { return Buf.size()-1; }
  574. bool empty() { return size() >= 1; }
  575. void clear() { Buf.clear(); Buf.push_back(0); }
  576. IMGUI_API void append(const char* fmt, ...);
  577. IMGUI_API void appendv(const char* fmt, va_list args);
  578. };
  579. // Helper: Key->value storage
  580. // - Store collapse state for a tree (Int 0/1)
  581. // - Store color edit options (Int using values in ImGuiColorEditMode enum).
  582. // - Custom user storage for temporary values.
  583. // Typically you don't have to worry about this since a storage is held within each Window.
  584. // Declare your own storage if:
  585. // - You want to manipulate the open/close state of a particular sub-tree in your interface (tree node uses Int 0/1 to store their state).
  586. // - You want to store custom debug data easily without adding or editing structures in your code.
  587. struct ImGuiStorage
  588. {
  589. struct Pair
  590. {
  591. ImGuiID key;
  592. union { int val_i; float val_f; void* val_p; };
  593. Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
  594. Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
  595. Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
  596. };
  597. ImVector<Pair> Data;
  598. // - Get***() functions find pair, never add/allocate. Pairs are sorted so a query is O(log N)
  599. // - Set***() functions find pair, insertion on demand if missing.
  600. // - Sorted insertion is costly but should amortize. A typical frame shouldn't need to insert any new pair.
  601. IMGUI_API void Clear();
  602. IMGUI_API int GetInt(ImGuiID key, int default_val = 0) const;
  603. IMGUI_API void SetInt(ImGuiID key, int val);
  604. IMGUI_API float GetFloat(ImGuiID key, float default_val = 0.0f) const;
  605. IMGUI_API void SetFloat(ImGuiID key, float val);
  606. IMGUI_API void* GetVoidPtr(ImGuiID key) const; // default_val is NULL
  607. IMGUI_API void SetVoidPtr(ImGuiID key, void* val);
  608. // - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set.
  609. // - References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer.
  610. // - A typical use case where this is convenient:
  611. // float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar;
  612. // - You can also use this to quickly create temporary editable values during a session of using Edit&Continue, without restarting your application.
  613. IMGUI_API int* GetIntRef(ImGuiID key, int default_val = 0);
  614. IMGUI_API float* GetFloatRef(ImGuiID key, float default_val = 0);
  615. // Use on your own storage if you know only integer are being stored (open/close all tree nodes)
  616. IMGUI_API void SetAllInt(int val);
  617. };
  618. // Shared state of InputText(), passed to callback when a ImGuiInputTextFlags_Callback* flag is used.
  619. struct ImGuiTextEditCallbackData
  620. {
  621. ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only
  622. char* Buf; // Current text // Read-write (pointed data only)
  623. size_t BufSize; // // Read-only
  624. bool BufDirty; // Set if you modify Buf directly // Write
  625. ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only
  626. int CursorPos; // // Read-write
  627. int SelectionStart; // // Read-write (== to SelectionEnd when no selection)
  628. int SelectionEnd; // // Read-write
  629. void* UserData; // What user passed to InputText()
  630. // NB: calling those function loses selection.
  631. void DeleteChars(int pos, int bytes_count);
  632. void InsertChars(int pos, const char* text, const char* text_end = NULL);
  633. };
  634. // ImColor() is just a helper that implicity converts to either ImU32 (packed 4x1 byte) or ImVec4 (4x1 float)
  635. // None of the ImGui API are using ImColor directly but you can use it as a convenience to pass colors in either formats.
  636. struct ImColor
  637. {
  638. ImVec4 Value;
  639. ImColor(int r, int g, int b, int a = 255) { Value.x = (float)r / 255.0f; Value.y = (float)g / 255.0f; Value.z = (float)b / 255.0f; Value.w = (float)a / 255.0f; }
  640. ImColor(float r, float g, float b, float a = 1.0f) { Value.x = r; Value.y = g; Value.z = b; Value.w = a; }
  641. ImColor(const ImVec4& col) { Value = col; }
  642. operator ImU32() const { return ImGui::ColorConvertFloat4ToU32(Value); }
  643. operator ImVec4() const { return Value; }
  644. static ImColor HSV(float h, float s, float v, float a = 1.0f) { float r,g,b; ImGui::ColorConvertHSVtoRGB(h, s, v, r, g, b); return ImColor(r,g,b,a); }
  645. };
  646. //-----------------------------------------------------------------------------
  647. // Draw List
  648. // Hold a series of drawing commands. The user provides a renderer for ImDrawList.
  649. //-----------------------------------------------------------------------------
  650. // Draw callbacks for advanced uses.
  651. // NB- You most likely DO NOT need to care about draw callbacks just to create your own widget or customized UI rendering (you can poke into the draw list for that)
  652. // Draw callback are useful for example if you want to render a complex 3D scene inside a UI element.
  653. // The expected behavior from your rendering loop is:
  654. // if (cmd.user_callback != NULL)
  655. // cmd.user_callback(parent_list, cmd);
  656. // else
  657. // RenderTriangles()
  658. // It is up to you to decide if your rendering loop or the callback should be responsible for backup/restoring rendering state.
  659. typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd);
  660. // Typically, 1 command = 1 gpu draw call
  661. struct ImDrawCmd
  662. {
  663. unsigned int vtx_count; // Number of vertices (multiple of 3) to be drawn as triangles. The vertices are stored in the callee ImDrawList's vtx_buffer[] array.
  664. ImVec4 clip_rect; // Clipping rectangle (x1, y1, x2, y2)
  665. ImTextureID texture_id; // User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions. Ignore if never using images or multiple fonts atlas.
  666. ImDrawCallback user_callback; // If != NULL, call the function instead of rendering the vertices. vtx_count will be 0. clip_rect and texture_id will be set normally.
  667. void* user_callback_data; // The draw callback code can access this.
  668. };
  669. // Vertex layout
  670. #ifndef IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT
  671. struct ImDrawVert
  672. {
  673. ImVec2 pos;
  674. ImVec2 uv;
  675. ImU32 col;
  676. };
  677. #else
  678. // You can change the vertex format layout by defining IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT in imconfig.h
  679. // The code expect ImVec2 pos (8 bytes), ImVec2 uv (8 bytes), ImU32 col (4 bytes), but you can re-order them or add other fields as needed to simplify integration in your engine.
  680. // The type has to be described by the #define (you can either declare the struct or use a typedef)
  681. IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT;
  682. #endif
  683. // Draw command list
  684. // This is the low-level list of polygons that ImGui functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering.
  685. // At the moment, each ImGui window contains its own ImDrawList but they could potentially be merged in the future.
  686. // If you want to add custom rendering within a window, you can use ImGui::GetWindowDrawList() to access the current draw list and add your own primitives.
  687. // You can interleave normal ImGui:: calls and adding primitives to the current draw list.
  688. // Note that this only gives you access to rendering polygons. If your intent is to create custom widgets and the publicly exposed functions/data aren't sufficient, you can add code in imgui_user.inl
  689. struct ImDrawList
  690. {
  691. // This is what you have to render
  692. ImVector<ImDrawCmd> commands; // Commands. Typically 1 command = 1 gpu draw call.
  693. ImVector<ImDrawVert> vtx_buffer; // Vertex buffer. Each command consume ImDrawCmd::vtx_count of those
  694. // [Internal to ImGui]
  695. ImVector<ImVec4> clip_rect_stack; // [Internal]
  696. ImVector<ImTextureID> texture_id_stack; // [Internal]
  697. ImDrawVert* vtx_write; // [Internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much)
  698. ImDrawList() { Clear(); }
  699. IMGUI_API void Clear();
  700. IMGUI_API void PushClipRect(const ImVec4& clip_rect); // Scissoring. The values are x1, y1, x2, y2.
  701. IMGUI_API void PopClipRect();
  702. IMGUI_API void PushTextureID(const ImTextureID& texture_id);
  703. IMGUI_API void PopTextureID();
  704. // Primitives
  705. IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col);
  706. IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
  707. IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
  708. IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col);
  709. IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
  710. IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
  711. IMGUI_API void AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris = false, const ImVec2& third_point_offset = ImVec2(0,0));
  712. IMGUI_API void AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f);
  713. IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col = 0xFFFFFFFF);
  714. // Advanced
  715. IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'user_callback' in ImDrawCmd and call the function instead of rendering triangles.
  716. IMGUI_API void AddDrawCmd(); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible
  717. // Internal helpers
  718. IMGUI_API void ReserveVertices(unsigned int vtx_count);
  719. IMGUI_API void AddVtx(const ImVec2& pos, ImU32 col);
  720. IMGUI_API void AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv);
  721. IMGUI_API void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col);
  722. IMGUI_API void UpdateClipRect();
  723. IMGUI_API void UpdateTextureID();
  724. };
  725. // Load and rasterize multiple TTF fonts into a same texture.
  726. // Sharing a texture for multiple fonts allows us to reduce the number of draw calls during rendering.
  727. // We also add custom graphic data into the texture that serves for ImGui.
  728. // 1. (Optional) Call AddFont*** functions. If you don't call any, the default font will be loaded for you.
  729. // 2. Call GetTexDataAsAlpha8() or GetTexDataAsRGBA32() to build and retrieve pixels data.
  730. // 3. Upload the pixels data into a texture within your graphics system.
  731. // 4. Call SetTexID(my_tex_id); and pass the pointer/identifier to your texture. This value will be passed back to you during rendering to identify the texture.
  732. // 5. Call ClearPixelsData() to free textures memory on the heap.
  733. struct ImFontAtlas
  734. {
  735. IMGUI_API ImFontAtlas();
  736. IMGUI_API ~ImFontAtlas();
  737. IMGUI_API ImFont* AddFontDefault();
  738. IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0);
  739. IMGUI_API ImFont* AddFontFromMemoryTTF(void* in_ttf_data, size_t in_ttf_data_size, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0); // Pass ownership of 'in_ttf_data' memory.
  740. IMGUI_API void ClearTexData(); // Saves RAM once the texture has been copied to graphics memory.
  741. IMGUI_API void Clear();
  742. // Retrieve texture data
  743. // User is in charge of copying the pixels into graphics memory, then call SetTextureUserID()
  744. // After loading the texture into your graphic system, store your texture handle in 'TexID' (ignore if you aren't using multiple fonts nor images)
  745. // RGBA32 format is provided for convenience and high compatibility, but note that all RGB pixels are white, so 75% of the memory is wasted.
  746. // Pitch = Width * BytesPerPixels
  747. IMGUI_API void GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 1 byte per-pixel
  748. IMGUI_API void GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 4 bytes-per-pixel
  749. IMGUI_API void SetTexID(void* id) { TexID = id; }
  750. // Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
  751. // (Those functions could be static, aren't so simple use case doesn't have to refer to the ImFontAtlas:: type ever if in their code)
  752. IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin
  753. IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
  754. IMGUI_API const ImWchar* GetGlyphRangesChinese(); // Japanese + full set of about 21000 CJK Unified Ideographs
  755. // Members
  756. // (Access texture data via GetTexData*() calls which will setup a default font for you.)
  757. void* TexID; // User data to refer to the texture once it has been uploaded to user's graphic systems. It ia passed back to you during rendering.
  758. unsigned char* TexPixelsAlpha8; // 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight
  759. unsigned int* TexPixelsRGBA32; // 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
  760. int TexWidth;
  761. int TexHeight;
  762. ImVec2 TexExtraDataPos; // Position of our rectangle where we draw non-font graphics
  763. ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block)
  764. ImVector<ImFont*> Fonts;
  765. // Private
  766. struct ImFontAtlasData;
  767. ImVector<ImFontAtlasData*> InputData; // Internal data
  768. IMGUI_API bool Build(); // Build pixels data. This is automatically for you by the GetTexData*** functions.
  769. IMGUI_API void ClearInputData(); // Clear the input TTF data.
  770. IMGUI_API void RenderCustomTexData();
  771. };
  772. // TTF font loading and rendering
  773. // ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
  774. // Kerning isn't supported. At the moment some ImGui code does per-character CalcTextSize calls, need something more state-ful.
  775. struct ImFont
  776. {
  777. // Members: Settings
  778. float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
  779. float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
  780. ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels
  781. ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found.
  782. // Members: Runtime data
  783. struct Glyph
  784. {
  785. ImWchar Codepoint;
  786. signed short XAdvance;
  787. signed short Width, Height;
  788. signed short XOffset, YOffset;
  789. float U0, V0, U1, V1; // Texture coordinates
  790. };
  791. ImFontAtlas* ContainerAtlas; // What we has been loaded into
  792. ImVector<Glyph> Glyphs;
  793. ImVector<int> IndexLookup; // Index glyphs by Unicode code-point
  794. const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
  795. // Methods
  796. IMGUI_API ImFont();
  797. IMGUI_API ~ImFont() { Clear(); }
  798. IMGUI_API void Clear();
  799. IMGUI_API void BuildLookupTable();
  800. IMGUI_API const Glyph* FindGlyph(unsigned short c) const;
  801. IMGUI_API bool IsLoaded() const { return ContainerAtlas != NULL; }
  802. // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
  803. // 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
  804. IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL) const; // utf8
  805. IMGUI_API ImVec2 CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL) const; // wchar
  806. IMGUI_API void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices, float wrap_width = 0.0f) const;
  807. IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const;
  808. };
  809. //---- Include imgui_user.h at the end of imgui.h
  810. //---- So you can include code that extends ImGui using any of the types declared above.
  811. //---- (also convenient for user to only explicitly include vanilla imgui.h)
  812. #ifdef IMGUI_INCLUDE_IMGUI_USER_H
  813. #include "imgui_user.h"
  814. #endif