PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/Engine/imgui/imgui_demo.cpp

https://gitlab.com/Strider2342/PannonEngine
C++ | 1037 lines | 861 code | 120 blank | 56 comment | 136 complexity | c9240fb4fd0957c2544c4912ab4a2ddf MD5 | raw file
  1. // dear imgui, v1.50 WIP
  2. // (demo code)
  3. // Don't remove this file from your project! It is useful reference code that you can execute.
  4. // You can call ImGui::ShowTestWindow() in your code to learn about various features of ImGui.
  5. // Everything in this file will be stripped out by the linker if you don't call ImGui::ShowTestWindow().
  6. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  7. #define _CRT_SECURE_NO_WARNINGS
  8. #endif
  9. #include "imgui.h"
  10. #include <ctype.h> // toupper, isprint
  11. #include <math.h> // sqrtf, powf, cosf, sinf, floorf, ceilf
  12. #include <stdio.h> // vsnprintf, sscanf, printf
  13. #include <stdlib.h> // NULL, malloc, free, qsort, atoi
  14. #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
  15. #include <stddef.h> // intptr_t
  16. #else
  17. #include <stdint.h> // intptr_t
  18. #endif
  19. #ifdef _MSC_VER
  20. #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
  21. #define snprintf _snprintf
  22. #endif
  23. #ifdef __clang__
  24. #pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
  25. #pragma clang diagnostic ignored "-Wdeprecated-declarations" // warning : 'xx' is deprecated: The POSIX name for this item.. // for strdup used in demo code (so user can copy & paste the code)
  26. #pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning : cast to 'void *' from smaller integer type 'int'
  27. #pragma clang diagnostic ignored "-Wformat-security" // warning : warning: format string is not a string literal
  28. #pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals.
  29. #if __has_warning("-Wreserved-id-macro")
  30. #pragma clang diagnostic ignored "-Wreserved-id-macro" // warning : macro name is a reserved identifier //
  31. #endif
  32. #elif defined(__GNUC__)
  33. #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size
  34. #pragma GCC diagnostic ignored "-Wformat-security" // warning : format string is not a string literal (potentially insecure)
  35. #pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function
  36. #pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value
  37. #endif
  38. // Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
  39. #ifdef _WIN32
  40. #define IM_NEWLINE "\r\n"
  41. #else
  42. #define IM_NEWLINE "\n"
  43. #endif
  44. #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
  45. #define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B))
  46. //-----------------------------------------------------------------------------
  47. // DEMO CODE
  48. //-----------------------------------------------------------------------------
  49. #ifndef IMGUI_DISABLE_TEST_WINDOWS
  50. static void ShowExampleAppConsole(bool* p_open);
  51. static void ShowExampleAppLog(bool* p_open);
  52. static void ShowExampleAppLayout(bool* p_open);
  53. static void ShowExampleAppPropertyEditor(bool* p_open);
  54. static void ShowExampleAppLongText(bool* p_open);
  55. static void ShowExampleAppAutoResize(bool* p_open);
  56. static void ShowExampleAppConstrainedResize(bool* p_open);
  57. static void ShowExampleAppFixedOverlay(bool* p_open);
  58. static void ShowExampleAppManipulatingWindowTitle(bool* p_open);
  59. static void ShowExampleAppCustomRendering(bool* p_open);
  60. static void ShowExampleAppMainMenuBar();
  61. static void ShowExampleMenuFile();
  62. static void ShowHelpMarker(const char* desc)
  63. {
  64. ImGui::TextDisabled("(?)");
  65. if (ImGui::IsItemHovered())
  66. {
  67. ImGui::BeginTooltip();
  68. ImGui::PushTextWrapPos(450.0f);
  69. ImGui::TextUnformatted(desc);
  70. ImGui::PopTextWrapPos();
  71. ImGui::EndTooltip();
  72. }
  73. }
  74. void ImGui::ShowUserGuide()
  75. {
  76. ImGui::BulletText("Double-click on title bar to collapse window.");
  77. ImGui::BulletText("Click and drag on lower right corner to resize window.");
  78. ImGui::BulletText("Click and drag on any empty space to move window.");
  79. ImGui::BulletText("Mouse Wheel to scroll.");
  80. if (ImGui::GetIO().FontAllowUserScaling)
  81. ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
  82. ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
  83. ImGui::BulletText("CTRL+Click on a slider or drag box to input text.");
  84. ImGui::BulletText(
  85. "While editing text:\n"
  86. "- Hold SHIFT or use mouse to select text\n"
  87. "- CTRL+Left/Right to word jump\n"
  88. "- CTRL+A or double-click to select all\n"
  89. "- CTRL+X,CTRL+C,CTRL+V clipboard\n"
  90. "- CTRL+Z,CTRL+Y undo/redo\n"
  91. "- ESCAPE to revert\n"
  92. "- You can apply arithmetic operators +,*,/ on numerical values.\n"
  93. " Use +- to subtract.\n");
  94. }
  95. // Demonstrate most ImGui features (big function!)
  96. void ImGui::ShowTestWindow(bool* p_open)
  97. {
  98. // Examples apps
  99. static bool show_app_main_menu_bar = false;
  100. static bool show_app_console = false;
  101. static bool show_app_log = false;
  102. static bool show_app_layout = false;
  103. static bool show_app_property_editor = false;
  104. static bool show_app_long_text = false;
  105. static bool show_app_auto_resize = false;
  106. static bool show_app_constrained_resize = false;
  107. static bool show_app_fixed_overlay = false;
  108. static bool show_app_manipulating_window_title = false;
  109. static bool show_app_custom_rendering = false;
  110. static bool show_app_style_editor = false;
  111. static bool show_app_metrics = false;
  112. static bool show_app_about = false;
  113. if (show_app_main_menu_bar) ShowExampleAppMainMenuBar();
  114. if (show_app_console) ShowExampleAppConsole(&show_app_console);
  115. if (show_app_log) ShowExampleAppLog(&show_app_log);
  116. if (show_app_layout) ShowExampleAppLayout(&show_app_layout);
  117. if (show_app_property_editor) ShowExampleAppPropertyEditor(&show_app_property_editor);
  118. if (show_app_long_text) ShowExampleAppLongText(&show_app_long_text);
  119. if (show_app_auto_resize) ShowExampleAppAutoResize(&show_app_auto_resize);
  120. if (show_app_constrained_resize) ShowExampleAppConstrainedResize(&show_app_constrained_resize);
  121. if (show_app_fixed_overlay) ShowExampleAppFixedOverlay(&show_app_fixed_overlay);
  122. if (show_app_manipulating_window_title) ShowExampleAppManipulatingWindowTitle(&show_app_manipulating_window_title);
  123. if (show_app_custom_rendering) ShowExampleAppCustomRendering(&show_app_custom_rendering);
  124. if (show_app_metrics) ImGui::ShowMetricsWindow(&show_app_metrics);
  125. if (show_app_style_editor) { ImGui::Begin("Style Editor", &show_app_style_editor); ImGui::ShowStyleEditor(); ImGui::End(); }
  126. if (show_app_about)
  127. {
  128. ImGui::Begin("About ImGui", &show_app_about, ImGuiWindowFlags_AlwaysAutoResize);
  129. ImGui::Text("dear imgui, %s", ImGui::GetVersion());
  130. ImGui::Separator();
  131. ImGui::Text("By Omar Cornut and all github contributors.");
  132. ImGui::Text("ImGui is licensed under the MIT License, see LICENSE for more information.");
  133. ImGui::End();
  134. }
  135. static bool no_titlebar = false;
  136. static bool no_border = true;
  137. static bool no_resize = false;
  138. static bool no_move = false;
  139. static bool no_scrollbar = false;
  140. static bool no_collapse = false;
  141. static bool no_menu = false;
  142. // Demonstrate the various window flags. Typically you would just use the default.
  143. ImGuiWindowFlags window_flags = 0;
  144. if (no_titlebar) window_flags |= ImGuiWindowFlags_NoTitleBar;
  145. if (!no_border) window_flags |= ImGuiWindowFlags_ShowBorders;
  146. if (no_resize) window_flags |= ImGuiWindowFlags_NoResize;
  147. if (no_move) window_flags |= ImGuiWindowFlags_NoMove;
  148. if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar;
  149. if (no_collapse) window_flags |= ImGuiWindowFlags_NoCollapse;
  150. if (!no_menu) window_flags |= ImGuiWindowFlags_MenuBar;
  151. ImGui::SetNextWindowSize(ImVec2(550,680), ImGuiSetCond_FirstUseEver);
  152. if (!ImGui::Begin("ImGui Demo", p_open, window_flags))
  153. {
  154. // Early out if the window is collapsed, as an optimization.
  155. ImGui::End();
  156. return;
  157. }
  158. //ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // 2/3 of the space for widget and 1/3 for labels
  159. ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels
  160. ImGui::Text("Dear ImGui says hello.");
  161. // Menu
  162. if (ImGui::BeginMenuBar())
  163. {
  164. if (ImGui::BeginMenu("Menu"))
  165. {
  166. ShowExampleMenuFile();
  167. ImGui::EndMenu();
  168. }
  169. if (ImGui::BeginMenu("Examples"))
  170. {
  171. ImGui::MenuItem("Main menu bar", NULL, &show_app_main_menu_bar);
  172. ImGui::MenuItem("Console", NULL, &show_app_console);
  173. ImGui::MenuItem("Log", NULL, &show_app_log);
  174. ImGui::MenuItem("Simple layout", NULL, &show_app_layout);
  175. ImGui::MenuItem("Property editor", NULL, &show_app_property_editor);
  176. ImGui::MenuItem("Long text display", NULL, &show_app_long_text);
  177. ImGui::MenuItem("Auto-resizing window", NULL, &show_app_auto_resize);
  178. ImGui::MenuItem("Constrained-resizing window", NULL, &show_app_constrained_resize);
  179. ImGui::MenuItem("Simple overlay", NULL, &show_app_fixed_overlay);
  180. ImGui::MenuItem("Manipulating window title", NULL, &show_app_manipulating_window_title);
  181. ImGui::MenuItem("Custom rendering", NULL, &show_app_custom_rendering);
  182. ImGui::EndMenu();
  183. }
  184. if (ImGui::BeginMenu("Help"))
  185. {
  186. ImGui::MenuItem("Metrics", NULL, &show_app_metrics);
  187. ImGui::MenuItem("Style Editor", NULL, &show_app_style_editor);
  188. ImGui::MenuItem("About ImGui", NULL, &show_app_about);
  189. ImGui::EndMenu();
  190. }
  191. ImGui::EndMenuBar();
  192. }
  193. ImGui::Spacing();
  194. if (ImGui::CollapsingHeader("Help"))
  195. {
  196. ImGui::TextWrapped("This window is being created by the ShowTestWindow() function. Please refer to the code for programming reference.\n\nUser Guide:");
  197. ImGui::ShowUserGuide();
  198. }
  199. if (ImGui::CollapsingHeader("Window options"))
  200. {
  201. ImGui::Checkbox("No titlebar", &no_titlebar); ImGui::SameLine(150);
  202. ImGui::Checkbox("No border", &no_border); ImGui::SameLine(300);
  203. ImGui::Checkbox("No resize", &no_resize);
  204. ImGui::Checkbox("No move", &no_move); ImGui::SameLine(150);
  205. ImGui::Checkbox("No scrollbar", &no_scrollbar); ImGui::SameLine(300);
  206. ImGui::Checkbox("No collapse", &no_collapse);
  207. ImGui::Checkbox("No menu", &no_menu);
  208. if (ImGui::TreeNode("Style"))
  209. {
  210. ImGui::ShowStyleEditor();
  211. ImGui::TreePop();
  212. }
  213. if (ImGui::TreeNode("Logging"))
  214. {
  215. ImGui::TextWrapped("The logging API redirects all text output so you can easily capture the content of a window or a block. Tree nodes can be automatically expanded. You can also call ImGui::LogText() to output directly to the log without a visual output.");
  216. ImGui::LogButtons();
  217. ImGui::TreePop();
  218. }
  219. }
  220. if (ImGui::CollapsingHeader("Widgets"))
  221. {
  222. if (ImGui::TreeNode("Trees"))
  223. {
  224. if (ImGui::TreeNode("Basic trees"))
  225. {
  226. for (int i = 0; i < 5; i++)
  227. if (ImGui::TreeNode((void*)(intptr_t)i, "Child %d", i))
  228. {
  229. ImGui::Text("blah blah");
  230. ImGui::SameLine();
  231. if (ImGui::SmallButton("print")) printf("Child %d pressed", i);
  232. ImGui::TreePop();
  233. }
  234. ImGui::TreePop();
  235. }
  236. if (ImGui::TreeNode("Advanced, with Selectable nodes"))
  237. {
  238. ShowHelpMarker("This is a more standard looking tree with selectable nodes.\nClick to select, CTRL+Click to toggle, click on arrows or double-click to open.");
  239. static bool align_label_with_current_x_position = false;
  240. ImGui::Checkbox("Align label with current X position)", &align_label_with_current_x_position);
  241. ImGui::Text("Hello!");
  242. if (align_label_with_current_x_position)
  243. ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing());
  244. static int selection_mask = (1 << 2); // Dumb representation of what may be user-side selection state. You may carry selection state inside or outside your objects in whatever format you see fit.
  245. int node_clicked = -1; // Temporary storage of what node we have clicked to process selection at the end of the loop. May be a pointer to your own node type, etc.
  246. ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, ImGui::GetFontSize()*3); // Increase spacing to differentiate leaves from expanded contents.
  247. for (int i = 0; i < 6; i++)
  248. {
  249. // Disable the default open on single-click behavior and pass in Selected flag according to our selection state.
  250. ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ((selection_mask & (1 << i)) ? ImGuiTreeNodeFlags_Selected : 0);
  251. if (i < 3)
  252. {
  253. // Node
  254. bool node_open = ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "Selectable Node %d", i);
  255. if (ImGui::IsItemClicked())
  256. node_clicked = i;
  257. if (node_open)
  258. {
  259. ImGui::Text("Blah blah\nBlah Blah");
  260. ImGui::TreePop();
  261. }
  262. }
  263. else
  264. {
  265. // Leaf: The only reason we have a TreeNode at all is to allow selection of the leaf. Otherwise we can use BulletText() or TreeAdvanceToLabelPos()+Text().
  266. ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags | ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen, "Selectable Leaf %d", i);
  267. if (ImGui::IsItemClicked())
  268. node_clicked = i;
  269. }
  270. }
  271. if (node_clicked != -1)
  272. {
  273. // Update selection state. Process outside of tree loop to avoid visual inconsistencies during the clicking-frame.
  274. if (ImGui::GetIO().KeyCtrl)
  275. selection_mask ^= (1 << node_clicked); // CTRL+click to toggle
  276. else //if (!(selection_mask & (1 << node_clicked))) // Depending on selection behavior you want, this commented bit preserve selection when clicking on item that is part of the selection
  277. selection_mask = (1 << node_clicked); // Click to single-select
  278. }
  279. ImGui::PopStyleVar();
  280. if (align_label_with_current_x_position)
  281. ImGui::Indent(ImGui::GetTreeNodeToLabelSpacing());
  282. ImGui::TreePop();
  283. }
  284. ImGui::TreePop();
  285. }
  286. if (ImGui::TreeNode("Collapsing Headers"))
  287. {
  288. static bool closable_group = true;
  289. if (ImGui::CollapsingHeader("Header"))
  290. {
  291. ImGui::Checkbox("Enable extra group", &closable_group);
  292. for (int i = 0; i < 5; i++)
  293. ImGui::Text("Some content %d", i);
  294. }
  295. if (ImGui::CollapsingHeader("Header with a close button", &closable_group))
  296. {
  297. for (int i = 0; i < 5; i++)
  298. ImGui::Text("More content %d", i);
  299. }
  300. ImGui::TreePop();
  301. }
  302. if (ImGui::TreeNode("Bullets"))
  303. {
  304. ImGui::BulletText("Bullet point 1");
  305. ImGui::BulletText("Bullet point 2\nOn multiple lines");
  306. ImGui::Bullet(); ImGui::Text("Bullet point 3 (two calls)");
  307. ImGui::Bullet(); ImGui::SmallButton("Button");
  308. ImGui::TreePop();
  309. }
  310. if (ImGui::TreeNode("Colored Text"))
  311. {
  312. // Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
  313. ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink");
  314. ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow");
  315. ImGui::TextDisabled("Disabled");
  316. ImGui::TreePop();
  317. }
  318. if (ImGui::TreeNode("Word Wrapping"))
  319. {
  320. // Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
  321. ImGui::TextWrapped("This text should automatically wrap on the edge of the window. The current implementation for text wrapping follows simple rules suitable for English and possibly other languages.");
  322. ImGui::Spacing();
  323. static float wrap_width = 200.0f;
  324. ImGui::SliderFloat("Wrap width", &wrap_width, -20, 600, "%.0f");
  325. ImGui::Text("Test paragraph 1:");
  326. ImVec2 pos = ImGui::GetCursorScreenPos();
  327. ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + wrap_width, pos.y), ImVec2(pos.x + wrap_width + 10, pos.y + ImGui::GetTextLineHeight()), IM_COL32(255,0,255,255));
  328. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  329. ImGui::Text("lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog.", wrap_width);
  330. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255,255,0,255));
  331. ImGui::PopTextWrapPos();
  332. ImGui::Text("Test paragraph 2:");
  333. pos = ImGui::GetCursorScreenPos();
  334. ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(pos.x + wrap_width, pos.y), ImVec2(pos.x + wrap_width + 10, pos.y + ImGui::GetTextLineHeight()), IM_COL32(255,0,255,255));
  335. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  336. ImGui::Text("aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh");
  337. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(255,255,0,255));
  338. ImGui::PopTextWrapPos();
  339. ImGui::TreePop();
  340. }
  341. if (ImGui::TreeNode("UTF-8 Text"))
  342. {
  343. // UTF-8 test with Japanese characters
  344. // (needs a suitable font, try Arial Unicode or M+ fonts http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html)
  345. // Most compiler appears to support UTF-8 in source code (with Visual Studio you need to save your file as 'UTF-8 without signature')
  346. // However for the sake for maximum portability here we are *not* including raw UTF-8 character in this source file, instead we encode the string with hexadecimal constants.
  347. // In your own application be reasonable and use UTF-8 in source or retrieve the data from file system!
  348. // Note that characters values are preserved even if the font cannot be displayed, so you can safely copy & paste garbled characters into another application.
  349. ImGui::TextWrapped("CJK text will only appears if the font was loaded with the appropriate CJK character ranges. Call io.Font->LoadFromFileTTF() manually to load extra character ranges.");
  350. ImGui::Text("Hiragana: \xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93 (kakikukeko)");
  351. ImGui::Text("Kanjis: \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e (nihongo)");
  352. static char buf[32] = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e";
  353. ImGui::InputText("UTF-8 input", buf, IM_ARRAYSIZE(buf));
  354. ImGui::TreePop();
  355. }
  356. if (ImGui::TreeNode("Images"))
  357. {
  358. ImGui::TextWrapped("Below we are displaying the font texture (which is the only texture we have access to in this demo). Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. Hover the texture for a zoomed view!");
  359. ImVec2 tex_screen_pos = ImGui::GetCursorScreenPos();
  360. float tex_w = (float)ImGui::GetIO().Fonts->TexWidth;
  361. float tex_h = (float)ImGui::GetIO().Fonts->TexHeight;
  362. ImTextureID tex_id = ImGui::GetIO().Fonts->TexID;
  363. ImGui::Text("%.0fx%.0f", tex_w, tex_h);
  364. ImGui::Image(tex_id, ImVec2(tex_w, tex_h), ImVec2(0,0), ImVec2(1,1), ImColor(255,255,255,255), ImColor(255,255,255,128));
  365. if (ImGui::IsItemHovered())
  366. {
  367. ImGui::BeginTooltip();
  368. float focus_sz = 32.0f;
  369. float focus_x = ImGui::GetMousePos().x - tex_screen_pos.x - focus_sz * 0.5f; if (focus_x < 0.0f) focus_x = 0.0f; else if (focus_x > tex_w - focus_sz) focus_x = tex_w - focus_sz;
  370. float focus_y = ImGui::GetMousePos().y - tex_screen_pos.y - focus_sz * 0.5f; if (focus_y < 0.0f) focus_y = 0.0f; else if (focus_y > tex_h - focus_sz) focus_y = tex_h - focus_sz;
  371. ImGui::Text("Min: (%.2f, %.2f)", focus_x, focus_y);
  372. ImGui::Text("Max: (%.2f, %.2f)", focus_x + focus_sz, focus_y + focus_sz);
  373. ImVec2 uv0 = ImVec2((focus_x) / tex_w, (focus_y) / tex_h);
  374. ImVec2 uv1 = ImVec2((focus_x + focus_sz) / tex_w, (focus_y + focus_sz) / tex_h);
  375. ImGui::Image(tex_id, ImVec2(128,128), uv0, uv1, ImColor(255,255,255,255), ImColor(255,255,255,128));
  376. ImGui::EndTooltip();
  377. }
  378. ImGui::TextWrapped("And now some textured buttons..");
  379. static int pressed_count = 0;
  380. for (int i = 0; i < 8; i++)
  381. {
  382. ImGui::PushID(i);
  383. int frame_padding = -1 + i; // -1 = uses default padding
  384. if (ImGui::ImageButton(tex_id, ImVec2(32,32), ImVec2(0,0), ImVec2(32.0f/tex_w,32/tex_h), frame_padding, ImColor(0,0,0,255)))
  385. pressed_count += 1;
  386. ImGui::PopID();
  387. ImGui::SameLine();
  388. }
  389. ImGui::NewLine();
  390. ImGui::Text("Pressed %d times.", pressed_count);
  391. ImGui::TreePop();
  392. }
  393. if (ImGui::TreeNode("Selectables"))
  394. {
  395. if (ImGui::TreeNode("Basic"))
  396. {
  397. static bool selected[4] = { false, true, false, false };
  398. ImGui::Selectable("1. I am selectable", &selected[0]);
  399. ImGui::Selectable("2. I am selectable", &selected[1]);
  400. ImGui::Text("3. I am not selectable");
  401. ImGui::Selectable("4. I am selectable", &selected[2]);
  402. if (ImGui::Selectable("5. I am double clickable", selected[3], ImGuiSelectableFlags_AllowDoubleClick))
  403. if (ImGui::IsMouseDoubleClicked(0))
  404. selected[3] = !selected[3];
  405. ImGui::TreePop();
  406. }
  407. if (ImGui::TreeNode("Rendering more text into the same block"))
  408. {
  409. static bool selected[3] = { false, false, false };
  410. ImGui::Selectable("main.c", &selected[0]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
  411. ImGui::Selectable("Hello.cpp", &selected[1]); ImGui::SameLine(300); ImGui::Text("12,345 bytes");
  412. ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes");
  413. ImGui::TreePop();
  414. }
  415. if (ImGui::TreeNode("In columns"))
  416. {
  417. ImGui::Columns(3, NULL, false);
  418. static bool selected[16] = { 0 };
  419. for (int i = 0; i < 16; i++)
  420. {
  421. char label[32]; sprintf(label, "Item %d", i);
  422. if (ImGui::Selectable(label, &selected[i])) {}
  423. ImGui::NextColumn();
  424. }
  425. ImGui::Columns(1);
  426. ImGui::TreePop();
  427. }
  428. if (ImGui::TreeNode("Grid"))
  429. {
  430. static bool selected[16] = { true, false, false, false, false, true, false, false, false, false, true, false, false, false, false, true };
  431. for (int i = 0; i < 16; i++)
  432. {
  433. ImGui::PushID(i);
  434. if (ImGui::Selectable("Sailor", &selected[i], 0, ImVec2(50,50)))
  435. {
  436. int x = i % 4, y = i / 4;
  437. if (x > 0) selected[i - 1] ^= 1;
  438. if (x < 3) selected[i + 1] ^= 1;
  439. if (y > 0) selected[i - 4] ^= 1;
  440. if (y < 3) selected[i + 4] ^= 1;
  441. }
  442. if ((i % 4) < 3) ImGui::SameLine();
  443. ImGui::PopID();
  444. }
  445. ImGui::TreePop();
  446. }
  447. ImGui::TreePop();
  448. }
  449. if (ImGui::TreeNode("Filtered Text Input"))
  450. {
  451. static char buf1[64] = ""; ImGui::InputText("default", buf1, 64);
  452. static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal);
  453. static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
  454. static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase);
  455. static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank);
  456. struct TextFilters { static int FilterImGuiLetters(ImGuiTextEditCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) return 0; return 1; } };
  457. static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters);
  458. ImGui::Text("Password input");
  459. static char bufpass[64] = "password123";
  460. ImGui::InputText("password", bufpass, 64, ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank);
  461. ImGui::SameLine(); ShowHelpMarker("Display all characters as '*'.\nDisable clipboard cut and copy.\nDisable logging.\n");
  462. ImGui::InputText("password (clear)", bufpass, 64, ImGuiInputTextFlags_CharsNoBlank);
  463. ImGui::TreePop();
  464. }
  465. if (ImGui::TreeNode("Multi-line Text Input"))
  466. {
  467. static bool read_only = false;
  468. static char text[1024*16] =
  469. "/*\n"
  470. " The Pentium F00F bug, shorthand for F0 0F C7 C8,\n"
  471. " the hexadecimal encoding of one offending instruction,\n"
  472. " more formally, the invalid operand with locked CMPXCHG8B\n"
  473. " instruction bug, is a design flaw in the majority of\n"
  474. " Intel Pentium, Pentium MMX, and Pentium OverDrive\n"
  475. " processors (all in the P5 microarchitecture).\n"
  476. "*/\n\n"
  477. "label:\n"
  478. "\tlock cmpxchg8b eax\n";
  479. ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
  480. ImGui::Checkbox("Read-only", &read_only);
  481. ImGui::PopStyleVar();
  482. ImGui::InputTextMultiline("##source", text, IM_ARRAYSIZE(text), ImVec2(-1.0f, ImGui::GetTextLineHeight() * 16), ImGuiInputTextFlags_AllowTabInput | (read_only ? ImGuiInputTextFlags_ReadOnly : 0));
  483. ImGui::TreePop();
  484. }
  485. static bool a=false;
  486. if (ImGui::Button("Button")) { printf("Clicked\n"); a ^= 1; }
  487. if (a)
  488. {
  489. ImGui::SameLine();
  490. ImGui::Text("Thanks for clicking me!");
  491. }
  492. static bool check = true;
  493. ImGui::Checkbox("checkbox", &check);
  494. static int e = 0;
  495. ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine();
  496. ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine();
  497. ImGui::RadioButton("radio c", &e, 2);
  498. // Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
  499. for (int i = 0; i < 7; i++)
  500. {
  501. if (i > 0) ImGui::SameLine();
  502. ImGui::PushID(i);
  503. ImGui::PushStyleColor(ImGuiCol_Button, ImColor::HSV(i/7.0f, 0.6f, 0.6f));
  504. ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImColor::HSV(i/7.0f, 0.7f, 0.7f));
  505. ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImColor::HSV(i/7.0f, 0.8f, 0.8f));
  506. ImGui::Button("Click");
  507. ImGui::PopStyleColor(3);
  508. ImGui::PopID();
  509. }
  510. ImGui::Text("Hover over me");
  511. if (ImGui::IsItemHovered())
  512. ImGui::SetTooltip("I am a tooltip");
  513. ImGui::SameLine();
  514. ImGui::Text("- or me");
  515. if (ImGui::IsItemHovered())
  516. {
  517. ImGui::BeginTooltip();
  518. ImGui::Text("I am a fancy tooltip");
  519. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  520. ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr));
  521. ImGui::EndTooltip();
  522. }
  523. // Testing IMGUI_ONCE_UPON_A_FRAME macro
  524. //for (int i = 0; i < 5; i++)
  525. //{
  526. // IMGUI_ONCE_UPON_A_FRAME
  527. // {
  528. // ImGui::Text("This will be displayed only once.");
  529. // }
  530. //}
  531. ImGui::Separator();
  532. ImGui::LabelText("label", "Value");
  533. static int item = 1;
  534. ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0"); // Combo using values packed in a single constant string (for really quick combo)
  535. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK" };
  536. static int item2 = -1;
  537. ImGui::Combo("combo scroll", &item2, items, IM_ARRAYSIZE(items)); // Combo using proper array. You can also pass a callback to retrieve array value, no need to create/copy an array just for that.
  538. {
  539. static char str0[128] = "Hello, world!";
  540. static int i0=123;
  541. static float f0=0.001f;
  542. ImGui::InputText("input text", str0, IM_ARRAYSIZE(str0));
  543. ImGui::SameLine(); ShowHelpMarker("Hold SHIFT or use mouse to select text.\n" "CTRL+Left/Right to word jump.\n" "CTRL+A or double-click to select all.\n" "CTRL+X,CTRL+C,CTRL+V clipboard.\n" "CTRL+Z,CTRL+Y undo/redo.\n" "ESCAPE to revert.\n");
  544. ImGui::InputInt("input int", &i0);
  545. ImGui::SameLine(); ShowHelpMarker("You can apply arithmetic operators +,*,/ on numerical values.\n e.g. [ 100 ], input \'*2\', result becomes [ 200 ]\nUse +- to subtract.\n");
  546. ImGui::InputFloat("input float", &f0, 0.01f, 1.0f);
  547. static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  548. ImGui::InputFloat3("input float3", vec4a);
  549. }
  550. {
  551. static int i1=50, i2=42;
  552. ImGui::DragInt("drag int", &i1, 1);
  553. ImGui::SameLine(); ShowHelpMarker("Click and drag to edit value.\nHold SHIFT/ALT for faster/slower edit.\nDouble-click or CTRL+click to input value.");
  554. ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100, "%.0f%%");
  555. static float f1=1.00f, f2=0.0067f;
  556. ImGui::DragFloat("drag float", &f1, 0.005f);
  557. ImGui::DragFloat("drag small float", &f2, 0.0001f, 0.0f, 0.0f, "%.06f ns");
  558. }
  559. {
  560. static int i1=0;
  561. ImGui::SliderInt("slider int", &i1, -1, 3);
  562. ImGui::SameLine(); ShowHelpMarker("CTRL+click to input value.");
  563. static float f1=0.123f, f2=0.0f;
  564. ImGui::SliderFloat("slider float", &f1, 0.0f, 1.0f, "ratio = %.3f");
  565. ImGui::SliderFloat("slider log float", &f2, -10.0f, 10.0f, "%.4f", 3.0f);
  566. static float angle = 0.0f;
  567. ImGui::SliderAngle("slider angle", &angle);
  568. }
  569. static float col1[3] = { 1.0f,0.0f,0.2f };
  570. static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
  571. ImGui::ColorEdit3("color 1", col1);
  572. ImGui::SameLine(); ShowHelpMarker("Click on the colored square to change edit mode.\nCTRL+click on individual component to input value.\n");
  573. ImGui::ColorEdit4("color 2", col2);
  574. const char* listbox_items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
  575. static int listbox_item_current = 1;
  576. ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
  577. //static int listbox_item_current2 = 2;
  578. //ImGui::PushItemWidth(-1);
  579. //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
  580. //ImGui::PopItemWidth();
  581. if (ImGui::TreeNode("Range Widgets"))
  582. {
  583. ImGui::Unindent();
  584. static float begin = 10, end = 90;
  585. static int begin_i = 100, end_i = 1000;
  586. ImGui::DragFloatRange2("range", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%");
  587. ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %.0f units", "Max: %.0f units");
  588. ImGui::Indent();
  589. ImGui::TreePop();
  590. }
  591. if (ImGui::TreeNode("Multi-component Widgets"))
  592. {
  593. ImGui::Unindent();
  594. static float vec4f[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  595. static int vec4i[4] = { 1, 5, 100, 255 };
  596. ImGui::InputFloat2("input float2", vec4f);
  597. ImGui::DragFloat2("drag float2", vec4f, 0.01f, 0.0f, 1.0f);
  598. ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f);
  599. ImGui::DragInt2("drag int2", vec4i, 1, 0, 255);
  600. ImGui::InputInt2("input int2", vec4i);
  601. ImGui::SliderInt2("slider int2", vec4i, 0, 255);
  602. ImGui::Spacing();
  603. ImGui::InputFloat3("input float3", vec4f);
  604. ImGui::DragFloat3("drag float3", vec4f, 0.01f, 0.0f, 1.0f);
  605. ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f);
  606. ImGui::DragInt3("drag int3", vec4i, 1, 0, 255);
  607. ImGui::InputInt3("input int3", vec4i);
  608. ImGui::SliderInt3("slider int3", vec4i, 0, 255);
  609. ImGui::Spacing();
  610. ImGui::InputFloat4("input float4", vec4f);
  611. ImGui::DragFloat4("drag float4", vec4f, 0.01f, 0.0f, 1.0f);
  612. ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f);
  613. ImGui::InputInt4("input int4", vec4i);
  614. ImGui::DragInt4("drag int4", vec4i, 1, 0, 255);
  615. ImGui::SliderInt4("slider int4", vec4i, 0, 255);
  616. ImGui::Indent();
  617. ImGui::TreePop();
  618. }
  619. if (ImGui::TreeNode("Vertical Sliders"))
  620. {
  621. ImGui::Unindent();
  622. const float spacing = 4;
  623. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(spacing, spacing));
  624. static int int_value = 0;
  625. ImGui::VSliderInt("##int", ImVec2(18,160), &int_value, 0, 5);
  626. ImGui::SameLine();
  627. static float values[7] = { 0.0f, 0.60f, 0.35f, 0.9f, 0.70f, 0.20f, 0.0f };
  628. ImGui::PushID("set1");
  629. for (int i = 0; i < 7; i++)
  630. {
  631. if (i > 0) ImGui::SameLine();
  632. ImGui::PushID(i);
  633. ImGui::PushStyleColor(ImGuiCol_FrameBg, ImColor::HSV(i/7.0f, 0.5f, 0.5f));
  634. ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImColor::HSV(i/7.0f, 0.6f, 0.5f));
  635. ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImColor::HSV(i/7.0f, 0.7f, 0.5f));
  636. ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor::HSV(i/7.0f, 0.9f, 0.9f));
  637. ImGui::VSliderFloat("##v", ImVec2(18,160), &values[i], 0.0f, 1.0f, "");
  638. if (ImGui::IsItemActive() || ImGui::IsItemHovered())
  639. ImGui::SetTooltip("%.3f", values[i]);
  640. ImGui::PopStyleColor(4);
  641. ImGui::PopID();
  642. }
  643. ImGui::PopID();
  644. ImGui::SameLine();
  645. ImGui::PushID("set2");
  646. static float values2[4] = { 0.20f, 0.80f, 0.40f, 0.25f };
  647. const int rows = 3;
  648. const ImVec2 small_slider_size(18, (160.0f-(rows-1)*spacing)/rows);
  649. for (int nx = 0; nx < 4; nx++)
  650. {
  651. if (nx > 0) ImGui::SameLine();
  652. ImGui::BeginGroup();
  653. for (int ny = 0; ny < rows; ny++)
  654. {
  655. ImGui::PushID(nx*rows+ny);
  656. ImGui::VSliderFloat("##v", small_slider_size, &values2[nx], 0.0f, 1.0f, "");
  657. if (ImGui::IsItemActive() || ImGui::IsItemHovered())
  658. ImGui::SetTooltip("%.3f", values2[nx]);
  659. ImGui::PopID();
  660. }
  661. ImGui::EndGroup();
  662. }
  663. ImGui::PopID();
  664. ImGui::SameLine();
  665. ImGui::PushID("set3");
  666. for (int i = 0; i < 4; i++)
  667. {
  668. if (i > 0) ImGui::SameLine();
  669. ImGui::PushID(i);
  670. ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 40);
  671. ImGui::VSliderFloat("##v", ImVec2(40,160), &values[i], 0.0f, 1.0f, "%.2f\nsec");
  672. ImGui::PopStyleVar();
  673. ImGui::PopID();
  674. }
  675. ImGui::PopID();
  676. ImGui::PopStyleVar();
  677. ImGui::Indent();
  678. ImGui::TreePop();
  679. }
  680. }
  681. if (ImGui::CollapsingHeader("Graphs widgets"))
  682. {
  683. static bool animate = true;
  684. ImGui::Checkbox("Animate", &animate);
  685. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  686. ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr));
  687. // Create a dummy array of contiguous float values to plot
  688. // Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float and the sizeof() of your structure in the Stride parameter.
  689. static float values[90] = { 0 };
  690. static int values_offset = 0;
  691. if (animate)
  692. {
  693. static float refresh_time = ImGui::GetTime(); // Create dummy data at fixed 60 hz rate for the demo
  694. for (; ImGui::GetTime() > refresh_time + 1.0f/60.0f; refresh_time += 1.0f/60.0f)
  695. {
  696. static float phase = 0.0f;
  697. values[values_offset] = cosf(phase);
  698. values_offset = (values_offset+1) % IM_ARRAYSIZE(values);
  699. phase += 0.10f*values_offset;
  700. }
  701. }
  702. ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80));
  703. ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80));
  704. // Use functions to generate output
  705. // FIXME: This is rather awkward because current plot API only pass in indices. We probably want an API passing floats and user provide sample rate/count.
  706. struct Funcs
  707. {
  708. static float Sin(void*, int i) { return sinf(i * 0.1f); }
  709. static float Saw(void*, int i) { return (i & 1) ? 1.0f : 0.0f; }
  710. };
  711. static int func_type = 0, display_count = 70;
  712. ImGui::Separator();
  713. ImGui::PushItemWidth(100); ImGui::Combo("func", &func_type, "Sin\0Saw\0"); ImGui::PopItemWidth();
  714. ImGui::SameLine();
  715. ImGui::SliderInt("Sample count", &display_count, 1, 400);
  716. float (*func)(void*, int) = (func_type == 0) ? Funcs::Sin : Funcs::Saw;
  717. ImGui::PlotLines("Lines", func, NULL, display_count, 0, NULL, -1.0f, 1.0f, ImVec2(0,80));
  718. ImGui::PlotHistogram("Histogram", func, NULL, display_count, 0, NULL, -1.0f, 1.0f, ImVec2(0,80));
  719. ImGui::Separator();
  720. // Animate a simple progress bar
  721. static float progress = 0.0f, progress_dir = 1.0f;
  722. if (animate)
  723. {
  724. progress += progress_dir * 0.4f * ImGui::GetIO().DeltaTime;
  725. if (progress >= +1.1f) { progress = +1.1f; progress_dir *= -1.0f; }
  726. if (progress <= -0.1f) { progress = -0.1f; progress_dir *= -1.0f; }
  727. }
  728. // Typically we would use ImVec2(-1.0f,0.0f) to use all available width, or ImVec2(width,0.0f) for a specified width. ImVec2(0.0f,0.0f) uses ItemWidth.
  729. ImGui::ProgressBar(progress, ImVec2(0.0f,0.0f));
  730. ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
  731. ImGui::Text("Progress Bar");
  732. float progress_saturated = (progress < 0.0f) ? 0.0f : (progress > 1.0f) ? 1.0f : progress;
  733. char buf[32];
  734. sprintf(buf, "%d/%d", (int)(progress_saturated*1753), 1753);
  735. ImGui::ProgressBar(progress, ImVec2(0.f,0.f), buf);
  736. }
  737. if (ImGui::CollapsingHeader("Layout"))
  738. {
  739. if (ImGui::TreeNode("Child regions"))
  740. {
  741. ImGui::Text("Without border");
  742. static int line = 50;
  743. bool goto_line = ImGui::Button("Goto");
  744. ImGui::SameLine();
  745. ImGui::PushItemWidth(100);
  746. goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
  747. ImGui::PopItemWidth();
  748. ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.5f,300), false, ImGuiWindowFlags_HorizontalScrollbar);
  749. for (int i = 0; i < 100; i++)
  750. {
  751. ImGui::Text("%04d: scrollable region", i);
  752. if (goto_line && line == i)
  753. ImGui::SetScrollHere();
  754. }
  755. if (goto_line && line >= 100)
  756. ImGui::SetScrollHere();
  757. ImGui::EndChild();
  758. ImGui::SameLine();
  759. ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, 5.0f);
  760. ImGui::BeginChild("Sub2", ImVec2(0,300), true);
  761. ImGui::Text("With border");
  762. ImGui::Columns(2);
  763. for (int i = 0; i < 100; i++)
  764. {
  765. if (i == 50)
  766. ImGui::NextColumn();
  767. char buf[32];
  768. sprintf(buf, "%08x", i*5731);
  769. ImGui::Button(buf, ImVec2(-1.0f, 0.0f));
  770. }
  771. ImGui::EndChild();
  772. ImGui::PopStyleVar();
  773. ImGui::TreePop();
  774. }
  775. if (ImGui::TreeNode("Widgets Width"))
  776. {
  777. static float f = 0.0f;
  778. ImGui::Text("PushItemWidth(100)");
  779. ImGui::SameLine(); ShowHelpMarker("Fixed width.");
  780. ImGui::PushItemWidth(100);
  781. ImGui::DragFloat("float##1", &f);
  782. ImGui::PopItemWidth();
  783. ImGui::Text("PushItemWidth(GetWindowWidth() * 0.5f)");
  784. ImGui::SameLine(); ShowHelpMarker("Half of window width.");
  785. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
  786. ImGui::DragFloat("float##2", &f);
  787. ImGui::PopItemWidth();
  788. ImGui::Text("PushItemWidth(GetContentRegionAvailWidth() * 0.5f)");
  789. ImGui::SameLine(); ShowHelpMarker("Half of available width.\n(~ right-cursor_pos)\n(works within a column set)");
  790. ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() * 0.5f);
  791. ImGui::DragFloat("float##3", &f);
  792. ImGui::PopItemWidth();
  793. ImGui::Text("PushItemWidth(-100)");
  794. ImGui::SameLine(); ShowHelpMarker("Align to right edge minus 100");
  795. ImGui::PushItemWidth(-100);
  796. ImGui::DragFloat("float##4", &f);
  797. ImGui::PopItemWidth();
  798. ImGui::Text("PushItemWidth(-1)");
  799. ImGui::SameLine(); ShowHelpMarker("Align to right edge");
  800. ImGui::PushItemWidth(-1);
  801. ImGui::DragFloat("float##5", &f);
  802. ImGui::PopItemWidth();
  803. ImGui::TreePop();
  804. }
  805. if (ImGui::TreeNode("Basic Horizontal Layout"))
  806. {
  807. ImGui::TextWrapped("(Use ImGui::SameLine() to keep adding items to the right of the preceding item)");
  808. // Text
  809. ImGui::Text("Two items: Hello"); ImGui::SameLine();
  810. ImGui::TextColored(ImVec4(1,1,0,1), "Sailor");
  811. // Adjust spacing
  812. ImGui::Text("More spacing: Hello"); ImGui::SameLine(0, 20);
  813. ImGui::TextColored(ImVec4(1,1,0,1), "Sailor");
  814. // Button
  815. ImGui::AlignFirstTextHeightToWidgets();
  816. ImGui::Text("Normal buttons"); ImGui::SameLine();
  817. ImGui::Button("Banana"); ImGui::SameLine();
  818. ImGui::Button("Apple"); ImGui::SameLine();
  819. ImGui::Button("Corniflower");
  820. // Button
  821. ImGui::Text("Small buttons"); ImGui::SameLine();
  822. ImGui::SmallButton("Like this one"); ImGui::SameLine();
  823. ImGui::Text("can fit within a text block.");
  824. // Aligned to arbitrary position. Easy/cheap column.
  825. ImGui::Text("Aligned");
  826. ImGui::SameLine(150); ImGui::Text("x=150");
  827. ImGui::SameLine(300); ImGui::Text("x=300");
  828. ImGui::Text("Aligned");
  829. ImGui::SameLine(150); ImGui::SmallButton("x=150");
  830. ImGui::SameLine(300); ImGui::SmallButton("x=300");
  831. // Checkbox
  832. static bool c1=false,c2=false,c3=false,c4=false;
  833. ImGui::Checkbox("My", &c1); ImGui::SameLine();
  834. ImGui::Checkbox("Tailor", &c2); ImGui::SameLine();
  835. ImGui::Checkbox("Is", &c3); ImGui::SameLine();
  836. ImGui::Checkbox("Rich", &c4);
  837. // Various
  838. static float f0=1.0f, f1=2.0f, f2=3.0f;
  839. ImGui::PushItemWidth(80);
  840. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" };
  841. static int item = -1;
  842. ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items)); ImGui::SameLine();
  843. ImGui::SliderFloat("X", &f0, 0.0f,5.0f); ImGui::SameLine();
  844. ImGui::SliderFloat("Y", &f1, 0.0f,5.0f); ImGui::SameLine();
  845. ImGui::SliderFloat("Z", &f2, 0.0f,5.0f);
  846. ImGui::PopItemWidth();
  847. ImGui::PushItemWidth(80);
  848. ImGui::Text("Lists:");
  849. static int selection[4] = { 0, 1, 2, 3 };
  850. for (int i = 0; i < 4; i++)
  851. {
  852. if (i > 0) ImGui::SameLine();
  853. ImGui::PushID(i);
  854. ImGui::ListBox("", &selection[i], items, IM_ARRAYSIZE(items));
  855. ImGui::PopID();
  856. //if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i);
  857. }
  858. ImGui::PopItemWidth();
  859. // Dummy
  860. ImVec2 sz(30,30);
  861. ImGui::Button("A", sz); ImGui::SameLine();
  862. ImGui::Dummy(sz); ImGui::SameLine();
  863. ImGui::Button("B", sz);
  864. ImGui::TreePop();
  865. }
  866. if (ImGui::TreeNode("Groups"))
  867. {
  868. ImGui::TextWrapped("(Using ImGui::BeginGroup()/EndGroup() to layout items. BeginGroup() basically locks the horizontal position. EndGroup() bundles the whole group so that you can use functions such as IsItemHovered() on it.)");
  869. ImGui::BeginGroup();
  870. {
  871. ImGui::BeginGroup();
  872. ImGui::Button("AAA");
  873. ImGui::SameLine();
  874. ImGui::Button("BBB");
  875. ImGui::SameLine();
  876. ImGui::BeginGroup();
  877. ImGui::Button("CCC");
  878. ImGui::Button("DDD");
  879. ImGui::EndGroup();
  880. if (ImGui::IsItemHovered())
  881. ImGui::SetTooltip("Group hovered");
  882. ImGui::SameLine();
  883. ImGui::Button("EEE");
  884. ImGui::EndGroup();
  885. }
  886. // Capture the group size and create widgets using the same size
  887. ImVec2 size = ImGui::GetItemRectSize();
  888. const float values[5] = { 0.5f, 0.20f, 0.80f, 0.60f, 0.25f };
  889. ImGui::PlotHistogram("##values", values, IM_ARRAYSIZE(values), 0, NULL, 0.0f, 1.0f, size);
  890. ImGui::Button("ACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y));
  891. ImGui::SameLine();
  892. ImGui::Button("REACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y));
  893. ImGui::EndGroup();
  894. ImGui::SameLine();
  895. ImGui::Button("LEVERAGE\nBUZZWORD", size);
  896. ImGui::SameLine();
  897. ImGui::ListBoxHeader("List", size);
  898. ImGui::Selectable("Selected", true);
  899. ImGui::Selectable("Not Selected", false);
  900. ImGui::ListBoxFooter();
  901. ImGui::TreePop();
  902. }
  903. if (ImGui::TreeNode("Text Baseline Alignment"))
  904. {
  905. ImGui::TextWrapped("(This is testing the vertical alignment that occurs on text to keep it at the same baseline as widgets. Lines only composed of text or \"small\" widgets fit in less vertical spaces than lines with normal widgets)");
  906. ImGui::Text("One\nTwo\nThree"); ImGui::SameLine();
  907. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  908. ImGui::Text("Banana");
  909. ImGui::Text("Banana"); ImGui::SameLine();
  910. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  911. ImGui::Text("One\nTwo\nThree");
  912. ImGui::Button("HOP##1"); ImGui::SameLine();
  913. ImGui::Text("Banana"); ImGui::SameLine();
  914. ImGui::Text("Hello\nWorld"); ImGui::SameLine();
  915. ImGui::Text("Banana");
  916. ImGui::Button("HOP##2"); ImGui::SameLine();
  917. ImGui