2018-06-25 19:20:07 +03:00
// dear imgui, v1.63 WIP
2015-12-25 02:38:10 +03:00
// (demo code)
2015-08-08 19:56:09 +03:00
2017-05-01 19:43:35 +03:00
// Message to the person tempted to delete this file when integrating ImGui into their code base:
2017-07-21 08:41:33 +03:00
// Don't do it! Do NOT remove this file from your project! It is useful reference code that you and other users will want to refer to.
2017-12-25 00:46:50 +03:00
// Everything in this file will be stripped out by the linker if you don't call ImGui::ShowDemoWindow().
// During development, you can call ImGui::ShowDemoWindow() in your code to learn about various features of ImGui. Have it wired in a debug menu!
2017-07-21 08:41:33 +03:00
// Removing this file from your project is hindering access to documentation for everyone in your team, likely leading you to poorer usage of the library.
2017-12-25 00:46:50 +03:00
// Note that you can #define IMGUI_DISABLE_DEMO_WINDOWS in imconfig.h for the same effect.
// If you want to link core ImGui in your final builds but not those demo windows, #define IMGUI_DISABLE_DEMO_WINDOWS in imconfig.h and those functions will be empty.
// In other situation, when you have ImGui available you probably want this to be available for reference and execution.
2017-07-21 08:41:33 +03:00
// Thank you,
// -Your beloved friend, imgui_demo.cpp (that you won't delete)
2015-08-08 19:56:09 +03:00
2018-06-26 19:49:48 +03:00
// Message to beginner C/C++ programmers about the meaning of the 'static' keyword: in this demo code, we frequently we use 'static' variables inside functions.
2018-05-17 18:47:13 +03:00
// A static variable persist across calls, so it is essentially like a global variable but declared inside the scope of the function.
2018-06-26 19:49:48 +03:00
// We do this as a way to gather code and data in the same place, just to make the demo code faster to read, faster to write, and use less code.
2017-08-07 08:32:42 +03:00
// It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be reentrant or used in threads.
2018-06-26 19:49:48 +03:00
// This might be a pattern you occasionally want to use in your code, but most of the real data you would be editing is likely to be stored outside your functions.
2017-08-07 08:32:42 +03:00
2015-08-08 19:56:09 +03:00
# if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
# endif
# include "imgui.h"
2015-11-17 07:32:11 +03:00
# include <ctype.h> // toupper, isprint
2018-05-13 18:58:15 +03:00
# include <limits.h> // INT_MIN, INT_MAX
2016-06-01 08:53:46 +03:00
# include <math.h> // sqrtf, powf, cosf, sinf, floorf, ceilf
2015-11-17 07:32:11 +03:00
# include <stdio.h> // vsnprintf, sscanf, printf
2017-07-16 19:17:12 +03:00
# include <stdlib.h> // NULL, malloc, free, atoi
2015-11-17 07:32:11 +03:00
# if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
# include <stddef.h> // intptr_t
# else
# include <stdint.h> // intptr_t
# endif
2015-08-08 19:56:09 +03:00
# ifdef _MSC_VER
# pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
# define snprintf _snprintf
# endif
# ifdef __clang__
2016-05-05 06:10:06 +03:00
# pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
2015-08-08 19:56:09 +03:00
# 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)
# pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning : cast to 'void *' from smaller integer type 'int'
2015-08-13 09:58:39 +03:00
# pragma clang diagnostic ignored "-Wformat-security" // warning : warning: format string is not a string literal
2016-05-05 06:10:06 +03:00
# 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.
2016-10-13 09:15:46 +03:00
# if __has_warning("-Wreserved-id-macro")
# pragma clang diagnostic ignored "-Wreserved-id-macro" // warning : macro name is a reserved identifier //
# endif
2016-05-09 23:26:55 +03:00
# elif defined(__GNUC__)
2015-08-08 19:56:09 +03:00
# pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size
2015-08-13 09:58:39 +03:00
# pragma GCC diagnostic ignored "-Wformat-security" // warning : format string is not a string literal (potentially insecure)
2016-05-08 20:16:37 +03:00
# pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function
# pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value
2016-11-13 04:14:45 +03:00
# if (__GNUC__ >= 6)
2017-12-25 00:46:50 +03:00
# pragma GCC diagnostic ignored "-Wmisleading-indentation" // warning: this 'if' clause does not guard this statement // GCC 6.0+ only. See #883 on GitHub.
2016-11-13 04:14:45 +03:00
# endif
2015-08-08 19:56:09 +03:00
# endif
2017-12-25 00:46:50 +03:00
// Play it nice with Windows users. Notepad in 2017 still doesn't display text data with Unix-style \n.
2015-08-13 09:58:39 +03:00
# ifdef _WIN32
2015-08-08 19:56:09 +03:00
# define IM_NEWLINE "\r\n"
# else
# define IM_NEWLINE "\n"
# endif
2016-05-22 00:54:06 +03:00
# define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B))
2015-08-08 19:56:09 +03:00
//-----------------------------------------------------------------------------
// DEMO CODE
//-----------------------------------------------------------------------------
2017-12-25 00:46:50 +03:00
# if !defined(IMGUI_DISABLE_OBSOLETE_FUNCTIONS) && defined(IMGUI_DISABLE_TEST_WINDOWS) && !defined(IMGUI_DISABLE_DEMO_WINDOWS) // Obsolete name since 1.53, TEST->DEMO
# define IMGUI_DISABLE_DEMO_WINDOWS
# endif
# if !defined(IMGUI_DISABLE_DEMO_WINDOWS)
2015-08-08 19:56:09 +03:00
2018-06-26 19:49:48 +03:00
// Forward Declarations
2018-07-12 19:05:12 +03:00
static void ShowExampleAppMainMenuBar ( ) ;
2016-05-04 05:29:37 +03:00
static void ShowExampleAppConsole ( bool * p_open ) ;
static void ShowExampleAppLog ( bool * p_open ) ;
static void ShowExampleAppLayout ( bool * p_open ) ;
static void ShowExampleAppPropertyEditor ( bool * p_open ) ;
static void ShowExampleAppLongText ( bool * p_open ) ;
static void ShowExampleAppAutoResize ( bool * p_open ) ;
2016-05-22 00:54:06 +03:00
static void ShowExampleAppConstrainedResize ( bool * p_open ) ;
2018-05-13 18:58:15 +03:00
static void ShowExampleAppSimpleOverlay ( bool * p_open ) ;
2017-12-11 20:27:48 +03:00
static void ShowExampleAppWindowTitles ( bool * p_open ) ;
2016-05-04 05:29:37 +03:00
static void ShowExampleAppCustomRendering ( bool * p_open ) ;
2015-08-08 19:56:09 +03:00
static void ShowExampleMenuFile ( ) ;
2018-06-26 19:49:48 +03:00
// Helper to display a little (?) mark which shows a tooltip when hovered.
2015-08-08 19:56:09 +03:00
static void ShowHelpMarker ( const char * desc )
{
2015-08-26 06:44:36 +03:00
ImGui : : TextDisabled ( " (?) " ) ;
if ( ImGui : : IsItemHovered ( ) )
2016-09-26 05:41:51 +03:00
{
ImGui : : BeginTooltip ( ) ;
2018-01-31 06:03:53 +03:00
ImGui : : PushTextWrapPos ( ImGui : : GetFontSize ( ) * 35.0f ) ;
2016-09-26 05:41:51 +03:00
ImGui : : TextUnformatted ( desc ) ;
ImGui : : PopTextWrapPos ( ) ;
ImGui : : EndTooltip ( ) ;
}
2015-08-08 19:56:09 +03:00
}
2018-06-26 19:49:48 +03:00
// Helper to display basic user controls.
2015-08-08 19:56:09 +03:00
void ImGui : : ShowUserGuide ( )
{
ImGui : : BulletText ( " Double-click on title bar to collapse window. " ) ;
2017-11-01 19:00:10 +03:00
ImGui : : BulletText ( " Click and drag on lower right corner to resize window \n (double-click to auto fit window to its contents). " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : BulletText ( " Click and drag on any empty space to move window. " ) ;
2017-11-01 19:00:10 +03:00
ImGui : : BulletText ( " TAB/SHIFT+TAB to cycle through keyboard editable fields. " ) ;
ImGui : : BulletText ( " CTRL+Click on a slider or drag box to input value as text. " ) ;
2015-08-08 19:56:09 +03:00
if ( ImGui : : GetIO ( ) . FontAllowUserScaling )
ImGui : : BulletText ( " CTRL+Mouse Wheel to zoom window contents. " ) ;
2017-11-01 19:00:10 +03:00
ImGui : : BulletText ( " Mouse Wheel to scroll. " ) ;
ImGui : : BulletText ( " While editing text: \n " ) ;
ImGui : : Indent ( ) ;
ImGui : : BulletText ( " Hold SHIFT or use mouse to select text. " ) ;
ImGui : : BulletText ( " CTRL+Left/Right to word jump. " ) ;
ImGui : : BulletText ( " CTRL+A or double-click to select all. " ) ;
ImGui : : BulletText ( " CTRL+X,CTRL+C,CTRL+V to use clipboard. " ) ;
ImGui : : BulletText ( " CTRL+Z,CTRL+Y to undo/redo. " ) ;
ImGui : : BulletText ( " ESCAPE to revert. " ) ;
ImGui : : BulletText ( " You can apply arithmetic operators +,*,/ on numerical values. \n Use +- to subtract. " ) ;
ImGui : : Unindent ( ) ;
2015-08-08 19:56:09 +03:00
}
2018-06-26 19:49:48 +03:00
// Demonstrate most Dear ImGui features (this is big function!)
// You may execute this function to experiment with the UI and understand what it does. You may then search for keywords in the code when you are interested by a specific feature.
2017-12-25 00:46:50 +03:00
void ImGui : : ShowDemoWindow ( bool * p_open )
2015-08-08 19:56:09 +03:00
{
2018-06-26 19:49:48 +03:00
// Examples Apps (accessible from the "Examples" menu)
2015-08-08 19:56:09 +03:00
static bool show_app_main_menu_bar = false ;
static bool show_app_console = false ;
2015-08-20 07:51:25 +03:00
static bool show_app_log = false ;
2015-08-08 19:56:09 +03:00
static bool show_app_layout = false ;
2015-11-29 04:58:18 +03:00
static bool show_app_property_editor = false ;
2015-08-08 19:56:09 +03:00
static bool show_app_long_text = false ;
static bool show_app_auto_resize = false ;
2016-05-22 00:54:06 +03:00
static bool show_app_constrained_resize = false ;
2018-05-13 18:58:15 +03:00
static bool show_app_simple_overlay = false ;
2017-12-11 20:27:48 +03:00
static bool show_app_window_titles = false ;
2015-12-15 09:56:16 +03:00
static bool show_app_custom_rendering = false ;
2017-12-11 20:27:48 +03:00
if ( show_app_main_menu_bar ) ShowExampleAppMainMenuBar ( ) ;
if ( show_app_console ) ShowExampleAppConsole ( & show_app_console ) ;
if ( show_app_log ) ShowExampleAppLog ( & show_app_log ) ;
if ( show_app_layout ) ShowExampleAppLayout ( & show_app_layout ) ;
if ( show_app_property_editor ) ShowExampleAppPropertyEditor ( & show_app_property_editor ) ;
if ( show_app_long_text ) ShowExampleAppLongText ( & show_app_long_text ) ;
if ( show_app_auto_resize ) ShowExampleAppAutoResize ( & show_app_auto_resize ) ;
if ( show_app_constrained_resize ) ShowExampleAppConstrainedResize ( & show_app_constrained_resize ) ;
2018-05-13 18:58:15 +03:00
if ( show_app_simple_overlay ) ShowExampleAppSimpleOverlay ( & show_app_simple_overlay ) ;
2017-12-11 20:27:48 +03:00
if ( show_app_window_titles ) ShowExampleAppWindowTitles ( & show_app_window_titles ) ;
if ( show_app_custom_rendering ) ShowExampleAppCustomRendering ( & show_app_custom_rendering ) ;
2018-06-26 19:49:48 +03:00
// Dear ImGui Apps (accessible from the "Help" menu)
static bool show_app_metrics = false ;
static bool show_app_style_editor = false ;
static bool show_app_about = false ;
2017-12-11 20:27:48 +03:00
if ( show_app_metrics ) { ImGui : : ShowMetricsWindow ( & show_app_metrics ) ; }
if ( show_app_style_editor ) { ImGui : : Begin ( " Style Editor " , & show_app_style_editor ) ; ImGui : : ShowStyleEditor ( ) ; ImGui : : End ( ) ; }
2015-08-08 19:56:09 +03:00
if ( show_app_about )
{
2017-12-11 20:27:48 +03:00
ImGui : : Begin ( " About Dear ImGui " , & show_app_about , ImGuiWindowFlags_AlwaysAutoResize ) ;
2018-01-03 20:23:33 +03:00
ImGui : : Text ( " Dear ImGui, %s " , ImGui : : GetVersion ( ) ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Separator ( ) ;
2017-12-11 20:27:48 +03:00
ImGui : : Text ( " By Omar Cornut and all dear imgui contributors. " ) ;
ImGui : : Text ( " Dear ImGui is licensed under the MIT License, see LICENSE for more information. " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : End ( ) ;
}
2018-06-26 19:49:48 +03:00
// Demonstrate the various window flags. Typically you would just use the default!
2015-08-08 19:56:09 +03:00
static bool no_titlebar = false ;
static bool no_scrollbar = false ;
static bool no_menu = false ;
2017-11-20 19:29:10 +03:00
static bool no_move = false ;
static bool no_resize = false ;
static bool no_collapse = false ;
2017-12-11 04:19:51 +03:00
static bool no_close = false ;
2018-02-07 00:24:05 +03:00
static bool no_nav = false ;
2015-08-08 19:56:09 +03:00
ImGuiWindowFlags window_flags = 0 ;
if ( no_titlebar ) window_flags | = ImGuiWindowFlags_NoTitleBar ;
if ( no_scrollbar ) window_flags | = ImGuiWindowFlags_NoScrollbar ;
if ( ! no_menu ) window_flags | = ImGuiWindowFlags_MenuBar ;
2017-11-20 19:29:10 +03:00
if ( no_move ) window_flags | = ImGuiWindowFlags_NoMove ;
if ( no_resize ) window_flags | = ImGuiWindowFlags_NoResize ;
if ( no_collapse ) window_flags | = ImGuiWindowFlags_NoCollapse ;
2018-02-07 00:24:05 +03:00
if ( no_nav ) window_flags | = ImGuiWindowFlags_NoNav ;
2017-12-11 04:19:51 +03:00
if ( no_close ) p_open = NULL ; // Don't pass our bool* to Begin
2018-07-17 19:18:14 +03:00
// We specify a default position/size in case there's no data in the .ini file. Typically this isn't required! We only do it to make the Demo applications a little more welcoming.
ImGui : : SetNextWindowPos ( ImVec2 ( 650 , 20 ) , ImGuiCond_FirstUseEver ) ;
ImGui : : SetNextWindowSize ( ImVec2 ( 550 , 680 ) , ImGuiCond_FirstUseEver ) ;
2018-06-26 19:49:48 +03:00
// Main body of the Demo window starts here.
2016-05-04 05:29:37 +03:00
if ( ! ImGui : : Begin ( " ImGui Demo " , p_open , window_flags ) )
2015-08-08 19:56:09 +03:00
{
// Early out if the window is collapsed, as an optimization.
ImGui : : End ( ) ;
return ;
}
2017-08-24 19:58:46 +03:00
ImGui : : Text ( " dear imgui says hello. (%s) " , IMGUI_VERSION ) ;
2015-08-08 19:56:09 +03:00
2018-06-26 19:49:48 +03:00
// Most "big" widgets share a common width settings by default.
//ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // Use 2/3 of the space for widgets and 1/3 for labels (default)
ImGui : : PushItemWidth ( ImGui : : GetFontSize ( ) * - 12 ) ; // Use fixed width for labels (by passing a negative value), the rest goes to widgets. We choose a width proportional to our font size.
2015-08-08 19:56:09 +03:00
// Menu
if ( ImGui : : BeginMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " Menu " ) )
{
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Examples " ) )
{
ImGui : : MenuItem ( " Main menu bar " , NULL , & show_app_main_menu_bar ) ;
ImGui : : MenuItem ( " Console " , NULL , & show_app_console ) ;
2015-08-20 07:51:25 +03:00
ImGui : : MenuItem ( " Log " , NULL , & show_app_log ) ;
2015-08-08 19:56:09 +03:00
ImGui : : MenuItem ( " Simple layout " , NULL , & show_app_layout ) ;
2015-11-29 04:58:18 +03:00
ImGui : : MenuItem ( " Property editor " , NULL , & show_app_property_editor ) ;
2015-08-08 19:56:09 +03:00
ImGui : : MenuItem ( " Long text display " , NULL , & show_app_long_text ) ;
ImGui : : MenuItem ( " Auto-resizing window " , NULL , & show_app_auto_resize ) ;
2016-05-22 00:54:06 +03:00
ImGui : : MenuItem ( " Constrained-resizing window " , NULL , & show_app_constrained_resize ) ;
2018-05-13 18:58:15 +03:00
ImGui : : MenuItem ( " Simple overlay " , NULL , & show_app_simple_overlay ) ;
2017-12-11 20:27:48 +03:00
ImGui : : MenuItem ( " Manipulating window titles " , NULL , & show_app_window_titles ) ;
2015-08-08 19:56:09 +03:00
ImGui : : MenuItem ( " Custom rendering " , NULL , & show_app_custom_rendering ) ;
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Help " ) )
{
ImGui : : MenuItem ( " Metrics " , NULL , & show_app_metrics ) ;
2015-12-15 09:56:16 +03:00
ImGui : : MenuItem ( " Style Editor " , NULL , & show_app_style_editor ) ;
2017-12-11 20:27:48 +03:00
ImGui : : MenuItem ( " About Dear ImGui " , NULL , & show_app_about ) ;
2015-08-08 19:56:09 +03:00
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenuBar ( ) ;
}
ImGui : : Spacing ( ) ;
if ( ImGui : : CollapsingHeader ( " Help " ) )
{
2017-12-25 00:46:50 +03:00
ImGui : : TextWrapped ( " This window is being created by the ShowDemoWindow() function. Please refer to the code in imgui_demo.cpp for reference. \n \n " ) ;
2017-11-01 19:00:10 +03:00
ImGui : : Text ( " USER GUIDE: " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : ShowUserGuide ( ) ;
}
if ( ImGui : : CollapsingHeader ( " Window options " ) )
{
2015-12-15 09:56:16 +03:00
ImGui : : Checkbox ( " No titlebar " , & no_titlebar ) ; ImGui : : SameLine ( 150 ) ;
ImGui : : Checkbox ( " No scrollbar " , & no_scrollbar ) ; ImGui : : SameLine ( 300 ) ;
ImGui : : Checkbox ( " No menu " , & no_menu ) ;
2017-11-20 19:29:10 +03:00
ImGui : : Checkbox ( " No move " , & no_move ) ; ImGui : : SameLine ( 150 ) ;
ImGui : : Checkbox ( " No resize " , & no_resize ) ; ImGui : : SameLine ( 300 ) ;
ImGui : : Checkbox ( " No collapse " , & no_collapse ) ;
2018-02-07 00:24:05 +03:00
ImGui : : Checkbox ( " No close " , & no_close ) ; ImGui : : SameLine ( 150 ) ;
ImGui : : Checkbox ( " No nav " , & no_nav ) ;
2015-12-15 09:56:16 +03:00
2015-08-08 19:56:09 +03:00
if ( ImGui : : TreeNode ( " Style " ) )
{
ImGui : : ShowStyleEditor ( ) ;
ImGui : : TreePop ( ) ;
}
2017-12-11 04:19:51 +03:00
if ( ImGui : : TreeNode ( " Capture/Logging " ) )
2015-08-08 19:56:09 +03:00
{
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. " ) ;
ImGui : : LogButtons ( ) ;
ImGui : : TreePop ( ) ;
}
}
if ( ImGui : : CollapsingHeader ( " Widgets " ) )
{
2017-08-08 19:11:10 +03:00
if ( ImGui : : TreeNode ( " Basic " ) )
{
static int clicked = 0 ;
2018-05-17 18:47:13 +03:00
if ( ImGui : : Button ( " Button " ) )
2017-08-08 19:11:10 +03:00
clicked + + ;
if ( clicked & 1 )
{
ImGui : : SameLine ( ) ;
ImGui : : Text ( " Thanks for clicking me! " ) ;
}
static bool check = true ;
ImGui : : Checkbox ( " checkbox " , & check ) ;
static int e = 0 ;
ImGui : : RadioButton ( " radio a " , & e , 0 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " radio b " , & e , 1 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " radio c " , & e , 2 ) ;
// Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
for ( int i = 0 ; i < 7 ; i + + )
{
if ( i > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushID ( i ) ;
2017-08-20 20:25:00 +03:00
ImGui : : PushStyleColor ( ImGuiCol_Button , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.6f , 0.6f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonHovered , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.7f , 0.7f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonActive , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.8f , 0.8f ) ) ;
2017-08-08 19:11:10 +03:00
ImGui : : Button ( " Click " ) ;
ImGui : : PopStyleColor ( 3 ) ;
ImGui : : PopID ( ) ;
}
2018-03-03 22:21:53 +03:00
// Arrow buttons
2018-06-26 19:49:48 +03:00
static int counter = 0 ;
2018-03-03 22:21:53 +03:00
float spacing = ImGui : : GetStyle ( ) . ItemInnerSpacing . x ;
2018-06-26 19:49:48 +03:00
ImGui : : PushButtonRepeat ( true ) ;
if ( ImGui : : ArrowButton ( " ##left " , ImGuiDir_Left ) ) { counter - - ; }
2018-03-03 22:21:53 +03:00
ImGui : : SameLine ( 0.0f , spacing ) ;
2018-06-26 19:49:48 +03:00
if ( ImGui : : ArrowButton ( " ##right " , ImGuiDir_Right ) ) { counter + + ; }
ImGui : : PopButtonRepeat ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : Text ( " %d " , counter ) ;
2018-03-03 22:21:53 +03:00
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Hover over me " ) ;
if ( ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( " I am a tooltip " ) ;
ImGui : : SameLine ( ) ;
ImGui : : Text ( " - or me " ) ;
if ( ImGui : : IsItemHovered ( ) )
{
ImGui : : BeginTooltip ( ) ;
ImGui : : Text ( " I am a fancy tooltip " ) ;
static float arr [ ] = { 0.6f , 0.1f , 1.0f , 0.5f , 0.92f , 0.1f , 0.2f } ;
ImGui : : PlotLines ( " Curve " , arr , IM_ARRAYSIZE ( arr ) ) ;
ImGui : : EndTooltip ( ) ;
}
ImGui : : Separator ( ) ;
ImGui : : LabelText ( " label " , " Value " ) ;
2017-12-25 21:41:53 +03:00
{
2018-03-20 06:00:57 +03:00
// Using the _simplified_ one-liner Combo() api here
2018-06-12 20:59:28 +03:00
// See "Combo" section for examples of how to use the more complete BeginCombo()/EndCombo() api.
2018-03-20 06:00:57 +03:00
const char * items [ ] = { " AAAA " , " BBBB " , " CCCC " , " DDDD " , " EEEE " , " FFFF " , " GGGG " , " HHHH " , " IIII " , " JJJJ " , " KKKK " , " LLLLLLL " , " MMMM " , " OOOOOOO " } ;
static int item_current = 0 ;
ImGui : : Combo ( " combo " , & item_current , items , IM_ARRAYSIZE ( items ) ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Refer to the \" Combo \" section below for an explanation of the full BeginCombo/EndCombo API, and demonstration of various flags. \n " ) ;
2017-12-25 21:41:53 +03:00
}
2017-08-08 19:11:10 +03:00
{
static char str0 [ 128 ] = " Hello, world! " ;
2018-03-23 07:11:18 +03:00
static int i0 = 123 ;
2017-08-08 19:11:10 +03:00
ImGui : : InputText ( " input text " , str0 , IM_ARRAYSIZE ( str0 ) ) ;
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 " ) ;
ImGui : : InputInt ( " input int " , & i0 ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " You can apply arithmetic operators +,*,/ on numerical values. \n e.g. [ 100 ], input \' *2 \' , result becomes [ 200 ] \n Use +- to subtract. \n " ) ;
2018-04-28 02:16:56 +03:00
static float f0 = 0.001f ;
2017-08-08 19:11:10 +03:00
ImGui : : InputFloat ( " input float " , & f0 , 0.01f , 1.0f ) ;
2018-05-11 18:26:25 +03:00
static double d0 = 999999.00000001 ;
ImGui : : InputDouble ( " input double " , & d0 , 0.01f , 1.0f , " %.8f " ) ;
2018-04-28 02:16:56 +03:00
static float f1 = 1.e10 f ;
ImGui : : InputFloat ( " input scientific " , & f1 , 0.0f , 0.0f , " %e " ) ;
2018-03-23 07:11:18 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " You can input value using the scientific notation, \n e.g. \" 1e+8 \" becomes \" 100000000 \" . \n " ) ;
2017-08-08 19:11:10 +03:00
static float vec4a [ 4 ] = { 0.10f , 0.20f , 0.30f , 0.44f } ;
ImGui : : InputFloat3 ( " input float3 " , vec4a ) ;
}
{
2018-03-23 07:11:18 +03:00
static int i1 = 50 , i2 = 42 ;
2017-08-08 19:11:10 +03:00
ImGui : : DragInt ( " drag int " , & i1 , 1 ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Click and drag to edit value. \n Hold SHIFT/ALT for faster/slower edit. \n Double-click or CTRL+click to input value. " ) ;
2018-05-11 18:26:25 +03:00
ImGui : : DragInt ( " drag int 0..100 " , & i2 , 1 , 0 , 100 , " %d%% " ) ;
2017-08-08 19:11:10 +03:00
static float f1 = 1.00f , f2 = 0.0067f ;
ImGui : : DragFloat ( " drag float " , & f1 , 0.005f ) ;
ImGui : : DragFloat ( " drag small float " , & f2 , 0.0001f , 0.0f , 0.0f , " %.06f ns " ) ;
}
{
static int i1 = 0 ;
ImGui : : SliderInt ( " slider int " , & i1 , - 1 , 3 ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " CTRL+click to input value. " ) ;
static float f1 = 0.123f , f2 = 0.0f ;
ImGui : : SliderFloat ( " slider float " , & f1 , 0.0f , 1.0f , " ratio = %.3f " ) ;
2018-05-11 18:26:25 +03:00
ImGui : : SliderFloat ( " slider float (curve) " , & f2 , - 10.0f , 10.0f , " %.4f " , 2.0f ) ;
2017-08-08 19:11:10 +03:00
static float angle = 0.0f ;
ImGui : : SliderAngle ( " slider angle " , & angle ) ;
}
2018-03-20 06:00:57 +03:00
{
static float col1 [ 3 ] = { 1.0f , 0.0f , 0.2f } ;
static float col2 [ 4 ] = { 0.4f , 0.7f , 0.0f , 0.5f } ;
ImGui : : ColorEdit3 ( " color 1 " , col1 ) ;
2018-07-09 17:38:59 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Click on the colored square to open a color picker. \n Click and hold to use drag and drop. \n Right-click on the colored square to show options. \n CTRL+click on individual component to input value. \n " ) ;
2017-08-08 19:11:10 +03:00
2018-03-20 06:00:57 +03:00
ImGui : : ColorEdit4 ( " color 2 " , col2 ) ;
}
2017-08-08 19:11:10 +03:00
2018-03-20 06:00:57 +03:00
{
// List box
const char * listbox_items [ ] = { " Apple " , " Banana " , " Cherry " , " Kiwi " , " Mango " , " Orange " , " Pineapple " , " Strawberry " , " Watermelon " } ;
static int listbox_item_current = 1 ;
ImGui : : ListBox ( " listbox \n (single select) " , & listbox_item_current , listbox_items , IM_ARRAYSIZE ( listbox_items ) , 4 ) ;
//static int listbox_item_current2 = 2;
//ImGui::PushItemWidth(-1);
//ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
//ImGui::PopItemWidth();
}
2017-08-08 19:11:10 +03:00
ImGui : : TreePop ( ) ;
}
2018-03-20 06:00:57 +03:00
// Testing ImGuiOnceUponAFrame helper.
//static ImGuiOnceUponAFrame once;
//for (int i = 0; i < 5; i++)
// if (once)
// ImGui::Text("This will be displayed only once.");
2016-04-26 07:11:13 +03:00
if ( ImGui : : TreeNode ( " Trees " ) )
2015-08-08 19:56:09 +03:00
{
2016-05-02 02:46:36 +03:00
if ( ImGui : : TreeNode ( " Basic trees " ) )
2015-08-08 19:56:09 +03:00
{
2016-05-02 02:46:36 +03:00
for ( int i = 0 ; i < 5 ; i + + )
if ( ImGui : : TreeNode ( ( void * ) ( intptr_t ) i , " Child %d " , i ) )
{
ImGui : : Text ( " blah blah " ) ;
2018-05-17 18:47:13 +03:00
ImGui : : SameLine ( ) ;
2018-01-03 20:23:33 +03:00
if ( ImGui : : SmallButton ( " button " ) ) { } ;
2016-05-02 02:46:36 +03:00
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
2016-05-29 19:17:23 +03:00
if ( ImGui : : TreeNode ( " Advanced, with Selectable nodes " ) )
2016-05-02 02:46:36 +03:00
{
2016-05-28 22:12:59 +03:00
ShowHelpMarker ( " This is a more standard looking tree with selectable nodes. \n Click to select, CTRL+Click to toggle, click on arrows or double-click to open. " ) ;
2016-05-29 19:17:23 +03:00
static bool align_label_with_current_x_position = false ;
ImGui : : Checkbox ( " Align label with current X position) " , & align_label_with_current_x_position ) ;
ImGui : : Text ( " Hello! " ) ;
if ( align_label_with_current_x_position )
ImGui : : Unindent ( ImGui : : GetTreeNodeToLabelSpacing ( ) ) ;
2016-05-28 22:12:59 +03:00
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.
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.
2016-05-29 19:17:23 +03:00
ImGui : : PushStyleVar ( ImGuiStyleVar_IndentSpacing , ImGui : : GetFontSize ( ) * 3 ) ; // Increase spacing to differentiate leaves from expanded contents.
2016-05-02 02:46:36 +03:00
for ( int i = 0 ; i < 6 ; i + + )
2015-08-08 19:56:09 +03:00
{
2016-05-28 22:12:59 +03:00
// Disable the default open on single-click behavior and pass in Selected flag according to our selection state.
2016-05-29 19:17:23 +03:00
ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ( ( selection_mask & ( 1 < < i ) ) ? ImGuiTreeNodeFlags_Selected : 0 ) ;
2016-05-28 22:12:59 +03:00
if ( i < 3 )
2016-05-02 02:46:36 +03:00
{
2016-05-28 22:12:59 +03:00
// Node
bool node_open = ImGui : : TreeNodeEx ( ( void * ) ( intptr_t ) i , node_flags , " Selectable Node %d " , i ) ;
2018-05-17 18:47:13 +03:00
if ( ImGui : : IsItemClicked ( ) )
2016-05-28 22:12:59 +03:00
node_clicked = i ;
if ( node_open )
{
ImGui : : Text ( " Blah blah \n Blah Blah " ) ;
ImGui : : TreePop ( ) ;
}
}
else
{
2016-05-29 19:17:23 +03:00
// 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().
2018-06-14 17:38:10 +03:00
node_flags | = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen ; // ImGuiTreeNodeFlags_Bullet
2017-10-12 09:33:45 +03:00
ImGui : : TreeNodeEx ( ( void * ) ( intptr_t ) i , node_flags , " Selectable Leaf %d " , i ) ;
2018-05-15 18:26:24 +03:00
if ( ImGui : : IsItemClicked ( ) )
2016-05-28 22:12:59 +03:00
node_clicked = i ;
2016-05-02 02:46:36 +03:00
}
}
if ( node_clicked ! = - 1 )
{
// Update selection state. Process outside of tree loop to avoid visual inconsistencies during the clicking-frame.
if ( ImGui : : GetIO ( ) . KeyCtrl )
2016-05-28 22:12:59 +03:00
selection_mask ^ = ( 1 < < node_clicked ) ; // CTRL+click to toggle
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
selection_mask = ( 1 < < node_clicked ) ; // Click to single-select
2015-08-08 19:56:09 +03:00
}
2016-05-28 22:12:59 +03:00
ImGui : : PopStyleVar ( ) ;
2016-05-29 19:17:23 +03:00
if ( align_label_with_current_x_position )
ImGui : : Indent ( ImGui : : GetTreeNodeToLabelSpacing ( ) ) ;
2016-05-02 02:46:36 +03:00
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Collapsing Headers " ) )
{
static bool closable_group = true ;
2017-10-19 07:31:01 +03:00
ImGui : : Checkbox ( " Enable extra group " , & closable_group ) ;
2016-05-02 02:46:36 +03:00
if ( ImGui : : CollapsingHeader ( " Header " ) )
{
2017-10-19 07:31:01 +03:00
ImGui : : Text ( " IsItemHovered: %d " , IsItemHovered ( ) ) ;
2016-05-02 02:46:36 +03:00
for ( int i = 0 ; i < 5 ; i + + )
ImGui : : Text ( " Some content %d " , i ) ;
}
if ( ImGui : : CollapsingHeader ( " Header with a close button " , & closable_group ) )
{
2017-10-19 07:31:01 +03:00
ImGui : : Text ( " IsItemHovered: %d " , IsItemHovered ( ) ) ;
2016-05-02 02:46:36 +03:00
for ( int i = 0 ; i < 5 ; i + + )
ImGui : : Text ( " More content %d " , i ) ;
2015-08-08 19:56:09 +03:00
}
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Bullets " ) )
{
ImGui : : BulletText ( " Bullet point 1 " ) ;
ImGui : : BulletText ( " Bullet point 2 \n On multiple lines " ) ;
ImGui : : Bullet ( ) ; ImGui : : Text ( " Bullet point 3 (two calls) " ) ;
ImGui : : Bullet ( ) ; ImGui : : SmallButton ( " Button " ) ;
ImGui : : TreePop ( ) ;
}
2017-08-08 19:11:10 +03:00
if ( ImGui : : TreeNode ( " Text " ) )
2015-08-08 19:56:09 +03:00
{
2017-08-08 19:11:10 +03:00
if ( ImGui : : TreeNode ( " Colored Text " ) )
{
// Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
ImGui : : TextColored ( ImVec4 ( 1.0f , 0.0f , 1.0f , 1.0f ) , " Pink " ) ;
ImGui : : TextColored ( ImVec4 ( 1.0f , 1.0f , 0.0f , 1.0f ) , " Yellow " ) ;
ImGui : : TextDisabled ( " Disabled " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " The TextDisabled color is stored in ImGuiStyle. " ) ;
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
if ( ImGui : : TreeNode ( " Word Wrapping " ) )
{
// Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
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. " ) ;
ImGui : : Spacing ( ) ;
static float wrap_width = 200.0f ;
ImGui : : SliderFloat ( " Wrap width " , & wrap_width , - 20 , 600 , " %.0f " ) ;
ImGui : : Text ( " Test paragraph 1: " ) ;
ImVec2 pos = ImGui : : GetCursorScreenPos ( ) ;
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 ) ) ;
ImGui : : PushTextWrapPos ( ImGui : : GetCursorPos ( ) . x + wrap_width ) ;
ImGui : : Text ( " The lazy dog is a good dog. This paragraph is made to fit within %.0f pixels. Testing a 1 character word. The quick brown fox jumps over the lazy dog. " , wrap_width ) ;
ImGui : : GetWindowDrawList ( ) - > AddRect ( ImGui : : GetItemRectMin ( ) , ImGui : : GetItemRectMax ( ) , IM_COL32 ( 255 , 255 , 0 , 255 ) ) ;
ImGui : : PopTextWrapPos ( ) ;
ImGui : : Text ( " Test paragraph 2: " ) ;
pos = ImGui : : GetCursorScreenPos ( ) ;
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 ) ) ;
ImGui : : PushTextWrapPos ( ImGui : : GetCursorPos ( ) . x + wrap_width ) ;
ImGui : : Text ( " aaaaaaaa bbbbbbbb, c cccccccc,dddddddd. d eeeeeeee ffffffff. gggggggg!hhhhhhhh " ) ;
ImGui : : GetWindowDrawList ( ) - > AddRect ( ImGui : : GetItemRectMin ( ) , ImGui : : GetItemRectMax ( ) , IM_COL32 ( 255 , 255 , 0 , 255 ) ) ;
ImGui : : PopTextWrapPos ( ) ;
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
if ( ImGui : : TreeNode ( " UTF-8 Text " ) )
{
// UTF-8 test with Japanese characters
2018-05-11 18:26:25 +03:00
// (Needs a suitable font, try Noto, or Arial Unicode, or M+ fonts. Read misc/fonts/README.txt for details.)
2017-08-08 19:11:10 +03:00
// - From C++11 you can use the u8"my text" syntax to encode literal strings as UTF-8
// - For earlier compiler, you may be able to encode your sources as UTF-8 (e.g. Visual Studio save your file as 'UTF-8 without signature')
2018-05-11 18:26:25 +03:00
// - FOR THIS DEMO FILE ONLY, BECAUSE WE WANT TO SUPPORT OLD COMPILERS, WE ARE *NOT* INCLUDING RAW UTF-8 CHARACTERS IN THIS SOURCE FILE.
2018-05-17 18:47:13 +03:00
// Instead we are encoding a few strings with hexadecimal constants. Don't do this in your application!
2018-05-11 18:26:25 +03:00
// Please use u8"text in any language" in your application!
2017-08-08 19:11:10 +03:00
// Note that characters values are preserved even by InputText() if the font cannot be displayed, so you can safely copy & paste garbled characters into another application.
2018-05-11 18:26:25 +03:00
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. Read misc/fonts/README.txt for details. " ) ;
ImGui : : Text ( " Hiragana: \xe3 \x81 \x8b \xe3 \x81 \x8d \xe3 \x81 \x8f \xe3 \x81 \x91 \xe3 \x81 \x93 (kakikukeko) " ) ; // Normally we would use u8"blah blah" with the proper characters directly in the string.
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Kanjis: \xe6 \x97 \xa5 \xe6 \x9c \xac \xe8 \xaa \x9e (nihongo) " ) ;
2018-05-11 18:26:25 +03:00
static char buf [ 32 ] = " \xe6 \x97 \xa5 \xe6 \x9c \xac \xe8 \xaa \x9e " ;
//static char buf[32] = u8"NIHONGO"; // <- this is how you would write it with C++11, using real kanjis
2017-08-08 19:11:10 +03:00
ImGui : : InputText ( " UTF-8 input " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Images " ) )
{
2017-11-01 19:00:10 +03:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
2018-03-20 06:00:57 +03:00
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! " ) ;
2017-11-01 19:00:10 +03:00
// Here we are grabbing the font texture because that's the only one we have access to inside the demo code.
// Remember that ImTextureID is just storage for whatever you want it to be, it is essentially a value that will be passed to the render function inside the ImDrawCmd structure.
// If you use one of the default imgui_impl_XXXX.cpp renderer, they all have comments at the top of their file to specify what they expect to be stored in ImTextureID.
// (for example, the imgui_impl_dx11.cpp renderer expect a 'ID3D11ShaderResourceView*' pointer. The imgui_impl_glfw_gl3.cpp renderer expect a GLuint OpenGL texture identifier etc.)
// If you decided that ImTextureID = MyEngineTexture*, then you can pass your MyEngineTexture* pointers to ImGui::Image(), and gather width/height through your own functions, etc.
// Using ShowMetricsWindow() as a "debugger" to inspect the draw data that are being passed to your render will help you debug issues if you are confused about this.
// Consider using the lower-level ImDrawList::AddImage() API, via ImGui::GetWindowDrawList()->AddImage().
2018-05-17 18:47:13 +03:00
ImTextureID my_tex_id = io . Fonts - > TexID ;
2017-11-20 19:29:10 +03:00
float my_tex_w = ( float ) io . Fonts - > TexWidth ;
float my_tex_h = ( float ) io . Fonts - > TexHeight ;
2017-11-01 19:00:10 +03:00
2017-11-20 19:29:10 +03:00
ImGui : : Text ( " %.0fx%.0f " , my_tex_w , my_tex_h ) ;
ImVec2 pos = ImGui : : GetCursorScreenPos ( ) ;
ImGui : : Image ( my_tex_id , ImVec2 ( my_tex_w , my_tex_h ) , ImVec2 ( 0 , 0 ) , ImVec2 ( 1 , 1 ) , ImColor ( 255 , 255 , 255 , 255 ) , ImColor ( 255 , 255 , 255 , 128 ) ) ;
2015-08-08 19:56:09 +03:00
if ( ImGui : : IsItemHovered ( ) )
{
ImGui : : BeginTooltip ( ) ;
2018-03-20 06:00:57 +03:00
float region_sz = 32.0f ;
float region_x = io . MousePos . x - pos . x - region_sz * 0.5f ; if ( region_x < 0.0f ) region_x = 0.0f ; else if ( region_x > my_tex_w - region_sz ) region_x = my_tex_w - region_sz ;
float region_y = io . MousePos . y - pos . y - region_sz * 0.5f ; if ( region_y < 0.0f ) region_y = 0.0f ; else if ( region_y > my_tex_h - region_sz ) region_y = my_tex_h - region_sz ;
float zoom = 4.0f ;
ImGui : : Text ( " Min: (%.2f, %.2f) " , region_x , region_y ) ;
ImGui : : Text ( " Max: (%.2f, %.2f) " , region_x + region_sz , region_y + region_sz ) ;
ImVec2 uv0 = ImVec2 ( ( region_x ) / my_tex_w , ( region_y ) / my_tex_h ) ;
ImVec2 uv1 = ImVec2 ( ( region_x + region_sz ) / my_tex_w , ( region_y + region_sz ) / my_tex_h ) ;
ImGui : : Image ( my_tex_id , ImVec2 ( region_sz * zoom , region_sz * zoom ) , uv0 , uv1 , ImColor ( 255 , 255 , 255 , 255 ) , ImColor ( 255 , 255 , 255 , 128 ) ) ;
2015-08-08 19:56:09 +03:00
ImGui : : EndTooltip ( ) ;
}
ImGui : : TextWrapped ( " And now some textured buttons.. " ) ;
static int pressed_count = 0 ;
for ( int i = 0 ; i < 8 ; i + + )
{
ImGui : : PushID ( i ) ;
int frame_padding = - 1 + i ; // -1 = uses default padding
2017-11-20 19:29:10 +03:00
if ( ImGui : : ImageButton ( my_tex_id , ImVec2 ( 32 , 32 ) , ImVec2 ( 0 , 0 ) , ImVec2 ( 32.0f / my_tex_w , 32 / my_tex_h ) , frame_padding , ImColor ( 0 , 0 , 0 , 255 ) ) )
2015-08-08 19:56:09 +03:00
pressed_count + = 1 ;
ImGui : : PopID ( ) ;
2016-05-21 19:27:18 +03:00
ImGui : : SameLine ( ) ;
2015-08-08 19:56:09 +03:00
}
2016-05-21 19:27:18 +03:00
ImGui : : NewLine ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " Pressed %d times. " , pressed_count ) ;
ImGui : : TreePop ( ) ;
}
2018-03-20 06:00:57 +03:00
if ( ImGui : : TreeNode ( " Combo " ) )
{
// Expose flags as checkbox for the demo
static ImGuiComboFlags flags = 0 ;
ImGui : : CheckboxFlags ( " ImGuiComboFlags_PopupAlignLeft " , ( unsigned int * ) & flags , ImGuiComboFlags_PopupAlignLeft ) ;
if ( ImGui : : CheckboxFlags ( " ImGuiComboFlags_NoArrowButton " , ( unsigned int * ) & flags , ImGuiComboFlags_NoArrowButton ) )
flags & = ~ ImGuiComboFlags_NoPreview ; // Clear the other flag, as we cannot combine both
if ( ImGui : : CheckboxFlags ( " ImGuiComboFlags_NoPreview " , ( unsigned int * ) & flags , ImGuiComboFlags_NoPreview ) )
flags & = ~ ImGuiComboFlags_NoArrowButton ; // Clear the other flag, as we cannot combine both
// General BeginCombo() API, you have full control over your selection data and display type.
// (your selection data could be an index, a pointer to the object, an id for the object, a flag stored in the object itself, etc.)
const char * items [ ] = { " AAAA " , " BBBB " , " CCCC " , " DDDD " , " EEEE " , " FFFF " , " GGGG " , " HHHH " , " IIII " , " JJJJ " , " KKKK " , " LLLLLLL " , " MMMM " , " OOOOOOO " } ;
static const char * item_current = items [ 0 ] ; // Here our selection is a single pointer stored outside the object.
if ( ImGui : : BeginCombo ( " combo 1 " , item_current , flags ) ) // The second parameter is the label previewed before opening the combo.
{
for ( int n = 0 ; n < IM_ARRAYSIZE ( items ) ; n + + )
{
bool is_selected = ( item_current = = items [ n ] ) ;
if ( ImGui : : Selectable ( items [ n ] , is_selected ) )
item_current = items [ n ] ;
if ( is_selected )
ImGui : : SetItemDefaultFocus ( ) ; // Set the initial focus when opening the combo (scrolling + for keyboard navigation support in the upcoming navigation branch)
}
ImGui : : EndCombo ( ) ;
}
// Simplified one-liner Combo() API, using values packed in a single constant string
2018-05-17 18:47:13 +03:00
static int item_current_2 = 0 ;
2018-03-20 06:00:57 +03:00
ImGui : : Combo ( " combo 2 (one-liner) " , & item_current_2 , " aaaa \0 bbbb \0 cccc \0 dddd \0 eeee \0 \0 " ) ;
// Simplified one-liner Combo() using an array of const char*
static int item_current_3 = - 1 ; // If the selection isn't within 0..count, Combo won't display a preview
ImGui : : Combo ( " combo 3 (array) " , & item_current_3 , items , IM_ARRAYSIZE ( items ) ) ;
// Simplified one-liner Combo() using an accessor function
struct FuncHolder { static bool ItemGetter ( void * data , int idx , const char * * out_str ) { * out_str = ( ( const char * * ) data ) [ idx ] ; return true ; } } ;
static int item_current_4 = 0 ;
ImGui : : Combo ( " combo 4 (function) " , & item_current_4 , & FuncHolder : : ItemGetter , items , IM_ARRAYSIZE ( items ) ) ;
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
if ( ImGui : : TreeNode ( " Selectables " ) )
{
2018-01-03 20:23:33 +03:00
// Selectable() has 2 overloads:
// - The one taking "bool selected" as a read-only selection information. When Selectable() has been clicked is returns true and you can alter selection state accordingly.
// - The one taking "bool* p_selected" as a read-write selection information (convenient in some cases)
// The earlier is more flexible, as in real application your selection may be stored in a different manner (in flags within objects, as an external list, etc).
2015-08-08 19:56:09 +03:00
if ( ImGui : : TreeNode ( " Basic " ) )
{
2018-01-03 20:23:33 +03:00
static bool selection [ 5 ] = { false , true , false , false , false } ;
ImGui : : Selectable ( " 1. I am selectable " , & selection [ 0 ] ) ;
ImGui : : Selectable ( " 2. I am selectable " , & selection [ 1 ] ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " 3. I am not selectable " ) ;
2018-01-03 20:23:33 +03:00
ImGui : : Selectable ( " 4. I am selectable " , & selection [ 3 ] ) ;
if ( ImGui : : Selectable ( " 5. I am double clickable " , selection [ 4 ] , ImGuiSelectableFlags_AllowDoubleClick ) )
2016-03-09 01:27:49 +03:00
if ( ImGui : : IsMouseDoubleClicked ( 0 ) )
2018-01-03 20:23:33 +03:00
selection [ 4 ] = ! selection [ 4 ] ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
2018-01-03 20:23:33 +03:00
if ( ImGui : : TreeNode ( " Selection State: Single Selection " ) )
2015-08-08 19:56:09 +03:00
{
2018-01-03 20:23:33 +03:00
static int selected = - 1 ;
for ( int n = 0 ; n < 5 ; n + + )
{
char buf [ 32 ] ;
sprintf ( buf , " Object %d " , n ) ;
2018-05-17 18:47:13 +03:00
if ( ImGui : : Selectable ( buf , selected = = n ) )
2018-01-03 20:23:33 +03:00
selected = n ;
}
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Selection State: Multiple Selection " ) )
{
ShowHelpMarker ( " Hold CTRL and click to select multiple items. " ) ;
static bool selection [ 5 ] = { false , false , false , false , false } ;
for ( int n = 0 ; n < 5 ; n + + )
{
char buf [ 32 ] ;
sprintf ( buf , " Object %d " , n ) ;
if ( ImGui : : Selectable ( buf , selection [ n ] ) )
{
if ( ! ImGui : : GetIO ( ) . KeyCtrl ) // Clear selection when CTRL is not held
2018-05-17 18:47:13 +03:00
memset ( selection , 0 , sizeof ( selection ) ) ;
2018-01-03 20:23:33 +03:00
selection [ n ] ^ = 1 ;
}
}
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Rendering more text into the same line " ) )
{
// Using the Selectable() override that takes "bool* p_selected" parameter and toggle your booleans automatically.
2015-08-08 19:56:09 +03:00
static bool selected [ 3 ] = { false , false , false } ;
2018-01-03 20:23:33 +03:00
ImGui : : Selectable ( " main.c " , & selected [ 0 ] ) ; ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " 2,345 bytes " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Selectable ( " Hello.cpp " , & selected [ 1 ] ) ; ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " 12,345 bytes " ) ;
2018-01-03 20:23:33 +03:00
ImGui : : Selectable ( " Hello.h " , & selected [ 2 ] ) ; ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " 2,345 bytes " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
2016-06-08 19:57:52 +03:00
if ( ImGui : : TreeNode ( " In columns " ) )
{
ImGui : : Columns ( 3 , NULL , false ) ;
static bool selected [ 16 ] = { 0 } ;
for ( int i = 0 ; i < 16 ; i + + )
{
char label [ 32 ] ; sprintf ( label , " Item %d " , i ) ;
if ( ImGui : : Selectable ( label , & selected [ i ] ) ) { }
ImGui : : NextColumn ( ) ;
}
ImGui : : Columns ( 1 ) ;
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
if ( ImGui : : TreeNode ( " Grid " ) )
{
static bool selected [ 16 ] = { true , false , false , false , false , true , false , false , false , false , true , false , false , false , false , true } ;
for ( int i = 0 ; i < 16 ; i + + )
{
ImGui : : PushID ( i ) ;
2016-04-26 07:11:13 +03:00
if ( ImGui : : Selectable ( " Sailor " , & selected [ i ] , 0 , ImVec2 ( 50 , 50 ) ) )
2015-08-08 19:56:09 +03:00
{
int x = i % 4 , y = i / 4 ;
if ( x > 0 ) selected [ i - 1 ] ^ = 1 ;
if ( x < 3 ) selected [ i + 1 ] ^ = 1 ;
if ( y > 0 ) selected [ i - 4 ] ^ = 1 ;
if ( y < 3 ) selected [ i + 4 ] ^ = 1 ;
}
if ( ( i % 4 ) < 3 ) ImGui : : SameLine ( ) ;
ImGui : : PopID ( ) ;
}
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Filtered Text Input " ) )
{
static char buf1 [ 64 ] = " " ; ImGui : : InputText ( " default " , buf1 , 64 ) ;
static char buf2 [ 64 ] = " " ; ImGui : : InputText ( " decimal " , buf2 , 64 , ImGuiInputTextFlags_CharsDecimal ) ;
static char buf3 [ 64 ] = " " ; ImGui : : InputText ( " hexadecimal " , buf3 , 64 , ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase ) ;
static char buf4 [ 64 ] = " " ; ImGui : : InputText ( " uppercase " , buf4 , 64 , ImGuiInputTextFlags_CharsUppercase ) ;
static char buf5 [ 64 ] = " " ; ImGui : : InputText ( " no blank " , buf5 , 64 , ImGuiInputTextFlags_CharsNoBlank ) ;
struct TextFilters { static int FilterImGuiLetters ( ImGuiTextEditCallbackData * data ) { if ( data - > EventChar < 256 & & strchr ( " imgui " , ( char ) data - > EventChar ) ) return 0 ; return 1 ; } } ;
static char buf6 [ 64 ] = " " ; ImGui : : InputText ( " \" imgui \" letters " , buf6 , 64 , ImGuiInputTextFlags_CallbackCharFilter , TextFilters : : FilterImGuiLetters ) ;
2015-11-22 06:54:18 +03:00
ImGui : : Text ( " Password input " ) ;
2016-03-26 20:44:17 +03:00
static char bufpass [ 64 ] = " password123 " ;
2016-02-05 06:46:15 +03:00
ImGui : : InputText ( " password " , bufpass , 64 , ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank ) ;
2015-11-22 06:54:18 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Display all characters as '*'. \n Disable clipboard cut and copy. \n Disable logging. \n " ) ;
2016-02-05 06:46:15 +03:00
ImGui : : InputText ( " password (clear) " , bufpass , 64 , ImGuiInputTextFlags_CharsNoBlank ) ;
2015-11-22 06:54:18 +03:00
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Multi-line Text Input " ) )
{
2015-09-12 08:40:55 +03:00
static bool read_only = false ;
2016-03-26 20:44:17 +03:00
static char text [ 1024 * 16 ] =
2015-10-20 04:12:08 +03:00
" /* \n "
" The Pentium F00F bug, shorthand for F0 0F C7 C8, \n "
" the hexadecimal encoding of one offending instruction, \n "
" more formally, the invalid operand with locked CMPXCHG8B \n "
" instruction bug, is a design flaw in the majority of \n "
" Intel Pentium, Pentium MMX, and Pentium OverDrive \n "
" processors (all in the P5 microarchitecture). \n "
" */ \n \n "
" label: \n "
" \t lock cmpxchg8b eax \n " ;
2015-09-12 08:40:55 +03:00
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 0 , 0 ) ) ;
ImGui : : Checkbox ( " Read-only " , & read_only ) ;
ImGui : : PopStyleVar ( ) ;
ImGui : : InputTextMultiline ( " ##source " , text , IM_ARRAYSIZE ( text ) , ImVec2 ( - 1.0f , ImGui : : GetTextLineHeight ( ) * 16 ) , ImGuiInputTextFlags_AllowTabInput | ( read_only ? ImGuiInputTextFlags_ReadOnly : 0 ) ) ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
2018-05-13 18:58:15 +03:00
if ( ImGui : : TreeNode ( " Plots Widgets " ) )
2015-08-08 19:56:09 +03:00
{
2017-08-08 19:11:10 +03:00
static bool animate = true ;
ImGui : : Checkbox ( " Animate " , & animate ) ;
2015-08-08 19:56:09 +03:00
static float arr [ ] = { 0.6f , 0.1f , 1.0f , 0.5f , 0.92f , 0.1f , 0.2f } ;
2017-08-08 19:11:10 +03:00
ImGui : : PlotLines ( " Frame Times " , arr , IM_ARRAYSIZE ( arr ) ) ;
// Create a dummy array of contiguous float values to plot
// 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.
static float values [ 90 ] = { 0 } ;
static int values_offset = 0 ;
2018-07-23 17:27:28 +03:00
static double refresh_time = 0.0 ;
2017-08-08 19:11:10 +03:00
if ( ! animate | | refresh_time = = 0.0f )
refresh_time = ImGui : : GetTime ( ) ;
while ( refresh_time < ImGui : : GetTime ( ) ) // Create dummy data at fixed 60 hz rate for the demo
{
static float phase = 0.0f ;
values [ values_offset ] = cosf ( phase ) ;
values_offset = ( values_offset + 1 ) % IM_ARRAYSIZE ( values ) ;
phase + = 0.10f * values_offset ;
refresh_time + = 1.0f / 60.0f ;
}
ImGui : : PlotLines ( " Lines " , values , IM_ARRAYSIZE ( values ) , values_offset , " avg 0.0 " , - 1.0f , 1.0f , ImVec2 ( 0 , 80 ) ) ;
ImGui : : PlotHistogram ( " Histogram " , arr , IM_ARRAYSIZE ( arr ) , 0 , NULL , 0.0f , 1.0f , ImVec2 ( 0 , 80 ) ) ;
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
// Use functions to generate output
// 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.
struct Funcs
{
static float Sin ( void * , int i ) { return sinf ( i * 0.1f ) ; }
static float Saw ( void * , int i ) { return ( i & 1 ) ? 1.0f : - 1.0f ; }
} ;
static int func_type = 0 , display_count = 70 ;
ImGui : : Separator ( ) ;
ImGui : : PushItemWidth ( 100 ) ; ImGui : : Combo ( " func " , & func_type , " Sin \0 Saw \0 " ) ; ImGui : : PopItemWidth ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : SliderInt ( " Sample count " , & display_count , 1 , 400 ) ;
float ( * func ) ( void * , int ) = ( func_type = = 0 ) ? Funcs : : Sin : Funcs : : Saw ;
ImGui : : PlotLines ( " Lines " , func , NULL , display_count , 0 , NULL , - 1.0f , 1.0f , ImVec2 ( 0 , 80 ) ) ;
ImGui : : PlotHistogram ( " Histogram " , func , NULL , display_count , 0 , NULL , - 1.0f , 1.0f , ImVec2 ( 0 , 80 ) ) ;
ImGui : : Separator ( ) ;
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
// Animate a simple progress bar
static float progress = 0.0f , progress_dir = 1.0f ;
if ( animate )
{
progress + = progress_dir * 0.4f * ImGui : : GetIO ( ) . DeltaTime ;
if ( progress > = + 1.1f ) { progress = + 1.1f ; progress_dir * = - 1.0f ; }
if ( progress < = - 0.1f ) { progress = - 0.1f ; progress_dir * = - 1.0f ; }
}
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
// 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.
ImGui : : ProgressBar ( progress , ImVec2 ( 0.0f , 0.0f ) ) ;
ImGui : : SameLine ( 0.0f , ImGui : : GetStyle ( ) . ItemInnerSpacing . x ) ;
ImGui : : Text ( " Progress Bar " ) ;
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
float progress_saturated = ( progress < 0.0f ) ? 0.0f : ( progress > 1.0f ) ? 1.0f : progress ;
char buf [ 32 ] ;
sprintf ( buf , " %d/%d " , ( int ) ( progress_saturated * 1753 ) , 1753 ) ;
ImGui : : ProgressBar ( progress , ImVec2 ( 0.f , 0.f ) , buf ) ;
ImGui : : TreePop ( ) ;
2015-08-08 19:56:09 +03:00
}
2017-08-08 19:11:10 +03:00
if ( ImGui : : TreeNode ( " Color/Picker Widgets " ) )
2015-08-08 19:56:09 +03:00
{
2017-08-08 19:11:10 +03:00
static ImVec4 color = ImColor ( 114 , 144 , 154 , 200 ) ;
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
static bool alpha_preview = true ;
static bool alpha_half_preview = false ;
2018-05-21 18:15:16 +03:00
static bool drag_and_drop = true ;
2017-08-08 19:11:10 +03:00
static bool options_menu = true ;
2018-01-03 20:23:33 +03:00
static bool hdr = false ;
2017-08-08 19:11:10 +03:00
ImGui : : Checkbox ( " With Alpha Preview " , & alpha_preview ) ;
ImGui : : Checkbox ( " With Half Alpha Preview " , & alpha_half_preview ) ;
2018-05-21 18:15:16 +03:00
ImGui : : Checkbox ( " With Drag and Drop " , & drag_and_drop ) ;
2017-08-08 19:11:10 +03:00
ImGui : : Checkbox ( " With Options Menu " , & options_menu ) ; ImGui : : SameLine ( ) ; ShowHelpMarker ( " Right-click on the individual color widget to show options. " ) ;
2018-01-03 20:23:33 +03:00
ImGui : : Checkbox ( " With HDR " , & hdr ) ; ImGui : : SameLine ( ) ; ShowHelpMarker ( " Currently all this does is to lift the 0..1 limits on dragging widgets. " ) ;
2018-05-21 18:15:16 +03:00
int misc_flags = ( hdr ? ImGuiColorEditFlags_HDR : 0 ) | ( drag_and_drop ? 0 : ImGuiColorEditFlags_NoDragDrop ) | ( alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : ( alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0 ) ) | ( options_menu ? 0 : ImGuiColorEditFlags_NoOptions ) ;
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Color widget: " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Click on the colored square to open a color picker. \n CTRL+click on individual component to input value. \n " ) ;
ImGui : : ColorEdit3 ( " MyColor##1 " , ( float * ) & color , misc_flags ) ;
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Color widget HSV with Alpha: " ) ;
ImGui : : ColorEdit4 ( " MyColor##2 " , ( float * ) & color , ImGuiColorEditFlags_HSV | misc_flags ) ;
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Color widget with Float Display: " ) ;
ImGui : : ColorEdit4 ( " MyColor##2f " , ( float * ) & color , ImGuiColorEditFlags_Float | misc_flags ) ;
2015-08-26 06:44:36 +03:00
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Color button with Picker: " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " With the ImGuiColorEditFlags_NoInputs flag you can hide all the slider/text inputs. \n With the ImGuiColorEditFlags_NoLabel flag you can pass a non-empty label which will only be used for the tooltip and picker popup. " ) ;
ImGui : : ColorEdit4 ( " MyColor##3 " , ( float * ) & color , ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | misc_flags ) ;
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Color button with Custom Picker Popup: " ) ;
2017-12-14 06:13:37 +03:00
// Generate a dummy palette
2017-08-08 19:11:10 +03:00
static bool saved_palette_inited = false ;
static ImVec4 saved_palette [ 32 ] ;
if ( ! saved_palette_inited )
for ( int n = 0 ; n < IM_ARRAYSIZE ( saved_palette ) ; n + + )
2017-12-14 06:13:37 +03:00
{
2017-08-08 19:11:10 +03:00
ImGui : : ColorConvertHSVtoRGB ( n / 31.0f , 0.8f , 0.8f , saved_palette [ n ] . x , saved_palette [ n ] . y , saved_palette [ n ] . z ) ;
2017-12-14 06:13:37 +03:00
saved_palette [ n ] . w = 1.0f ; // Alpha
}
saved_palette_inited = true ;
static ImVec4 backup_color ;
2017-08-08 19:11:10 +03:00
bool open_popup = ImGui : : ColorButton ( " MyColor##3b " , color , misc_flags ) ;
ImGui : : SameLine ( ) ;
open_popup | = ImGui : : Button ( " Palette " ) ;
if ( open_popup )
{
ImGui : : OpenPopup ( " mypicker " ) ;
backup_color = color ;
}
if ( ImGui : : BeginPopup ( " mypicker " ) )
{
// FIXME: Adding a drag and drop example here would be perfect!
ImGui : : Text ( " MY CUSTOM COLOR PICKER WITH AN AMAZING PALETTE! " ) ;
ImGui : : Separator ( ) ;
ImGui : : ColorPicker4 ( " ##picker " , ( float * ) & color , misc_flags | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoSmallPreview ) ;
ImGui : : SameLine ( ) ;
ImGui : : BeginGroup ( ) ;
ImGui : : Text ( " Current " ) ;
ImGui : : ColorButton ( " ##current " , color , ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf , ImVec2 ( 60 , 40 ) ) ;
ImGui : : Text ( " Previous " ) ;
if ( ImGui : : ColorButton ( " ##previous " , backup_color , ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf , ImVec2 ( 60 , 40 ) ) )
color = backup_color ;
ImGui : : Separator ( ) ;
ImGui : : Text ( " Palette " ) ;
for ( int n = 0 ; n < IM_ARRAYSIZE ( saved_palette ) ; n + + )
{
ImGui : : PushID ( n ) ;
if ( ( n % 8 ) ! = 0 )
ImGui : : SameLine ( 0.0f , ImGui : : GetStyle ( ) . ItemSpacing . y ) ;
2017-12-14 06:13:37 +03:00
if ( ImGui : : ColorButton ( " ##palette " , saved_palette [ n ] , ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoTooltip , ImVec2 ( 20 , 20 ) ) )
2017-08-08 19:11:10 +03:00
color = ImVec4 ( saved_palette [ n ] . x , saved_palette [ n ] . y , saved_palette [ n ] . z , color . w ) ; // Preserve alpha!
2017-12-14 06:13:37 +03:00
if ( ImGui : : BeginDragDropTarget ( ) )
{
if ( const ImGuiPayload * payload = AcceptDragDropPayload ( IMGUI_PAYLOAD_TYPE_COLOR_3F ) )
memcpy ( ( float * ) & saved_palette [ n ] , payload - > Data , sizeof ( float ) * 3 ) ;
if ( const ImGuiPayload * payload = AcceptDragDropPayload ( IMGUI_PAYLOAD_TYPE_COLOR_4F ) )
memcpy ( ( float * ) & saved_palette [ n ] , payload - > Data , sizeof ( float ) * 4 ) ;
EndDragDropTarget ( ) ;
}
2017-08-08 19:11:10 +03:00
ImGui : : PopID ( ) ;
}
ImGui : : EndGroup ( ) ;
ImGui : : EndPopup ( ) ;
}
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Color button only: " ) ;
2017-09-29 07:51:20 +03:00
ImGui : : ColorButton ( " MyColor##3c " , * ( ImVec4 * ) & color , misc_flags , ImVec2 ( 80 , 80 ) ) ;
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Color picker: " ) ;
static bool alpha = true ;
static bool alpha_bar = true ;
static bool side_preview = true ;
static bool ref_color = false ;
static ImVec4 ref_color_v ( 1.0f , 0.0f , 1.0f , 0.5f ) ;
static int inputs_mode = 2 ;
static int picker_mode = 0 ;
ImGui : : Checkbox ( " With Alpha " , & alpha ) ;
ImGui : : Checkbox ( " With Alpha Bar " , & alpha_bar ) ;
ImGui : : Checkbox ( " With Side Preview " , & side_preview ) ;
if ( side_preview )
{
ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " With Ref Color " , & ref_color ) ;
if ( ref_color )
{
ImGui : : SameLine ( ) ;
ImGui : : ColorEdit4 ( " ##RefColor " , & ref_color_v . x , ImGuiColorEditFlags_NoInputs | misc_flags ) ;
}
}
ImGui : : Combo ( " Inputs Mode " , & inputs_mode , " All Inputs \0 No Inputs \0 RGB Input \0 HSV Input \0 HEX Input \0 " ) ;
ImGui : : Combo ( " Picker Mode " , & picker_mode , " Auto/Current \0 Hue bar + SV rect \0 Hue wheel + SV triangle \0 " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " User can right-click the picker to change mode. " ) ;
ImGuiColorEditFlags flags = misc_flags ;
if ( ! alpha ) flags | = ImGuiColorEditFlags_NoAlpha ; // This is by default if you call ColorPicker3() instead of ColorPicker4()
if ( alpha_bar ) flags | = ImGuiColorEditFlags_AlphaBar ;
if ( ! side_preview ) flags | = ImGuiColorEditFlags_NoSidePreview ;
if ( picker_mode = = 1 ) flags | = ImGuiColorEditFlags_PickerHueBar ;
if ( picker_mode = = 2 ) flags | = ImGuiColorEditFlags_PickerHueWheel ;
if ( inputs_mode = = 1 ) flags | = ImGuiColorEditFlags_NoInputs ;
if ( inputs_mode = = 2 ) flags | = ImGuiColorEditFlags_RGB ;
if ( inputs_mode = = 3 ) flags | = ImGuiColorEditFlags_HSV ;
if ( inputs_mode = = 4 ) flags | = ImGuiColorEditFlags_HEX ;
ImGui : : ColorPicker4 ( " MyColor##4 " , ( float * ) & color , flags , ref_color ? & ref_color_v . x : NULL ) ;
2018-05-14 18:14:39 +03:00
ImGui : : Text ( " Programmatically set defaults: " ) ;
2017-08-08 19:11:10 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " SetColorEditOptions() is designed to allow you to set boot-time default. \n We don't have Push/Pop functions because you can force options on a per-widget basis if needed, and the user can change non-forced ones with the options menu. \n We don't have a getter to avoid encouraging you to persistently save values that aren't forward-compatible. " ) ;
2018-05-14 18:14:39 +03:00
if ( ImGui : : Button ( " Default: Uint8 + HSV + Hue Bar " ) )
ImGui : : SetColorEditOptions ( ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_HSV | ImGuiColorEditFlags_PickerHueBar ) ;
if ( ImGui : : Button ( " Default: Float + HDR + Hue Wheel " ) )
ImGui : : SetColorEditOptions ( ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_PickerHueWheel ) ;
2017-08-08 19:11:10 +03:00
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
if ( ImGui : : TreeNode ( " Range Widgets " ) )
{
static float begin = 10 , end = 90 ;
static int begin_i = 100 , end_i = 1000 ;
ImGui : : DragFloatRange2 ( " range " , & begin , & end , 0.25f , 0.0f , 100.0f , " Min: %.1f %% " , " Max: %.1f %% " ) ;
2018-05-11 18:26:25 +03:00
ImGui : : DragIntRange2 ( " range int (no bounds) " , & begin_i , & end_i , 5 , 0 , 0 , " Min: %d units " , " Max: %d units " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
2018-05-13 18:58:15 +03:00
if ( ImGui : : TreeNode ( " Data Types " ) )
{
// The DragScalar, InputScalar, SliderScalar functions allow manipulating most common data types: signed/unsigned int/long long and float/double
// To avoid polluting the public API with all possible combinations, we use the ImGuiDataType enum to pass the type, and argument-by-values are turned into argument-by-address.
// This is the reason the test code below creates local variables to hold "zero" "one" etc. for each types.
2018-05-17 18:47:13 +03:00
// In practice, if you frequently use a given type that is not covered by the normal API entry points, you may want to wrap it yourself inside a 1 line function
2018-05-13 18:58:15 +03:00
// which can take typed values argument instead of void*, and then pass their address to the generic function. For example:
2018-05-14 18:14:39 +03:00
// bool SliderU64(const char *label, u64* value, u64 min = 0, u64 max = 0, const char* format = "%lld") { return SliderScalar(label, ImGuiDataType_U64, value, &min, &max, format); }
2018-05-13 18:58:15 +03:00
// Below are helper variables we can take the address of to work-around this:
2018-05-17 18:47:13 +03:00
// Note that the SliderScalar function has a maximum usable range of half the natural type maximum, hence the /2 below.
2018-05-13 18:58:15 +03:00
const ImS32 s32_zero = 0 , s32_one = 1 , s32_fifty = 50 , s32_min = INT_MIN / 2 , s32_max = INT_MAX / 2 , s32_hi_a = INT_MAX / 2 - 100 , s32_hi_b = INT_MAX / 2 ;
const ImU32 u32_zero = 0 , u32_one = 1 , u32_fifty = 50 , u32_min = 0 , u32_max = UINT_MAX / 2 , u32_hi_a = UINT_MAX / 2 - 100 , u32_hi_b = UINT_MAX / 2 ;
const ImS64 s64_zero = 0 , s64_one = 1 , s64_fifty = 50 , s64_min = LLONG_MIN / 2 , s64_max = LLONG_MAX / 2 , s64_hi_a = LLONG_MAX / 2 - 100 , s64_hi_b = LLONG_MAX / 2 ;
const ImU64 u64_zero = 0 , u64_one = 1 , u64_fifty = 50 , u64_min = 0 , u64_max = ULLONG_MAX / 2 , u64_hi_a = ULLONG_MAX / 2 - 100 , u64_hi_b = ULLONG_MAX / 2 ;
const float f32_zero = 0.f , f32_one = 1.f , f32_lo_a = - 10000000000.0f , f32_hi_a = + 10000000000.0f ;
const double f64_zero = 0. , f64_one = 1. , f64_lo_a = - 1000000000000000 , f64_hi_a = + 1000000000000000 ;
// State
static ImS32 s32_v = - 1 ;
static ImU32 u32_v = ( ImU32 ) - 1 ;
static ImS64 s64_v = - 1 ;
static ImU64 u64_v = ( ImU64 ) - 1 ;
static float f32_v = 0.123f ;
static double f64_v = 90000.01234567890123456789 ;
const float drag_speed = 0.2f ;
static bool drag_clamp = false ;
ImGui : : Text ( " Drags: " ) ;
ImGui : : Checkbox ( " Clamp integers to 0..50 " , & drag_clamp ) ; ImGui : : SameLine ( ) ; ShowHelpMarker ( " As with every widgets in dear imgui, we never modify values unless there is a user interaction. \n You can override the clamping limits by using CTRL+Click to input a value. " ) ;
ImGui : : DragScalar ( " drag s32 " , ImGuiDataType_S32 , & s32_v , drag_speed , drag_clamp ? & s32_zero : NULL , drag_clamp ? & s32_fifty : NULL ) ;
ImGui : : DragScalar ( " drag u32 " , ImGuiDataType_U32 , & u32_v , drag_speed , drag_clamp ? & u32_zero : NULL , drag_clamp ? & u32_fifty : NULL , " %u ms " ) ;
ImGui : : DragScalar ( " drag s64 " , ImGuiDataType_S64 , & s64_v , drag_speed , drag_clamp ? & s64_zero : NULL , drag_clamp ? & s64_fifty : NULL ) ;
ImGui : : DragScalar ( " drag u64 " , ImGuiDataType_U64 , & u64_v , drag_speed , drag_clamp ? & u64_zero : NULL , drag_clamp ? & u64_fifty : NULL ) ;
ImGui : : DragScalar ( " drag float " , ImGuiDataType_Float , & f32_v , 0.005f , & f32_zero , & f32_one , " %f " , 1.0f ) ;
ImGui : : DragScalar ( " drag float ^2 " , ImGuiDataType_Float , & f32_v , 0.005f , & f32_zero , & f32_one , " %f " , 2.0f ) ; ImGui : : SameLine ( ) ; ShowHelpMarker ( " You can use the 'power' parameter to increase tweaking precision on one side of the range. " ) ;
ImGui : : DragScalar ( " drag double " , ImGuiDataType_Double , & f64_v , 0.0005f , & f64_zero , NULL , " %.10f grams " , 1.0f ) ;
ImGui : : DragScalar ( " drag double ^2 " , ImGuiDataType_Double , & f64_v , 0.0005f , & f64_zero , & f64_one , " 0 < %.10f < 1 " , 2.0f ) ;
ImGui : : Text ( " Sliders " ) ;
ImGui : : SliderScalar ( " slider s32 low " , ImGuiDataType_S32 , & s32_v , & s32_zero , & s32_fifty , " %d " ) ;
ImGui : : SliderScalar ( " slider s32 high " , ImGuiDataType_S32 , & s32_v , & s32_hi_a , & s32_hi_b , " %d " ) ;
ImGui : : SliderScalar ( " slider s32 full " , ImGuiDataType_S32 , & s32_v , & s32_min , & s32_max , " %d " ) ;
ImGui : : SliderScalar ( " slider u32 low " , ImGuiDataType_U32 , & u32_v , & u32_zero , & u32_fifty , " %u " ) ;
ImGui : : SliderScalar ( " slider u32 high " , ImGuiDataType_U32 , & u32_v , & u32_hi_a , & u32_hi_b , " %u " ) ;
ImGui : : SliderScalar ( " slider u32 full " , ImGuiDataType_U32 , & u32_v , & u32_min , & u32_max , " %u " ) ;
ImGui : : SliderScalar ( " slider s64 low " , ImGuiDataType_S64 , & s64_v , & s64_zero , & s64_fifty , " %I64d " ) ;
ImGui : : SliderScalar ( " slider s64 high " , ImGuiDataType_S64 , & s64_v , & s64_hi_a , & s64_hi_b , " %I64d " ) ;
ImGui : : SliderScalar ( " slider s64 full " , ImGuiDataType_S64 , & s64_v , & s64_min , & s64_max , " %I64d " ) ;
ImGui : : SliderScalar ( " slider u64 low " , ImGuiDataType_U64 , & u64_v , & u64_zero , & u64_fifty , " %I64u ms " ) ;
ImGui : : SliderScalar ( " slider u64 high " , ImGuiDataType_U64 , & u64_v , & u64_hi_a , & u64_hi_b , " %I64u ms " ) ;
ImGui : : SliderScalar ( " slider u64 full " , ImGuiDataType_U64 , & u64_v , & u64_min , & u64_max , " %I64u ms " ) ;
ImGui : : SliderScalar ( " slider float low " , ImGuiDataType_Float , & f32_v , & f32_zero , & f32_one ) ;
ImGui : : SliderScalar ( " slider float low^2 " , ImGuiDataType_Float , & f32_v , & f32_zero , & f32_one , " %.10f " , 2.0f ) ;
ImGui : : SliderScalar ( " slider float high " , ImGuiDataType_Float , & f32_v , & f32_lo_a , & f32_hi_a , " %e " ) ;
ImGui : : SliderScalar ( " slider double low " , ImGuiDataType_Double , & f64_v , & f64_zero , & f64_one , " %.10f grams " , 1.0f ) ;
ImGui : : SliderScalar ( " slider double low^2 " , ImGuiDataType_Double , & f64_v , & f64_zero , & f64_one , " %.10f " , 2.0f ) ;
ImGui : : SliderScalar ( " slider double high " , ImGuiDataType_Double , & f64_v , & f64_lo_a , & f64_hi_a , " %e grams " , 1.0f ) ;
static bool inputs_step = true ;
ImGui : : Text ( " Inputs " ) ;
ImGui : : Checkbox ( " Show step buttons " , & inputs_step ) ;
ImGui : : InputScalar ( " input s32 " , ImGuiDataType_S32 , & s32_v , inputs_step ? & s32_one : NULL , NULL , " %d " ) ;
ImGui : : InputScalar ( " input s32 hex " , ImGuiDataType_S32 , & s32_v , inputs_step ? & s32_one : NULL , NULL , " %08X " , ImGuiInputTextFlags_CharsHexadecimal ) ;
ImGui : : InputScalar ( " input u32 " , ImGuiDataType_U32 , & u32_v , inputs_step ? & u32_one : NULL , NULL , " %u " ) ;
ImGui : : InputScalar ( " input u32 hex " , ImGuiDataType_U32 , & u32_v , inputs_step ? & u32_one : NULL , NULL , " %08X " , ImGuiInputTextFlags_CharsHexadecimal ) ;
ImGui : : InputScalar ( " input s64 " , ImGuiDataType_S64 , & s64_v , inputs_step ? & s64_one : NULL ) ;
ImGui : : InputScalar ( " input u64 " , ImGuiDataType_U64 , & u64_v , inputs_step ? & u64_one : NULL ) ;
ImGui : : InputScalar ( " input float " , ImGuiDataType_Float , & f32_v , inputs_step ? & f32_one : NULL ) ;
ImGui : : InputScalar ( " input double " , ImGuiDataType_Double , & f64_v , inputs_step ? & f64_one : NULL ) ;
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
if ( ImGui : : TreeNode ( " Multi-component Widgets " ) )
{
static float vec4f [ 4 ] = { 0.10f , 0.20f , 0.30f , 0.44f } ;
static int vec4i [ 4 ] = { 1 , 5 , 100 , 255 } ;
ImGui : : InputFloat2 ( " input float2 " , vec4f ) ;
ImGui : : DragFloat2 ( " drag float2 " , vec4f , 0.01f , 0.0f , 1.0f ) ;
ImGui : : SliderFloat2 ( " slider float2 " , vec4f , 0.0f , 1.0f ) ;
ImGui : : InputInt2 ( " input int2 " , vec4i ) ;
2018-05-11 18:26:25 +03:00
ImGui : : DragInt2 ( " drag int2 " , vec4i , 1 , 0 , 255 ) ;
2015-08-08 19:56:09 +03:00
ImGui : : SliderInt2 ( " slider int2 " , vec4i , 0 , 255 ) ;
ImGui : : Spacing ( ) ;
ImGui : : InputFloat3 ( " input float3 " , vec4f ) ;
ImGui : : DragFloat3 ( " drag float3 " , vec4f , 0.01f , 0.0f , 1.0f ) ;
ImGui : : SliderFloat3 ( " slider float3 " , vec4f , 0.0f , 1.0f ) ;
ImGui : : InputInt3 ( " input int3 " , vec4i ) ;
2018-05-11 18:26:25 +03:00
ImGui : : DragInt3 ( " drag int3 " , vec4i , 1 , 0 , 255 ) ;
2015-08-08 19:56:09 +03:00
ImGui : : SliderInt3 ( " slider int3 " , vec4i , 0 , 255 ) ;
ImGui : : Spacing ( ) ;
ImGui : : InputFloat4 ( " input float4 " , vec4f ) ;
ImGui : : DragFloat4 ( " drag float4 " , vec4f , 0.01f , 0.0f , 1.0f ) ;
ImGui : : SliderFloat4 ( " slider float4 " , vec4f , 0.0f , 1.0f ) ;
ImGui : : InputInt4 ( " input int4 " , vec4i ) ;
ImGui : : DragInt4 ( " drag int4 " , vec4i , 1 , 0 , 255 ) ;
ImGui : : SliderInt4 ( " slider int4 " , vec4i , 0 , 255 ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Vertical Sliders " ) )
{
const float spacing = 4 ;
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( spacing , spacing ) ) ;
static int int_value = 0 ;
ImGui : : VSliderInt ( " ##int " , ImVec2 ( 18 , 160 ) , & int_value , 0 , 5 ) ;
ImGui : : SameLine ( ) ;
static float values [ 7 ] = { 0.0f , 0.60f , 0.35f , 0.9f , 0.70f , 0.20f , 0.0f } ;
ImGui : : PushID ( " set1 " ) ;
for ( int i = 0 ; i < 7 ; i + + )
{
if ( i > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushID ( i ) ;
2017-08-20 20:25:00 +03:00
ImGui : : PushStyleColor ( ImGuiCol_FrameBg , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.5f , 0.5f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_FrameBgHovered , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.6f , 0.5f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_FrameBgActive , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.7f , 0.5f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_SliderGrab , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.9f , 0.9f ) ) ;
2015-08-08 19:56:09 +03:00
ImGui : : VSliderFloat ( " ##v " , ImVec2 ( 18 , 160 ) , & values [ i ] , 0.0f , 1.0f , " " ) ;
if ( ImGui : : IsItemActive ( ) | | ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( " %.3f " , values [ i ] ) ;
ImGui : : PopStyleColor ( 4 ) ;
ImGui : : PopID ( ) ;
}
ImGui : : PopID ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : PushID ( " set2 " ) ;
static float values2 [ 4 ] = { 0.20f , 0.80f , 0.40f , 0.25f } ;
const int rows = 3 ;
const ImVec2 small_slider_size ( 18 , ( 160.0f - ( rows - 1 ) * spacing ) / rows ) ;
for ( int nx = 0 ; nx < 4 ; nx + + )
{
if ( nx > 0 ) ImGui : : SameLine ( ) ;
ImGui : : BeginGroup ( ) ;
for ( int ny = 0 ; ny < rows ; ny + + )
{
ImGui : : PushID ( nx * rows + ny ) ;
ImGui : : VSliderFloat ( " ##v " , small_slider_size , & values2 [ nx ] , 0.0f , 1.0f , " " ) ;
if ( ImGui : : IsItemActive ( ) | | ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( " %.3f " , values2 [ nx ] ) ;
ImGui : : PopID ( ) ;
}
ImGui : : EndGroup ( ) ;
}
ImGui : : PopID ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : PushID ( " set3 " ) ;
for ( int i = 0 ; i < 4 ; i + + )
{
if ( i > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushID ( i ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_GrabMinSize , 40 ) ;
2016-05-21 19:27:18 +03:00
ImGui : : VSliderFloat ( " ##v " , ImVec2 ( 40 , 160 ) , & values [ i ] , 0.0f , 1.0f , " %.2f \n sec " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PopStyleVar ( ) ;
ImGui : : PopID ( ) ;
}
ImGui : : PopID ( ) ;
ImGui : : PopStyleVar ( ) ;
ImGui : : TreePop ( ) ;
}
2018-06-12 20:59:28 +03:00
2018-07-09 17:38:59 +03:00
if ( ImGui : : TreeNode ( " Drag and Drop " ) )
{
{
// ColorEdit widgets automatically act as drag source and drag target.
// They are using standardized payload strings IMGUI_PAYLOAD_TYPE_COLOR_3F and IMGUI_PAYLOAD_TYPE_COLOR_4F to allow your own widgets
// to use colors in their drag and drop interaction. Also see the demo in Color Picker -> Palette demo.
ImGui : : BulletText ( " Drag and drop in standard widgets " ) ;
ImGui : : Indent ( ) ;
static float col1 [ 3 ] = { 1.0f , 0.0f , 0.2f } ;
static float col2 [ 4 ] = { 0.4f , 0.7f , 0.0f , 0.5f } ;
ImGui : : ColorEdit3 ( " color 1 " , col1 ) ;
ImGui : : ColorEdit4 ( " color 2 " , col2 ) ;
ImGui : : Unindent ( ) ;
}
{
ImGui : : BulletText ( " Drag and drop to copy/swap items " ) ;
ImGui : : Indent ( ) ;
enum Mode
{
Mode_Copy ,
Mode_Move ,
Mode_Swap
} ;
static int mode = 0 ;
if ( ImGui : : RadioButton ( " Copy " , mode = = Mode_Copy ) ) { mode = Mode_Copy ; } ImGui : : SameLine ( ) ;
if ( ImGui : : RadioButton ( " Move " , mode = = Mode_Move ) ) { mode = Mode_Move ; } ImGui : : SameLine ( ) ;
if ( ImGui : : RadioButton ( " Swap " , mode = = Mode_Swap ) ) { mode = Mode_Swap ; }
static const char * names [ 9 ] = { " Bobby " , " Beatrice " , " Betty " , " Brianna " , " Barry " , " Bernard " , " Bibi " , " Blaine " , " Bryn " } ;
for ( int n = 0 ; n < IM_ARRAYSIZE ( names ) ; n + + )
{
ImGui : : PushID ( n ) ;
if ( ( n % 3 ) ! = 0 )
ImGui : : SameLine ( ) ;
ImGui : : Button ( names [ n ] , ImVec2 ( 60 , 60 ) ) ;
// Our buttons are both drag sources and drag targets here!
if ( ImGui : : BeginDragDropSource ( ImGuiDragDropFlags_None ) )
{
ImGui : : SetDragDropPayload ( " DND_DEMO_CELL " , & n , sizeof ( int ) ) ; // Set payload to carry the index of our item (could be anything)
if ( mode = = Mode_Copy ) { ImGui : : Text ( " Copy %s " , names [ n ] ) ; } // Display preview (could be anything, e.g. when dragging an image we could decide to display the filename and a small preview of the image, etc.)
if ( mode = = Mode_Move ) { ImGui : : Text ( " Move %s " , names [ n ] ) ; }
if ( mode = = Mode_Swap ) { ImGui : : Text ( " Swap %s " , names [ n ] ) ; }
ImGui : : EndDragDropSource ( ) ;
}
if ( ImGui : : BeginDragDropTarget ( ) )
{
if ( const ImGuiPayload * payload = ImGui : : AcceptDragDropPayload ( " DND_DEMO_CELL " ) )
{
IM_ASSERT ( payload - > DataSize = = sizeof ( int ) ) ;
int payload_n = * ( const int * ) payload - > Data ;
if ( mode = = Mode_Copy )
{
names [ n ] = names [ payload_n ] ;
}
if ( mode = = Mode_Move )
{
names [ n ] = names [ payload_n ] ;
names [ payload_n ] = " " ;
}
if ( mode = = Mode_Swap )
{
const char * tmp = names [ n ] ;
names [ n ] = names [ payload_n ] ;
names [ payload_n ] = tmp ;
}
}
ImGui : : EndDragDropTarget ( ) ;
}
ImGui : : PopID ( ) ;
}
ImGui : : Unindent ( ) ;
}
ImGui : : TreePop ( ) ;
}
2018-06-12 20:59:28 +03:00
if ( ImGui : : TreeNode ( " Active, Focused, Hovered & Focused Tests " ) )
{
2018-06-13 19:09:27 +03:00
// Display the value of IsItemHovered() and other common item state functions. Note that the flags can be combined.
2018-06-12 20:59:28 +03:00
// (because BulletText is an item itself and that would affect the output of IsItemHovered() we pass all state in a single call to simplify the code).
static int item_type = 1 ;
2018-06-13 19:09:27 +03:00
static bool b = false ;
2018-06-12 20:59:28 +03:00
static float col4f [ 4 ] = { 1.0f , 0.5 , 0.0f , 1.0f } ;
ImGui : : RadioButton ( " Text " , & item_type , 0 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " Button " , & item_type , 1 ) ; ImGui : : SameLine ( ) ;
2018-06-13 19:09:27 +03:00
ImGui : : RadioButton ( " CheckBox " , & item_type , 2 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " SliderFloat " , & item_type , 3 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " ColorEdit4 " , & item_type , 4 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " ListBox " , & item_type , 5 ) ;
bool ret = false ;
if ( item_type = = 0 ) { ImGui : : Text ( " ITEM: Text " ) ; } // Testing text items with no identifier/interaction
if ( item_type = = 1 ) { ret = ImGui : : Button ( " ITEM: Button " ) ; } // Testing button
if ( item_type = = 2 ) { ret = ImGui : : Checkbox ( " ITEM: CheckBox " , & b ) ; } // Testing checkbox
if ( item_type = = 3 ) { ret = ImGui : : SliderFloat ( " ITEM: SliderFloat " , & col4f [ 0 ] , 0.0f , 1.0f ) ; } // Testing basic item
if ( item_type = = 4 ) { ret = ImGui : : ColorEdit4 ( " ITEM: ColorEdit4 " , col4f ) ; } // Testing multi-component items (IsItemXXX flags are reported merged)
if ( item_type = = 5 ) { const char * items [ ] = { " Apple " , " Banana " , " Cherry " , " Kiwi " } ; static int current = 1 ; ret = ImGui : : ListBox ( " ITEM: ListBox " , & current , items , IM_ARRAYSIZE ( items ) , IM_ARRAYSIZE ( items ) ) ; }
2018-06-12 20:59:28 +03:00
ImGui : : BulletText (
" Return value = %d \n "
" IsItemFocused() = %d \n "
" IsItemHovered() = %d \n "
" IsItemHovered(_AllowWhenBlockedByPopup) = %d \n "
" IsItemHovered(_AllowWhenBlockedByActiveItem) = %d \n "
" IsItemHovered(_AllowWhenOverlapped) = %d \n "
" IsItemHovered(_RectOnly) = %d \n "
" IsItemActive() = %d \n "
" IsItemDeactivated() = %d \n "
2018-06-13 19:09:27 +03:00
" IsItemDeactivatedAfterChange() = %d \n "
2018-06-12 20:59:28 +03:00
" IsItemVisible() = %d \n " ,
2018-06-13 19:09:27 +03:00
ret ,
2018-06-12 20:59:28 +03:00
ImGui : : IsItemFocused ( ) ,
ImGui : : IsItemHovered ( ) ,
ImGui : : IsItemHovered ( ImGuiHoveredFlags_AllowWhenBlockedByPopup ) ,
ImGui : : IsItemHovered ( ImGuiHoveredFlags_AllowWhenBlockedByActiveItem ) ,
ImGui : : IsItemHovered ( ImGuiHoveredFlags_AllowWhenOverlapped ) ,
ImGui : : IsItemHovered ( ImGuiHoveredFlags_RectOnly ) ,
ImGui : : IsItemActive ( ) ,
ImGui : : IsItemDeactivated ( ) ,
2018-06-13 19:09:27 +03:00
ImGui : : IsItemDeactivatedAfterChange ( ) ,
2018-06-12 20:59:28 +03:00
ImGui : : IsItemVisible ( )
) ;
static bool embed_all_inside_a_child_window = false ;
ImGui : : Checkbox ( " Embed everything inside a child window (for additional testing) " , & embed_all_inside_a_child_window ) ;
if ( embed_all_inside_a_child_window )
ImGui : : BeginChild ( " outer_child " , ImVec2 ( 0 , ImGui : : GetFontSize ( ) * 20 ) , true ) ;
// Testing IsWindowFocused() function with its various flags. Note that the flags can be combined.
ImGui : : BulletText (
" IsWindowFocused() = %d \n "
" IsWindowFocused(_ChildWindows) = %d \n "
" IsWindowFocused(_ChildWindows|_RootWindow) = %d \n "
" IsWindowFocused(_RootWindow) = %d \n "
" IsWindowFocused(_AnyWindow) = %d \n " ,
ImGui : : IsWindowFocused ( ) ,
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_ChildWindows ) ,
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_RootWindow ) ,
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_RootWindow ) ,
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_AnyWindow ) ) ;
// Testing IsWindowHovered() function with its various flags. Note that the flags can be combined.
ImGui : : BulletText (
" IsWindowHovered() = %d \n "
" IsWindowHovered(_AllowWhenBlockedByPopup) = %d \n "
" IsWindowHovered(_AllowWhenBlockedByActiveItem) = %d \n "
" IsWindowHovered(_ChildWindows) = %d \n "
" IsWindowHovered(_ChildWindows|_RootWindow) = %d \n "
" IsWindowHovered(_RootWindow) = %d \n "
" IsWindowHovered(_AnyWindow) = %d \n " ,
ImGui : : IsWindowHovered ( ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_AllowWhenBlockedByPopup ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_AllowWhenBlockedByActiveItem ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_ChildWindows ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_RootWindow ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_RootWindow ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_AnyWindow ) ) ;
ImGui : : BeginChild ( " child " , ImVec2 ( 0 , 50 ) , true ) ;
ImGui : : Text ( " This is another child window for testing with the _ChildWindows flag. " ) ;
ImGui : : EndChild ( ) ;
if ( embed_all_inside_a_child_window )
EndChild ( ) ;
2018-07-17 19:18:14 +03:00
// Calling IsItemHovered() after begin returns the hovered status of the title bar.
// This is useful in particular if you want to create a context menu (with BeginPopupContextItem) associated to the title bar of a window.
static bool test_window = false ;
ImGui : : Checkbox ( " Hovered/Active tests after Begin() for title bar testing " , & test_window ) ;
if ( test_window )
{
ImGui : : Begin ( " Title bar Hovered/Active tests " , & test_window ) ;
if ( ImGui : : BeginPopupContextItem ( ) ) // <-- This is using IsItemHovered()
{
if ( ImGui : : MenuItem ( " Close " ) ) { test_window = false ; }
ImGui : : EndPopup ( ) ;
}
ImGui : : Text (
" IsItemHovered() after begin = %d (== is title bar hovered) \n "
" IsItemActive() after begin = %d (== is window being clicked/moved) \n " ,
ImGui : : IsItemHovered ( ) , ImGui : : IsItemActive ( ) ) ;
ImGui : : End ( ) ;
}
2018-06-12 20:59:28 +03:00
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
}
if ( ImGui : : CollapsingHeader ( " Layout " ) )
{
if ( ImGui : : TreeNode ( " Child regions " ) )
{
2017-12-15 07:47:35 +03:00
static bool disable_mouse_wheel = false ;
2018-02-02 08:03:15 +03:00
static bool disable_menu = false ;
2017-12-15 07:47:35 +03:00
ImGui : : Checkbox ( " Disable Mouse Wheel " , & disable_mouse_wheel ) ;
2018-02-02 08:03:15 +03:00
ImGui : : Checkbox ( " Disable Menu " , & disable_menu ) ;
2017-12-15 07:47:35 +03:00
2015-08-08 19:56:09 +03:00
static int line = 50 ;
bool goto_line = ImGui : : Button ( " Goto " ) ;
2015-08-26 06:44:36 +03:00
ImGui : : SameLine ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PushItemWidth ( 100 ) ;
goto_line | = ImGui : : InputInt ( " ##Line " , & line , 0 , 0 , ImGuiInputTextFlags_EnterReturnsTrue ) ;
ImGui : : PopItemWidth ( ) ;
2017-12-15 07:47:35 +03:00
2018-01-12 09:10:53 +03:00
// Child 1: no border, enable horizontal scrollbar
2015-08-08 19:56:09 +03:00
{
2018-01-12 09:10:53 +03:00
ImGui : : BeginChild ( " Child1 " , ImVec2 ( ImGui : : GetWindowContentRegionWidth ( ) * 0.5f , 300 ) , false , ImGuiWindowFlags_HorizontalScrollbar | ( disable_mouse_wheel ? ImGuiWindowFlags_NoScrollWithMouse : 0 ) ) ;
for ( int i = 0 ; i < 100 ; i + + )
{
ImGui : : Text ( " %04d: scrollable region " , i ) ;
if ( goto_line & & line = = i )
ImGui : : SetScrollHere ( ) ;
}
if ( goto_line & & line > = 100 )
2015-08-08 19:56:09 +03:00
ImGui : : SetScrollHere ( ) ;
2018-01-12 09:10:53 +03:00
ImGui : : EndChild ( ) ;
2015-08-08 19:56:09 +03:00
}
ImGui : : SameLine ( ) ;
2018-01-12 09:10:53 +03:00
// Child 2: rounded border
2015-08-08 19:56:09 +03:00
{
2018-01-12 09:10:53 +03:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ChildRounding , 5.0f ) ;
2018-02-02 08:03:15 +03:00
ImGui : : BeginChild ( " Child2 " , ImVec2 ( 0 , 300 ) , true , ( disable_mouse_wheel ? ImGuiWindowFlags_NoScrollWithMouse : 0 ) | ( disable_menu ? 0 : ImGuiWindowFlags_MenuBar ) ) ;
if ( ! disable_menu & & ImGui : : BeginMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " Menu " ) )
{
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenuBar ( ) ;
}
2018-01-12 09:10:53 +03:00
ImGui : : Columns ( 2 ) ;
for ( int i = 0 ; i < 100 ; i + + )
{
char buf [ 32 ] ;
2018-06-05 19:18:15 +03:00
sprintf ( buf , " %03d " , i ) ;
2018-01-12 09:10:53 +03:00
ImGui : : Button ( buf , ImVec2 ( - 1.0f , 0.0f ) ) ;
2018-06-05 19:18:15 +03:00
ImGui : : NextColumn ( ) ;
2018-01-12 09:10:53 +03:00
}
ImGui : : EndChild ( ) ;
ImGui : : PopStyleVar ( ) ;
2015-08-08 19:56:09 +03:00
}
ImGui : : TreePop ( ) ;
}
2015-12-04 05:33:57 +03:00
if ( ImGui : : TreeNode ( " Widgets Width " ) )
2015-08-08 19:56:09 +03:00
{
static float f = 0.0f ;
2016-03-26 20:44:17 +03:00
ImGui : : Text ( " PushItemWidth(100) " ) ;
2016-01-09 09:29:36 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Fixed width. " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PushItemWidth ( 100 ) ;
2015-09-01 23:34:54 +03:00
ImGui : : DragFloat ( " float##1 " , & f ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PopItemWidth ( ) ;
2016-01-09 09:29:36 +03:00
ImGui : : Text ( " PushItemWidth(GetWindowWidth() * 0.5f) " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Half of window width. " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PushItemWidth ( ImGui : : GetWindowWidth ( ) * 0.5f ) ;
2015-09-01 23:34:54 +03:00
ImGui : : DragFloat ( " float##2 " , & f ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PopItemWidth ( ) ;
2016-01-09 09:29:36 +03:00
ImGui : : Text ( " PushItemWidth(GetContentRegionAvailWidth() * 0.5f) " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Half of available width. \n (~ right-cursor_pos) \n (works within a column set) " ) ;
2015-09-01 23:34:54 +03:00
ImGui : : PushItemWidth ( ImGui : : GetContentRegionAvailWidth ( ) * 0.5f ) ;
ImGui : : DragFloat ( " float##3 " , & f ) ;
ImGui : : PopItemWidth ( ) ;
2016-01-09 09:29:36 +03:00
ImGui : : Text ( " PushItemWidth(-100) " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Align to right edge minus 100 " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PushItemWidth ( - 100 ) ;
2015-09-01 23:34:54 +03:00
ImGui : : DragFloat ( " float##4 " , & f ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PopItemWidth ( ) ;
2016-01-09 09:29:36 +03:00
ImGui : : Text ( " PushItemWidth(-1) " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Align to right edge " ) ;
ImGui : : PushItemWidth ( - 1 ) ;
ImGui : : DragFloat ( " float##5 " , & f ) ;
ImGui : : PopItemWidth ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Basic Horizontal Layout " ) )
{
2016-09-13 06:56:38 +03:00
ImGui : : TextWrapped ( " (Use ImGui::SameLine() to keep adding items to the right of the preceding item) " ) ;
2015-08-08 19:56:09 +03:00
// Text
ImGui : : Text ( " Two items: Hello " ) ; ImGui : : SameLine ( ) ;
ImGui : : TextColored ( ImVec4 ( 1 , 1 , 0 , 1 ) , " Sailor " ) ;
// Adjust spacing
ImGui : : Text ( " More spacing: Hello " ) ; ImGui : : SameLine ( 0 , 20 ) ;
ImGui : : TextColored ( ImVec4 ( 1 , 1 , 0 , 1 ) , " Sailor " ) ;
// Button
2017-10-12 09:33:45 +03:00
ImGui : : AlignTextToFramePadding ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " Normal buttons " ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " Banana " ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " Apple " ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " Corniflower " ) ;
// Button
ImGui : : Text ( " Small buttons " ) ; ImGui : : SameLine ( ) ;
ImGui : : SmallButton ( " Like this one " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " can fit within a text block. " ) ;
// Aligned to arbitrary position. Easy/cheap column.
2015-08-26 06:44:36 +03:00
ImGui : : Text ( " Aligned " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : SameLine ( 150 ) ; ImGui : : Text ( " x=150 " ) ;
ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " x=300 " ) ;
ImGui : : Text ( " Aligned " ) ;
ImGui : : SameLine ( 150 ) ; ImGui : : SmallButton ( " x=150 " ) ;
ImGui : : SameLine ( 300 ) ; ImGui : : SmallButton ( " x=300 " ) ;
// Checkbox
static bool c1 = false , c2 = false , c3 = false , c4 = false ;
ImGui : : Checkbox ( " My " , & c1 ) ; ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " Tailor " , & c2 ) ; ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " Is " , & c3 ) ; ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " Rich " , & c4 ) ;
// Various
static float f0 = 1.0f , f1 = 2.0f , f2 = 3.0f ;
ImGui : : PushItemWidth ( 80 ) ;
const char * items [ ] = { " AAAA " , " BBBB " , " CCCC " , " DDDD " } ;
static int item = - 1 ;
ImGui : : Combo ( " Combo " , & item , items , IM_ARRAYSIZE ( items ) ) ; ImGui : : SameLine ( ) ;
ImGui : : SliderFloat ( " X " , & f0 , 0.0f , 5.0f ) ; ImGui : : SameLine ( ) ;
ImGui : : SliderFloat ( " Y " , & f1 , 0.0f , 5.0f ) ; ImGui : : SameLine ( ) ;
2015-08-26 06:44:36 +03:00
ImGui : : SliderFloat ( " Z " , & f2 , 0.0f , 5.0f ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PopItemWidth ( ) ;
ImGui : : PushItemWidth ( 80 ) ;
ImGui : : Text ( " Lists: " ) ;
static int selection [ 4 ] = { 0 , 1 , 2 , 3 } ;
for ( int i = 0 ; i < 4 ; i + + )
{
if ( i > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushID ( i ) ;
ImGui : : ListBox ( " " , & selection [ i ] , items , IM_ARRAYSIZE ( items ) ) ;
ImGui : : PopID ( ) ;
2015-08-26 06:44:36 +03:00
//if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i);
2015-08-08 19:56:09 +03:00
}
ImGui : : PopItemWidth ( ) ;
// Dummy
ImVec2 sz ( 30 , 30 ) ;
ImGui : : Button ( " A " , sz ) ; ImGui : : SameLine ( ) ;
ImGui : : Dummy ( sz ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " B " , sz ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Groups " ) )
{
2015-09-12 08:40:55 +03:00
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.) " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : BeginGroup ( ) ;
{
ImGui : : BeginGroup ( ) ;
ImGui : : Button ( " AAA " ) ;
ImGui : : SameLine ( ) ;
ImGui : : Button ( " BBB " ) ;
ImGui : : SameLine ( ) ;
ImGui : : BeginGroup ( ) ;
ImGui : : Button ( " CCC " ) ;
ImGui : : Button ( " DDD " ) ;
ImGui : : EndGroup ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : Button ( " EEE " ) ;
ImGui : : EndGroup ( ) ;
2017-09-28 05:42:53 +03:00
if ( ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( " First group hovered " ) ;
2015-08-08 19:56:09 +03:00
}
// Capture the group size and create widgets using the same size
ImVec2 size = ImGui : : GetItemRectSize ( ) ;
const float values [ 5 ] = { 0.5f , 0.20f , 0.80f , 0.60f , 0.25f } ;
ImGui : : PlotHistogram ( " ##values " , values , IM_ARRAYSIZE ( values ) , 0 , NULL , 0.0f , 1.0f , size ) ;
ImGui : : Button ( " ACTION " , ImVec2 ( ( size . x - ImGui : : GetStyle ( ) . ItemSpacing . x ) * 0.5f , size . y ) ) ;
ImGui : : SameLine ( ) ;
ImGui : : Button ( " REACTION " , ImVec2 ( ( size . x - ImGui : : GetStyle ( ) . ItemSpacing . x ) * 0.5f , size . y ) ) ;
ImGui : : EndGroup ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : Button ( " LEVERAGE \n BUZZWORD " , size ) ;
ImGui : : SameLine ( ) ;
2018-04-29 18:47:32 +03:00
if ( ImGui : : ListBoxHeader ( " List " , size ) )
{
ImGui : : Selectable ( " Selected " , true ) ;
ImGui : : Selectable ( " Not Selected " , false ) ;
ImGui : : ListBoxFooter ( ) ;
}
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Text Baseline Alignment " ) )
{
2015-08-26 06:44:36 +03:00
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) " ) ;
2015-08-08 19:56:09 +03:00
2015-08-26 06:44:36 +03:00
ImGui : : Text ( " One \n Two \n Three " ) ; ImGui : : SameLine ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " Hello \n World " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Banana " ) ;
ImGui : : Text ( " Banana " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Hello \n World " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " One \n Two \n Three " ) ;
2016-06-26 02:30:09 +03:00
ImGui : : Button ( " HOP##1 " ) ; ImGui : : SameLine ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " Banana " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Hello \n World " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Banana " ) ;
2016-06-26 02:30:09 +03:00
ImGui : : Button ( " HOP##2 " ) ; ImGui : : SameLine ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " Hello \n World " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Banana " ) ;
2016-06-26 02:30:09 +03:00
ImGui : : Button ( " TEST##1 " ) ; ImGui : : SameLine ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " TEST " ) ; ImGui : : SameLine ( ) ;
2016-06-26 02:30:09 +03:00
ImGui : : SmallButton ( " TEST##2 " ) ;
2015-08-08 19:56:09 +03:00
2017-10-12 09:33:45 +03:00
ImGui : : AlignTextToFramePadding ( ) ; // If your line starts with text, call this to align it to upcoming widgets.
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " Text aligned to Widget " ) ; ImGui : : SameLine ( ) ;
2016-06-26 02:30:09 +03:00
ImGui : : Button ( " Widget##1 " ) ; ImGui : : SameLine ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " Widget " ) ; ImGui : : SameLine ( ) ;
2017-09-29 07:51:20 +03:00
ImGui : : SmallButton ( " Widget##2 " ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " Widget##3 " ) ;
2015-08-08 19:56:09 +03:00
2015-12-04 05:33:57 +03:00
// Tree
const float spacing = ImGui : : GetStyle ( ) . ItemInnerSpacing . x ;
2016-03-26 20:44:17 +03:00
ImGui : : Button ( " Button##1 " ) ;
ImGui : : SameLine ( 0.0f , spacing ) ;
2015-12-04 05:33:57 +03:00
if ( ImGui : : TreeNode ( " Node##1 " ) ) { for ( int i = 0 ; i < 6 ; i + + ) ImGui : : BulletText ( " Item %d.. " , i ) ; ImGui : : TreePop ( ) ; } // Dummy tree data
2017-10-12 09:33:45 +03:00
ImGui : : AlignTextToFramePadding ( ) ; // Vertically align text node a bit lower so it'll be vertically centered with upcoming widget. Otherwise you can use SmallButton (smaller fit).
2016-05-04 05:29:37 +03:00
bool node_open = ImGui : : TreeNode ( " Node##2 " ) ; // Common mistake to avoid: if we want to SameLine after TreeNode we need to do it before we add child content.
2015-12-04 05:33:57 +03:00
ImGui : : SameLine ( 0.0f , spacing ) ; ImGui : : Button ( " Button##2 " ) ;
2016-05-04 05:29:37 +03:00
if ( node_open ) { for ( int i = 0 ; i < 6 ; i + + ) ImGui : : BulletText ( " Item %d.. " , i ) ; ImGui : : TreePop ( ) ; } // Dummy tree data
2015-12-04 05:33:57 +03:00
2015-12-15 09:56:16 +03:00
// Bullet
2016-03-26 20:44:17 +03:00
ImGui : : Button ( " Button##3 " ) ;
ImGui : : SameLine ( 0.0f , spacing ) ;
2015-12-15 09:56:16 +03:00
ImGui : : BulletText ( " Bullet text " ) ;
2017-10-12 09:33:45 +03:00
ImGui : : AlignTextToFramePadding ( ) ;
2015-12-15 09:56:16 +03:00
ImGui : : BulletText ( " Node " ) ;
ImGui : : SameLine ( 0.0f , spacing ) ; ImGui : : Button ( " Button##4 " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Scrolling " ) )
{
2015-08-30 03:00:23 +03:00
ImGui : : TextWrapped ( " (Use SetScrollHere() or SetScrollFromPosY() to scroll to a given position.) " ) ;
2015-08-08 19:56:09 +03:00
static bool track = true ;
static int track_line = 50 , scroll_to_px = 200 ;
ImGui : : Checkbox ( " Track " , & track ) ;
2016-05-08 20:16:37 +03:00
ImGui : : PushItemWidth ( 100 ) ;
2018-05-11 18:26:25 +03:00
ImGui : : SameLine ( 130 ) ; track | = ImGui : : DragInt ( " ##line " , & track_line , 0.25f , 0 , 99 , " Line = %d " ) ;
2017-08-08 19:11:10 +03:00
bool scroll_to = ImGui : : Button ( " Scroll To Pos " ) ;
2018-05-11 18:26:25 +03:00
ImGui : : SameLine ( 130 ) ; scroll_to | = ImGui : : DragInt ( " ##pos_y " , & scroll_to_px , 1.00f , 0 , 9999 , " Y = %d px " ) ;
2016-05-08 20:16:37 +03:00
ImGui : : PopItemWidth ( ) ;
2015-08-08 19:56:09 +03:00
if ( scroll_to ) track = false ;
for ( int i = 0 ; i < 5 ; i + + )
{
if ( i > 0 ) ImGui : : SameLine ( ) ;
ImGui : : BeginGroup ( ) ;
ImGui : : Text ( " %s " , i = = 0 ? " Top " : i = = 1 ? " 25% " : i = = 2 ? " Center " : i = = 3 ? " 75% " : " Bottom " ) ;
2015-12-04 05:33:57 +03:00
ImGui : : BeginChild ( ImGui : : GetID ( ( void * ) ( intptr_t ) i ) , ImVec2 ( ImGui : : GetWindowWidth ( ) * 0.17f , 200.0f ) , true ) ;
2015-08-08 19:56:09 +03:00
if ( scroll_to )
ImGui : : SetScrollFromPosY ( ImGui : : GetCursorStartPos ( ) . y + scroll_to_px , i * 0.25f ) ;
for ( int line = 0 ; line < 100 ; line + + )
{
if ( track & & line = = track_line )
{
ImGui : : TextColored ( ImColor ( 255 , 255 , 0 ) , " Line %d " , line ) ;
ImGui : : SetScrollHere ( i * 0.25f ) ; // 0.0f:top, 0.5f:center, 1.0f:bottom
}
else
{
ImGui : : Text ( " Line %d " , line ) ;
}
}
2017-08-08 19:11:10 +03:00
float scroll_y = ImGui : : GetScrollY ( ) , scroll_max_y = ImGui : : GetScrollMaxY ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : EndChild ( ) ;
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " %.0f/%0.f " , scroll_y , scroll_max_y ) ;
2015-08-08 19:56:09 +03:00
ImGui : : EndGroup ( ) ;
}
ImGui : : TreePop ( ) ;
}
2015-09-01 23:34:54 +03:00
if ( ImGui : : TreeNode ( " Horizontal Scrolling " ) )
{
ImGui : : Bullet ( ) ; ImGui : : TextWrapped ( " Horizontal scrolling for a window has to be enabled explicitly via the ImGuiWindowFlags_HorizontalScrollbar flag. " ) ;
ImGui : : Bullet ( ) ; ImGui : : TextWrapped ( " You may want to explicitly specify content width by calling SetNextWindowContentWidth() before Begin(). " ) ;
2015-10-03 03:57:00 +03:00
static int lines = 7 ;
ImGui : : SliderInt ( " Lines " , & lines , 1 , 15 ) ;
2015-09-01 23:34:54 +03:00
ImGui : : PushStyleVar ( ImGuiStyleVar_FrameRounding , 3.0f ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 2.0f , 1.0f ) ) ;
2017-12-12 19:54:29 +03:00
ImGui : : BeginChild ( " scrolling " , ImVec2 ( 0 , ImGui : : GetFrameHeightWithSpacing ( ) * 7 + 30 ) , true , ImGuiWindowFlags_HorizontalScrollbar ) ;
2015-10-03 03:57:00 +03:00
for ( int line = 0 ; line < lines ; line + + )
2015-09-01 23:34:54 +03:00
{
2018-05-17 18:47:13 +03:00
// Display random stuff (for the sake of this trivial demo we are using basic Button+SameLine. If you want to create your own time line for a real application you may be better off
2016-12-22 09:56:54 +03:00
// manipulating the cursor position yourself, aka using SetCursorPos/SetCursorScreenPos to position the widgets yourself. You may also want to use the lower-level ImDrawList API)
2015-09-01 23:34:54 +03:00
int num_buttons = 10 + ( ( line & 1 ) ? line * 9 : line * 3 ) ;
for ( int n = 0 ; n < num_buttons ; n + + )
{
if ( n > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushID ( n + line * 1000 ) ;
char num_buf [ 16 ] ;
2017-12-23 23:05:41 +03:00
sprintf ( num_buf , " %d " , n ) ;
const char * label = ( ! ( n % 15 ) ) ? " FizzBuzz " : ( ! ( n % 3 ) ) ? " Fizz " : ( ! ( n % 5 ) ) ? " Buzz " : num_buf ;
2015-09-01 23:34:54 +03:00
float hue = n * 0.05f ;
2017-08-20 20:25:00 +03:00
ImGui : : PushStyleColor ( ImGuiCol_Button , ( ImVec4 ) ImColor : : HSV ( hue , 0.6f , 0.6f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonHovered , ( ImVec4 ) ImColor : : HSV ( hue , 0.7f , 0.7f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonActive , ( ImVec4 ) ImColor : : HSV ( hue , 0.8f , 0.8f ) ) ;
2015-09-01 23:34:54 +03:00
ImGui : : Button ( label , ImVec2 ( 40.0f + sinf ( ( float ) ( line + n ) ) * 20.0f , 0.0f ) ) ;
ImGui : : PopStyleColor ( 3 ) ;
ImGui : : PopID ( ) ;
}
}
2017-08-08 19:11:10 +03:00
float scroll_x = ImGui : : GetScrollX ( ) , scroll_max_x = ImGui : : GetScrollMaxX ( ) ;
2015-09-01 23:34:54 +03:00
ImGui : : EndChild ( ) ;
ImGui : : PopStyleVar ( 2 ) ;
float scroll_x_delta = 0.0f ;
2018-05-17 18:47:13 +03:00
ImGui : : SmallButton ( " << " ) ; if ( ImGui : : IsItemActive ( ) ) scroll_x_delta = - ImGui : : GetIO ( ) . DeltaTime * 1000.0f ; ImGui : : SameLine ( ) ;
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Scroll from code " ) ; ImGui : : SameLine ( ) ;
2018-05-17 18:47:13 +03:00
ImGui : : SmallButton ( " >> " ) ; if ( ImGui : : IsItemActive ( ) ) scroll_x_delta = + ImGui : : GetIO ( ) . DeltaTime * 1000.0f ; ImGui : : SameLine ( ) ;
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " %.0f/%.0f " , scroll_x , scroll_max_x ) ;
2015-09-01 23:34:54 +03:00
if ( scroll_x_delta ! = 0.0f )
{
ImGui : : BeginChild ( " scrolling " ) ; // Demonstrate a trick: you can use Begin to set yourself in the context of another window (here we are already out of your child window)
ImGui : : SetScrollX ( ImGui : : GetScrollX ( ) + scroll_x_delta ) ;
ImGui : : End ( ) ;
}
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
if ( ImGui : : TreeNode ( " Clipping " ) )
{
static ImVec2 size ( 100 , 100 ) , offset ( 50 , 20 ) ;
ImGui : : TextWrapped ( " On a per-widget basis we are occasionally clipping text CPU-side if it won't fit in its frame. Otherwise we are doing coarser clipping + passing a scissor rectangle to the renderer. The system is designed to try minimizing both execution and CPU/GPU rendering cost. " ) ;
ImGui : : DragFloat2 ( " size " , ( float * ) & size , 0.5f , 0.0f , 200.0f , " %.0f " ) ;
2015-12-04 05:33:57 +03:00
ImGui : : TextWrapped ( " (Click and drag) " ) ;
2015-08-08 19:56:09 +03:00
ImVec2 pos = ImGui : : GetCursorScreenPos ( ) ;
ImVec4 clip_rect ( pos . x , pos . y , pos . x + size . x , pos . y + size . y ) ;
2015-09-12 08:40:55 +03:00
ImGui : : InvisibleButton ( " ##dummy " , size ) ;
if ( ImGui : : IsItemActive ( ) & & ImGui : : IsMouseDragging ( ) ) { offset . x + = ImGui : : GetIO ( ) . MouseDelta . x ; offset . y + = ImGui : : GetIO ( ) . MouseDelta . y ; }
2018-01-12 09:10:53 +03:00
ImGui : : GetWindowDrawList ( ) - > AddRectFilled ( pos , ImVec2 ( pos . x + size . x , pos . y + size . y ) , IM_COL32 ( 90 , 90 , 120 , 255 ) ) ;
ImGui : : GetWindowDrawList ( ) - > AddText ( ImGui : : GetFont ( ) , ImGui : : GetFontSize ( ) * 2.0f , ImVec2 ( pos . x + offset . x , pos . y + offset . y ) , IM_COL32 ( 255 , 255 , 255 , 255 ) , " Line 1 hello \n Line 2 clip me! " , NULL , 0.0f , & clip_rect ) ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
}
if ( ImGui : : CollapsingHeader ( " Popups & Modal windows " ) )
{
if ( ImGui : : TreeNode ( " Popups " ) )
{
ImGui : : TextWrapped ( " When a popup is active, it inhibits interacting with windows that are behind the popup. Clicking outside the popup closes it. " ) ;
static int selected_fish = - 1 ;
const char * names [ ] = { " Bream " , " Haddock " , " Mackerel " , " Pollock " , " Tilefish " } ;
static bool toggles [ ] = { true , false , false , false , false } ;
2016-12-22 09:56:54 +03:00
// Simple selection popup
// (If you want to show the current selection inside the Button itself, you may want to build a string using the "###" operator to preserve a constant ID with a variable label)
2015-08-08 19:56:09 +03:00
if ( ImGui : : Button ( " Select.. " ) )
ImGui : : OpenPopup ( " select " ) ;
ImGui : : SameLine ( ) ;
2017-11-20 19:29:10 +03:00
ImGui : : TextUnformatted ( selected_fish = = - 1 ? " <None> " : names [ selected_fish ] ) ;
2015-08-08 19:56:09 +03:00
if ( ImGui : : BeginPopup ( " select " ) )
{
ImGui : : Text ( " Aquarium " ) ;
ImGui : : Separator ( ) ;
for ( int i = 0 ; i < IM_ARRAYSIZE ( names ) ; i + + )
if ( ImGui : : Selectable ( names [ i ] ) )
selected_fish = i ;
ImGui : : EndPopup ( ) ;
}
2016-12-22 09:56:54 +03:00
// Showing a menu with toggles
2015-08-08 19:56:09 +03:00
if ( ImGui : : Button ( " Toggle.. " ) )
ImGui : : OpenPopup ( " toggle " ) ;
if ( ImGui : : BeginPopup ( " toggle " ) )
{
for ( int i = 0 ; i < IM_ARRAYSIZE ( names ) ; i + + )
ImGui : : MenuItem ( names [ i ] , " " , & toggles [ i ] ) ;
if ( ImGui : : BeginMenu ( " Sub-menu " ) )
{
ImGui : : MenuItem ( " Click me " ) ;
ImGui : : EndMenu ( ) ;
}
ImGui : : Separator ( ) ;
ImGui : : Text ( " Tooltip here " ) ;
if ( ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( " I am a tooltip over a popup " ) ;
if ( ImGui : : Button ( " Stacked Popup " ) )
ImGui : : OpenPopup ( " another popup " ) ;
if ( ImGui : : BeginPopup ( " another popup " ) )
{
for ( int i = 0 ; i < IM_ARRAYSIZE ( names ) ; i + + )
ImGui : : MenuItem ( names [ i ] , " " , & toggles [ i ] ) ;
if ( ImGui : : BeginMenu ( " Sub-menu " ) )
{
ImGui : : MenuItem ( " Click me " ) ;
ImGui : : EndMenu ( ) ;
}
ImGui : : EndPopup ( ) ;
}
ImGui : : EndPopup ( ) ;
}
if ( ImGui : : Button ( " Popup Menu.. " ) )
2016-12-22 09:56:54 +03:00
ImGui : : OpenPopup ( " FilePopup " ) ;
if ( ImGui : : BeginPopup ( " FilePopup " ) )
2015-08-08 19:56:09 +03:00
{
ShowExampleMenuFile ( ) ;
ImGui : : EndPopup ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Context menus " ) )
{
2017-10-17 18:14:14 +03:00
// BeginPopupContextItem() is a helper to provide common/simple popup behavior of essentially doing:
// if (IsItemHovered() && IsMouseClicked(0))
// OpenPopup(id);
// return BeginPopup(id);
// For more advanced uses you may want to replicate and cuztomize this code. This the comments inside BeginPopupContextItem() implementation.
2015-08-08 19:56:09 +03:00
static float value = 0.5f ;
ImGui : : Text ( " Value = %.3f (<-- right-click here) " , value ) ;
if ( ImGui : : BeginPopupContextItem ( " item context menu " ) )
{
2015-08-26 06:44:36 +03:00
if ( ImGui : : Selectable ( " Set to zero " ) ) value = 0.0f ;
if ( ImGui : : Selectable ( " Set to PI " ) ) value = 3.1415f ;
2017-10-21 18:22:26 +03:00
ImGui : : PushItemWidth ( - 1 ) ;
ImGui : : DragFloat ( " ##Value " , & value , 0.1f , 0.0f , 0.0f ) ;
ImGui : : PopItemWidth ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : EndPopup ( ) ;
}
2017-08-08 19:11:10 +03:00
static char name [ 32 ] = " Label1 " ;
2017-10-17 18:14:14 +03:00
char buf [ 64 ] ; sprintf ( buf , " Button: %s###Button " , name ) ; // ### operator override ID ignoring the preceding label
2017-08-08 19:11:10 +03:00
ImGui : : Button ( buf ) ;
2017-10-17 18:14:14 +03:00
if ( ImGui : : BeginPopupContextItem ( ) ) // When used after an item that has an ID (here the Button), we can skip providing an ID to BeginPopupContextItem().
2015-08-08 19:56:09 +03:00
{
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Edit name: " ) ;
ImGui : : InputText ( " ##edit " , name , IM_ARRAYSIZE ( name ) ) ;
2015-08-08 19:56:09 +03:00
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
ImGui : : EndPopup ( ) ;
}
ImGui : : SameLine ( ) ; ImGui : : Text ( " (<-- right-click here) " ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Modals " ) )
2015-08-26 06:44:36 +03:00
{
2015-08-08 19:56:09 +03:00
ImGui : : TextWrapped ( " Modal windows are like popups but the user cannot close them by clicking outside the window. " ) ;
if ( ImGui : : Button ( " Delete.. " ) )
ImGui : : OpenPopup ( " Delete? " ) ;
if ( ImGui : : BeginPopupModal ( " Delete? " , NULL , ImGuiWindowFlags_AlwaysAutoResize ) )
{
2018-02-07 00:24:05 +03:00
ImGui : : Text ( " All those beautiful files will be deleted. \n This operation cannot be undone! \n \n " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Separator ( ) ;
2015-08-26 06:44:36 +03:00
2016-05-11 06:07:30 +03:00
//static int dummy_i = 0;
//ImGui::Combo("Combo", &dummy_i, "Delete\0Delete harder\0");
2015-08-08 19:56:09 +03:00
static bool dont_ask_me_next_time = false ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 0 , 0 ) ) ;
ImGui : : Checkbox ( " Don't ask me next time " , & dont_ask_me_next_time ) ;
ImGui : : PopStyleVar ( ) ;
if ( ImGui : : Button ( " OK " , ImVec2 ( 120 , 0 ) ) ) { ImGui : : CloseCurrentPopup ( ) ; }
2018-02-07 00:24:05 +03:00
ImGui : : SetItemDefaultFocus ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Cancel " , ImVec2 ( 120 , 0 ) ) ) { ImGui : : CloseCurrentPopup ( ) ; }
ImGui : : EndPopup ( ) ;
}
if ( ImGui : : Button ( " Stacked modals.. " ) )
ImGui : : OpenPopup ( " Stacked 1 " ) ;
if ( ImGui : : BeginPopupModal ( " Stacked 1 " ) )
{
2018-07-11 00:13:14 +03:00
ImGui : : Text ( " Hello from Stacked The First \n Using style.Colors[ImGuiCol_ModalWindowDimBg] behind it. " ) ;
2017-08-08 19:11:10 +03:00
static int item = 1 ;
ImGui : : Combo ( " Combo " , & item , " aaaa \0 bbbb \0 cccc \0 dddd \0 eeee \0 \0 " ) ;
2017-10-21 18:22:26 +03:00
static float color [ 4 ] = { 0.4f , 0.7f , 0.0f , 0.5f } ;
ImGui : : ColorEdit4 ( " color " , color ) ; // This is to test behavior of stacked regular popups over a modal
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
if ( ImGui : : Button ( " Add another modal.. " ) )
2015-08-08 19:56:09 +03:00
ImGui : : OpenPopup ( " Stacked 2 " ) ;
if ( ImGui : : BeginPopupModal ( " Stacked 2 " ) )
{
2018-01-13 05:29:32 +03:00
ImGui : : Text ( " Hello from Stacked The Second! " ) ;
2015-08-08 19:56:09 +03:00
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
ImGui : : EndPopup ( ) ;
}
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
ImGui : : EndPopup ( ) ;
}
ImGui : : TreePop ( ) ;
}
2017-10-21 18:22:26 +03:00
if ( ImGui : : TreeNode ( " Menus inside a regular window " ) )
{
ImGui : : TextWrapped ( " Below we are testing adding menu items to a regular window. It's rather unusual but should work! " ) ;
ImGui : : Separator ( ) ;
// NB: As a quirk in this very specific example, we want to differentiate the parent of this menu from the parent of the various popup menus above.
// To do so we are encloding the items in a PushID()/PopID() block to make them two different menusets. If we don't, opening any popup above and hovering our menu here
// would open it. This is because once a menu is active, we allow to switch to a sibling menu by just hovering on it, which is the desired behavior for regular menus.
ImGui : : PushID ( " foo " ) ;
ImGui : : MenuItem ( " Menu item " , " CTRL+M " ) ;
if ( ImGui : : BeginMenu ( " Menu inside a regular window " ) )
{
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
}
ImGui : : PopID ( ) ;
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
}
if ( ImGui : : CollapsingHeader ( " Columns " ) )
{
2017-08-15 08:16:52 +03:00
ImGui : : PushID ( " Columns " ) ;
2015-08-08 19:56:09 +03:00
// Basic columns
2015-11-29 04:58:18 +03:00
if ( ImGui : : TreeNode ( " Basic " ) )
{
2016-06-08 19:57:52 +03:00
ImGui : : Text ( " Without border: " ) ;
ImGui : : Columns ( 3 , " mycolumns3 " , false ) ; // 3-ways, no border
ImGui : : Separator ( ) ;
for ( int n = 0 ; n < 14 ; n + + )
{
char label [ 32 ] ;
sprintf ( label , " Item %d " , n ) ;
if ( ImGui : : Selectable ( label ) ) { }
//if (ImGui::Button(label, ImVec2(-1,0))) {}
ImGui : : NextColumn ( ) ;
}
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : Text ( " With border: " ) ;
ImGui : : Columns ( 4 , " mycolumns " ) ; // 4-ways, with border
2015-11-29 04:58:18 +03:00
ImGui : : Separator ( ) ;
ImGui : : Text ( " ID " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Name " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Path " ) ; ImGui : : NextColumn ( ) ;
2017-09-29 07:51:20 +03:00
ImGui : : Text ( " Hovered " ) ; ImGui : : NextColumn ( ) ;
2015-11-29 04:58:18 +03:00
ImGui : : Separator ( ) ;
const char * names [ 3 ] = { " One " , " Two " , " Three " } ;
const char * paths [ 3 ] = { " /path/one " , " /path/two " , " /path/three " } ;
static int selected = - 1 ;
for ( int i = 0 ; i < 3 ; i + + )
{
char label [ 32 ] ;
sprintf ( label , " %04d " , i ) ;
if ( ImGui : : Selectable ( label , selected = = i , ImGuiSelectableFlags_SpanAllColumns ) )
selected = i ;
2017-09-29 07:51:20 +03:00
bool hovered = ImGui : : IsItemHovered ( ) ;
2015-11-29 04:58:18 +03:00
ImGui : : NextColumn ( ) ;
ImGui : : Text ( names [ i ] ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( paths [ i ] ) ; ImGui : : NextColumn ( ) ;
2017-09-29 07:51:20 +03:00
ImGui : : Text ( " %d " , hovered ) ; ImGui : : NextColumn ( ) ;
2015-11-29 04:58:18 +03:00
}
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
2015-08-08 19:56:09 +03:00
}
// Create multiple items in a same cell before switching to next column
2015-11-29 04:58:18 +03:00
if ( ImGui : : TreeNode ( " Mixed items " ) )
{
ImGui : : Columns ( 3 , " mixed " ) ;
ImGui : : Separator ( ) ;
2015-08-08 19:56:09 +03:00
2015-11-29 04:58:18 +03:00
ImGui : : Text ( " Hello " ) ;
ImGui : : Button ( " Banana " ) ;
ImGui : : NextColumn ( ) ;
2015-08-08 19:56:09 +03:00
2015-11-29 04:58:18 +03:00
ImGui : : Text ( " ImGui " ) ;
ImGui : : Button ( " Apple " ) ;
static float foo = 1.0f ;
2018-04-28 02:16:56 +03:00
ImGui : : InputFloat ( " red " , & foo , 0.05f , 0 , " %.3f " ) ;
2015-11-29 04:58:18 +03:00
ImGui : : Text ( " An extra line here. " ) ;
ImGui : : NextColumn ( ) ;
2015-08-08 19:56:09 +03:00
2017-08-20 20:25:00 +03:00
ImGui : : Text ( " Sailor " ) ;
2015-11-29 04:58:18 +03:00
ImGui : : Button ( " Corniflower " ) ;
static float bar = 1.0f ;
2018-04-28 02:16:56 +03:00
ImGui : : InputFloat ( " blue " , & bar , 0.05f , 0 , " %.3f " ) ;
2015-11-29 04:58:18 +03:00
ImGui : : NextColumn ( ) ;
2015-08-08 19:56:09 +03:00
2016-10-21 09:16:18 +03:00
if ( ImGui : : CollapsingHeader ( " Category A " ) ) { ImGui : : Text ( " Blah blah blah " ) ; } ImGui : : NextColumn ( ) ;
if ( ImGui : : CollapsingHeader ( " Category B " ) ) { ImGui : : Text ( " Blah blah blah " ) ; } ImGui : : NextColumn ( ) ;
if ( ImGui : : CollapsingHeader ( " Category C " ) ) { ImGui : : Text ( " Blah blah blah " ) ; } ImGui : : NextColumn ( ) ;
2015-11-29 04:58:18 +03:00
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
2015-09-01 23:34:54 +03:00
// Word wrapping
2015-11-29 04:58:18 +03:00
if ( ImGui : : TreeNode ( " Word-wrapping " ) )
{
ImGui : : Columns ( 2 , " word-wrapping " ) ;
ImGui : : Separator ( ) ;
ImGui : : TextWrapped ( " The quick brown fox jumps over the lazy dog. " ) ;
ImGui : : TextWrapped ( " Hello Left " ) ;
ImGui : : NextColumn ( ) ;
ImGui : : TextWrapped ( " The quick brown fox jumps over the lazy dog. " ) ;
ImGui : : TextWrapped ( " Hello Right " ) ;
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
2015-11-29 04:58:18 +03:00
if ( ImGui : : TreeNode ( " Borders " ) )
2015-08-08 19:56:09 +03:00
{
2017-08-24 19:58:46 +03:00
// NB: Future columns API should allow automatic horizontal borders.
2015-11-29 04:58:18 +03:00
static bool h_borders = true ;
static bool v_borders = true ;
ImGui : : Checkbox ( " horizontal " , & h_borders ) ;
ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " vertical " , & v_borders ) ;
ImGui : : Columns ( 4 , NULL , v_borders ) ;
2017-08-20 20:25:00 +03:00
for ( int i = 0 ; i < 4 * 3 ; i + + )
2015-08-08 19:56:09 +03:00
{
2017-08-20 20:25:00 +03:00
if ( h_borders & & ImGui : : GetColumnIndex ( ) = = 0 )
ImGui : : Separator ( ) ;
2015-11-29 04:58:18 +03:00
ImGui : : Text ( " %c%c%c " , ' a ' + i , ' a ' + i , ' a ' + i ) ;
2017-08-20 20:25:00 +03:00
ImGui : : Text ( " Width %.2f \n Offset %.2f " , ImGui : : GetColumnWidth ( ) , ImGui : : GetColumnOffset ( ) ) ;
2015-11-29 04:58:18 +03:00
ImGui : : NextColumn ( ) ;
2015-08-08 19:56:09 +03:00
}
2015-11-29 04:58:18 +03:00
ImGui : : Columns ( 1 ) ;
2017-08-20 20:25:00 +03:00
if ( h_borders )
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
// Scrolling columns
/*
if ( ImGui : : TreeNode ( " Vertical Scrolling " ) )
{
ImGui : : BeginChild ( " ##header " , ImVec2 ( 0 , ImGui : : GetTextLineHeightWithSpacing ( ) + ImGui : : GetStyle ( ) . ItemSpacing . y ) ) ;
ImGui : : Columns ( 3 ) ;
ImGui : : Text ( " ID " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Name " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Path " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : EndChild ( ) ;
ImGui : : BeginChild ( " ##scrollingregion " , ImVec2 ( 0 , 60 ) ) ;
ImGui : : Columns ( 3 ) ;
for ( int i = 0 ; i < 10 ; i + + )
{
ImGui : : Text ( " %04d " , i ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Foobar " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " /path/foobar/%04d/ " , i ) ; ImGui : : NextColumn ( ) ;
}
ImGui : : Columns ( 1 ) ;
ImGui : : EndChild ( ) ;
ImGui : : TreePop ( ) ;
}
*/
if ( ImGui : : TreeNode ( " Horizontal Scrolling " ) )
{
2017-12-11 04:19:51 +03:00
ImGui : : SetNextWindowContentSize ( ImVec2 ( 1500.0f , 0.0f ) ) ;
2017-11-16 04:10:11 +03:00
ImGui : : BeginChild ( " ##ScrollingRegion " , ImVec2 ( 0 , ImGui : : GetFontSize ( ) * 20 ) , false , ImGuiWindowFlags_HorizontalScrollbar ) ;
2017-08-20 20:25:00 +03:00
ImGui : : Columns ( 10 ) ;
2017-11-16 04:10:11 +03:00
int ITEMS_COUNT = 2000 ;
ImGuiListClipper clipper ( ITEMS_COUNT ) ; // Also demonstrate using the clipper for large list
while ( clipper . Step ( ) )
{
for ( int i = clipper . DisplayStart ; i < clipper . DisplayEnd ; i + + )
for ( int j = 0 ; j < 10 ; j + + )
{
ImGui : : Text ( " Line %d Column %d... " , i , j ) ;
ImGui : : NextColumn ( ) ;
}
}
2017-08-20 20:25:00 +03:00
ImGui : : Columns ( 1 ) ;
ImGui : : EndChild ( ) ;
2015-11-29 04:58:18 +03:00
ImGui : : TreePop ( ) ;
}
2016-05-04 05:29:37 +03:00
bool node_open = ImGui : : TreeNode ( " Tree within single cell " ) ;
2017-08-08 19:11:10 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " NB: Tree node must be poped before ending the cell. There's no storage of state per-cell. " ) ;
2016-05-04 05:29:37 +03:00
if ( node_open )
2015-11-29 04:58:18 +03:00
{
2016-03-26 20:44:17 +03:00
ImGui : : Columns ( 2 , " tree items " ) ;
2015-11-29 04:58:18 +03:00
ImGui : : Separator ( ) ;
if ( ImGui : : TreeNode ( " Hello " ) ) { ImGui : : BulletText ( " Sailor " ) ; ImGui : : TreePop ( ) ; } ImGui : : NextColumn ( ) ;
if ( ImGui : : TreeNode ( " Bonjour " ) ) { ImGui : : BulletText ( " Marin " ) ; ImGui : : TreePop ( ) ; } ImGui : : NextColumn ( ) ;
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
2017-08-15 08:16:52 +03:00
ImGui : : PopID ( ) ;
2015-08-08 19:56:09 +03:00
}
if ( ImGui : : CollapsingHeader ( " Filtering " ) )
{
static ImGuiTextFilter filter ;
ImGui : : Text ( " Filter usage: \n "
" \" \" display all lines \n "
" \" xxx \" display lines containing \" xxx \" \n "
" \" xxx,yyy \" display lines containing \" xxx \" or \" yyy \" \n "
" \" -xxx \" hide lines containing \" xxx \" " ) ;
filter . Draw ( ) ;
const char * lines [ ] = { " aaa1.c " , " bbb1.c " , " ccc1.c " , " aaa2.cpp " , " bbb2.cpp " , " ccc2.cpp " , " abc.h " , " hello, world " } ;
for ( int i = 0 ; i < IM_ARRAYSIZE ( lines ) ; i + + )
if ( filter . PassFilter ( lines [ i ] ) )
ImGui : : BulletText ( " %s " , lines [ i ] ) ;
}
2018-02-07 00:24:05 +03:00
if ( ImGui : : CollapsingHeader ( " Inputs, Navigation & Focus " ) )
2015-08-08 19:56:09 +03:00
{
2017-08-08 19:11:10 +03:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
ImGui : : Text ( " WantCaptureMouse: %d " , io . WantCaptureMouse ) ;
ImGui : : Text ( " WantCaptureKeyboard: %d " , io . WantCaptureKeyboard ) ;
ImGui : : Text ( " WantTextInput: %d " , io . WantTextInput ) ;
2018-03-21 19:47:24 +03:00
ImGui : : Text ( " WantSetMousePos: %d " , io . WantSetMousePos ) ;
2018-02-07 00:24:05 +03:00
ImGui : : Text ( " NavActive: %d, NavVisible: %d " , io . NavActive , io . NavVisible ) ;
ImGui : : Checkbox ( " io.MouseDrawCursor " , & io . MouseDrawCursor ) ;
2018-04-07 05:34:49 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Instruct ImGui to render a mouse cursor for you in software. Note that a mouse cursor rendered via your application GPU rendering path will feel more laggy than hardware cursor, but will be more in sync with your other visuals. \n \n Some desktop applications may use both kinds of cursors (e.g. enable software cursor only when resizing/dragging something). " ) ;
2018-05-11 18:26:25 +03:00
ImGui : : CheckboxFlags ( " io.ConfigFlags: NavEnableGamepad [beta] " , ( unsigned int * ) & io . ConfigFlags , ImGuiConfigFlags_NavEnableGamepad ) ;
ImGui : : CheckboxFlags ( " io.ConfigFlags: NavEnableKeyboard [beta] " , ( unsigned int * ) & io . ConfigFlags , ImGuiConfigFlags_NavEnableKeyboard ) ;
2018-05-17 18:47:13 +03:00
ImGui : : CheckboxFlags ( " io.ConfigFlags: NavEnableSetMousePos " , ( unsigned int * ) & io . ConfigFlags , ImGuiConfigFlags_NavEnableSetMousePos ) ;
2018-04-07 05:34:49 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Instruct navigation to move the mouse cursor. See comment for ImGuiConfigFlags_NavEnableSetMousePos. " ) ;
2018-05-17 18:47:13 +03:00
ImGui : : CheckboxFlags ( " io.ConfigFlags: NoMouseCursorChange " , ( unsigned int * ) & io . ConfigFlags , ImGuiConfigFlags_NoMouseCursorChange ) ;
2018-04-07 05:34:49 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Instruct back-end to not alter mouse cursor shape and visibility. " ) ;
2017-08-08 19:11:10 +03:00
2018-02-07 00:24:05 +03:00
if ( ImGui : : TreeNode ( " Keyboard, Mouse & Navigation State " ) )
2017-08-08 19:11:10 +03:00
{
2017-12-23 23:05:41 +03:00
if ( ImGui : : IsMousePosValid ( ) )
ImGui : : Text ( " Mouse pos: (%g, %g) " , io . MousePos . x , io . MousePos . y ) ;
else
ImGui : : Text ( " Mouse pos: <INVALID> " ) ;
2018-04-26 02:52:26 +03:00
ImGui : : Text ( " Mouse delta: (%g, %g) " , io . MouseDelta . x , io . MouseDelta . y ) ;
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Mouse down: " ) ; for ( int i = 0 ; i < IM_ARRAYSIZE ( io . MouseDown ) ; i + + ) if ( io . MouseDownDuration [ i ] > = 0.0f ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " b%d (%.02f secs) " , i , io . MouseDownDuration [ i ] ) ; }
ImGui : : Text ( " Mouse clicked: " ) ; for ( int i = 0 ; i < IM_ARRAYSIZE ( io . MouseDown ) ; i + + ) if ( ImGui : : IsMouseClicked ( i ) ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " b%d " , i ) ; }
ImGui : : Text ( " Mouse dbl-clicked: " ) ; for ( int i = 0 ; i < IM_ARRAYSIZE ( io . MouseDown ) ; i + + ) if ( ImGui : : IsMouseDoubleClicked ( i ) ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " b%d " , i ) ; }
ImGui : : Text ( " Mouse released: " ) ; for ( int i = 0 ; i < IM_ARRAYSIZE ( io . MouseDown ) ; i + + ) if ( ImGui : : IsMouseReleased ( i ) ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " b%d " , i ) ; }
ImGui : : Text ( " Mouse wheel: %.1f " , io . MouseWheel ) ;
ImGui : : Text ( " Keys down: " ) ; for ( int i = 0 ; i < IM_ARRAYSIZE ( io . KeysDown ) ; i + + ) if ( io . KeysDownDuration [ i ] > = 0.0f ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " %d (%.02f secs) " , i , io . KeysDownDuration [ i ] ) ; }
ImGui : : Text ( " Keys pressed: " ) ; for ( int i = 0 ; i < IM_ARRAYSIZE ( io . KeysDown ) ; i + + ) if ( ImGui : : IsKeyPressed ( i ) ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " %d " , i ) ; }
ImGui : : Text ( " Keys release: " ) ; for ( int i = 0 ; i < IM_ARRAYSIZE ( io . KeysDown ) ; i + + ) if ( ImGui : : IsKeyReleased ( i ) ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " %d " , i ) ; }
ImGui : : Text ( " Keys mods: %s%s%s%s " , io . KeyCtrl ? " CTRL " : " " , io . KeyShift ? " SHIFT " : " " , io . KeyAlt ? " ALT " : " " , io . KeySuper ? " SUPER " : " " ) ;
2018-02-07 00:24:05 +03:00
ImGui : : Text ( " NavInputs down: " ) ; for ( int i = 0 ; i < IM_ARRAYSIZE ( io . NavInputs ) ; i + + ) if ( io . NavInputs [ i ] > 0.0f ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " [%d] %.2f " , i , io . NavInputs [ i ] ) ; }
ImGui : : Text ( " NavInputs pressed: " ) ; for ( int i = 0 ; i < IM_ARRAYSIZE ( io . NavInputs ) ; i + + ) if ( io . NavInputsDownDuration [ i ] = = 0.0f ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " [%d] " , i ) ; }
ImGui : : Text ( " NavInputs duration: " ) ; for ( int i = 0 ; i < IM_ARRAYSIZE ( io . NavInputs ) ; i + + ) if ( io . NavInputsDownDuration [ i ] > = 0.0f ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " [%d] %.2f " , i , io . NavInputsDownDuration [ i ] ) ; }
2017-08-08 19:11:10 +03:00
ImGui : : Button ( " Hovering me sets the \n keyboard capture flag " ) ;
if ( ImGui : : IsItemHovered ( ) )
ImGui : : CaptureKeyboardFromApp ( true ) ;
ImGui : : SameLine ( ) ;
ImGui : : Button ( " Holding me clears the \n the keyboard capture flag " ) ;
if ( ImGui : : IsItemActive ( ) )
ImGui : : CaptureKeyboardFromApp ( false ) ;
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
if ( ImGui : : TreeNode ( " Tabbing " ) )
{
ImGui : : Text ( " Use TAB/SHIFT+TAB to cycle through keyboard editable fields. " ) ;
static char buf [ 32 ] = " dummy " ;
ImGui : : InputText ( " 1 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : InputText ( " 2 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : InputText ( " 3 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : PushAllowKeyboardFocus ( false ) ;
ImGui : : InputText ( " 4 (tab skip) " , buf , IM_ARRAYSIZE ( buf ) ) ;
//ImGui::SameLine(); ShowHelperMarker("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets.");
ImGui : : PopAllowKeyboardFocus ( ) ;
ImGui : : InputText ( " 5 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Focus from code " ) )
{
bool focus_1 = ImGui : : Button ( " Focus on 1 " ) ; ImGui : : SameLine ( ) ;
bool focus_2 = ImGui : : Button ( " Focus on 2 " ) ; ImGui : : SameLine ( ) ;
bool focus_3 = ImGui : : Button ( " Focus on 3 " ) ;
int has_focus = 0 ;
static char buf [ 128 ] = " click on a button to set focus " ;
2015-08-26 06:44:36 +03:00
2015-08-08 19:56:09 +03:00
if ( focus_1 ) ImGui : : SetKeyboardFocusHere ( ) ;
ImGui : : InputText ( " 1 " , buf , IM_ARRAYSIZE ( buf ) ) ;
if ( ImGui : : IsItemActive ( ) ) has_focus = 1 ;
2015-08-26 06:44:36 +03:00
2015-08-08 19:56:09 +03:00
if ( focus_2 ) ImGui : : SetKeyboardFocusHere ( ) ;
ImGui : : InputText ( " 2 " , buf , IM_ARRAYSIZE ( buf ) ) ;
if ( ImGui : : IsItemActive ( ) ) has_focus = 2 ;
ImGui : : PushAllowKeyboardFocus ( false ) ;
if ( focus_3 ) ImGui : : SetKeyboardFocusHere ( ) ;
ImGui : : InputText ( " 3 (tab skip) " , buf , IM_ARRAYSIZE ( buf ) ) ;
if ( ImGui : : IsItemActive ( ) ) has_focus = 3 ;
ImGui : : PopAllowKeyboardFocus ( ) ;
2018-01-13 05:29:32 +03:00
2015-08-08 19:56:09 +03:00
if ( has_focus )
ImGui : : Text ( " Item with focus: %d " , has_focus ) ;
2015-08-26 06:44:36 +03:00
else
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " Item with focus: <none> " ) ;
2018-02-07 00:24:05 +03:00
// Use >= 0 parameter to SetKeyboardFocusHere() to focus an upcoming item
static float f3 [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
int focus_ahead = - 1 ;
if ( ImGui : : Button ( " Focus on X " ) ) focus_ahead = 0 ; ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Focus on Y " ) ) focus_ahead = 1 ; ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Focus on Z " ) ) focus_ahead = 2 ;
if ( focus_ahead ! = - 1 ) ImGui : : SetKeyboardFocusHere ( focus_ahead ) ;
ImGui : : SliderFloat3 ( " Float3 " , & f3 [ 0 ] , 0.0f , 1.0f ) ;
ImGui : : TextWrapped ( " NB: Cursor & selection are preserved when refocusing last used item in code. " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Dragging " ) )
{
2016-10-18 05:15:33 +03:00
ImGui : : TextWrapped ( " You can use ImGui::GetMouseDragDelta(0) to query for the dragged amount on any widget. " ) ;
2017-12-08 06:00:53 +03:00
for ( int button = 0 ; button < 3 ; button + + )
2018-05-17 18:47:13 +03:00
ImGui : : Text ( " IsMouseDragging(%d): \n w/ default threshold: %d, \n w/ zero threshold: %d \n w/ large threshold: %d " ,
2017-12-12 19:54:29 +03:00
button , ImGui : : IsMouseDragging ( button ) , ImGui : : IsMouseDragging ( button , 0.0f ) , ImGui : : IsMouseDragging ( button , 20.0f ) ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Button ( " Drag Me " ) ;
if ( ImGui : : IsItemActive ( ) )
{
// Draw a line between the button and the mouse cursor
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
draw_list - > PushClipRectFullScreen ( ) ;
2017-12-29 22:21:43 +03:00
draw_list - > AddLine ( io . MouseClickedPos [ 0 ] , io . MousePos , ImGui : : GetColorU32 ( ImGuiCol_Button ) , 4.0f ) ;
2015-08-08 19:56:09 +03:00
draw_list - > PopClipRect ( ) ;
2017-12-12 19:54:29 +03:00
// Drag operations gets "unlocked" when the mouse has moved past a certain threshold (the default threshold is stored in io.MouseDragThreshold)
// You can request a lower or higher threshold using the second parameter of IsMouseDragging() and GetMouseDragDelta()
2015-08-08 19:56:09 +03:00
ImVec2 value_raw = ImGui : : GetMouseDragDelta ( 0 , 0.0f ) ;
ImVec2 value_with_lock_threshold = ImGui : : GetMouseDragDelta ( 0 ) ;
2017-08-08 19:11:10 +03:00
ImVec2 mouse_delta = io . MouseDelta ;
2015-09-12 08:40:55 +03:00
ImGui : : SameLine ( ) ; ImGui : : Text ( " Raw (%.1f, %.1f), WithLockThresold (%.1f, %.1f), MouseDelta (%.1f, %.1f) " , value_raw . x , value_raw . y , value_with_lock_threshold . x , value_with_lock_threshold . y , mouse_delta . x , mouse_delta . y ) ;
2015-08-08 19:56:09 +03:00
}
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Mouse cursors " ) )
{
2018-06-29 18:59:21 +03:00
const char * mouse_cursors_names [ ] = { " Arrow " , " TextInput " , " Move " , " ResizeNS " , " ResizeEW " , " ResizeNESW " , " ResizeNWSE " , " Hand " } ;
2018-03-03 22:21:53 +03:00
IM_ASSERT ( IM_ARRAYSIZE ( mouse_cursors_names ) = = ImGuiMouseCursor_COUNT ) ;
2017-12-08 06:00:53 +03:00
ImGui : : Text ( " Current mouse cursor = %d: %s " , ImGui : : GetMouseCursor ( ) , mouse_cursors_names [ ImGui : : GetMouseCursor ( ) ] ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " Hover to see mouse cursors: " ) ;
2017-08-08 19:11:10 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, otherwise your backend needs to handle it. " ) ;
2018-03-03 22:21:53 +03:00
for ( int i = 0 ; i < ImGuiMouseCursor_COUNT ; i + + )
2015-08-08 19:56:09 +03:00
{
char label [ 32 ] ;
2017-12-08 06:00:53 +03:00
sprintf ( label , " Mouse cursor %d: %s " , i , mouse_cursors_names [ i ] ) ;
2015-08-26 06:44:36 +03:00
ImGui : : Bullet ( ) ; ImGui : : Selectable ( label , false ) ;
2018-02-07 00:24:05 +03:00
if ( ImGui : : IsItemHovered ( ) | | ImGui : : IsItemFocused ( ) )
2015-08-08 19:56:09 +03:00
ImGui : : SetMouseCursor ( i ) ;
}
ImGui : : TreePop ( ) ;
}
}
2018-07-12 19:05:12 +03:00
// End of ShowDemoWindow()
2015-08-08 19:56:09 +03:00
ImGui : : End ( ) ;
}
2017-12-25 00:46:50 +03:00
// Demo helper function to select among default colors. See ShowStyleEditor() for more advanced options.
// Here we use the simplified Combo() api that packs items into a single literal string. Useful for quick combo boxes where the choices are known locally.
2017-12-14 06:13:37 +03:00
bool ImGui : : ShowStyleSelector ( const char * label )
{
2018-01-31 06:03:53 +03:00
static int style_idx = - 1 ;
2017-12-14 06:13:37 +03:00
if ( ImGui : : Combo ( label , & style_idx , " Classic \0 Dark \0 Light \0 " ) )
{
switch ( style_idx )
{
case 0 : ImGui : : StyleColorsClassic ( ) ; break ;
case 1 : ImGui : : StyleColorsDark ( ) ; break ;
case 2 : ImGui : : StyleColorsLight ( ) ; break ;
}
return true ;
}
return false ;
}
2017-12-25 00:46:50 +03:00
// Demo helper function to select among loaded fonts.
// Here we use the regular BeginCombo()/EndCombo() api which is more the more flexible one.
2017-12-14 06:13:37 +03:00
void ImGui : : ShowFontSelector ( const char * label )
{
ImGuiIO & io = ImGui : : GetIO ( ) ;
ImFont * font_current = ImGui : : GetFont ( ) ;
if ( ImGui : : BeginCombo ( label , font_current - > GetDebugName ( ) ) )
{
for ( int n = 0 ; n < io . Fonts - > Fonts . Size ; n + + )
if ( ImGui : : Selectable ( io . Fonts - > Fonts [ n ] - > GetDebugName ( ) , io . Fonts - > Fonts [ n ] = = font_current ) )
io . FontDefault = io . Fonts - > Fonts [ n ] ;
ImGui : : EndCombo ( ) ;
}
2018-05-17 18:47:13 +03:00
ImGui : : SameLine ( ) ;
2017-12-14 06:13:37 +03:00
ShowHelpMarker (
" - Load additional fonts with io.Fonts->AddFontFromFileTTF(). \n "
" - The font atlas is built when calling io.Fonts->GetTexDataAsXXXX() or io.Fonts->Build(). \n "
2018-02-02 08:03:15 +03:00
" - Read FAQ and documentation in misc/fonts/ for more details. \n "
2017-12-14 06:13:37 +03:00
" - If you need to add/remove fonts at runtime (e.g. for DPI change), do it before calling NewFrame(). " ) ;
}
2015-08-08 19:56:09 +03:00
void ImGui : : ShowStyleEditor ( ImGuiStyle * ref )
{
2017-11-20 19:29:10 +03:00
// You can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it compares to an internally stored reference)
2015-08-08 19:56:09 +03:00
ImGuiStyle & style = ImGui : : GetStyle ( ) ;
2017-11-20 19:29:10 +03:00
static ImGuiStyle ref_saved_style ;
2015-08-08 19:56:09 +03:00
2017-11-20 19:29:10 +03:00
// Default to using internal storage as reference
static bool init = true ;
if ( init & & ref = = NULL )
ref_saved_style = style ;
init = false ;
if ( ref = = NULL )
ref = & ref_saved_style ;
2016-05-13 18:03:36 +03:00
2017-11-20 19:29:10 +03:00
ImGui : : PushItemWidth ( ImGui : : GetWindowWidth ( ) * 0.50f ) ;
2017-12-14 06:13:37 +03:00
if ( ImGui : : ShowStyleSelector ( " Colors##Selector " ) )
2017-11-20 19:29:10 +03:00
ref_saved_style = style ;
2017-12-14 06:13:37 +03:00
ImGui : : ShowFontSelector ( " Fonts##Selector " ) ;
2015-08-08 19:56:09 +03:00
2017-11-20 19:29:10 +03:00
// Simplified Settings
2018-05-17 18:47:13 +03:00
if ( ImGui : : SliderFloat ( " FrameRounding " , & style . FrameRounding , 0.0f , 12.0f , " %.0f " ) )
2017-11-20 19:29:10 +03:00
style . GrabRounding = style . FrameRounding ; // Make GrabRounding always the same value as FrameRounding
{ bool window_border = ( style . WindowBorderSize > 0.0f ) ; if ( ImGui : : Checkbox ( " WindowBorder " , & window_border ) ) style . WindowBorderSize = window_border ? 1.0f : 0.0f ; }
ImGui : : SameLine ( ) ;
{ bool frame_border = ( style . FrameBorderSize > 0.0f ) ; if ( ImGui : : Checkbox ( " FrameBorder " , & frame_border ) ) style . FrameBorderSize = frame_border ? 1.0f : 0.0f ; }
ImGui : : SameLine ( ) ;
{ bool popup_border = ( style . PopupBorderSize > 0.0f ) ; if ( ImGui : : Checkbox ( " PopupBorder " , & popup_border ) ) style . PopupBorderSize = popup_border ? 1.0f : 0.0f ; }
// Save/Revert button
if ( ImGui : : Button ( " Save Ref " ) )
* ref = ref_saved_style = style ;
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Revert Ref " ) )
style = * ref ;
ImGui : : SameLine ( ) ;
ShowHelpMarker ( " Save/Revert in local non-persistent storage. Default Colors definition are not affected. Use \" Export Colors \" below to save them somewhere. " ) ;
2015-08-08 19:56:09 +03:00
if ( ImGui : : TreeNode ( " Rendering " ) )
{
2017-08-15 08:16:52 +03:00
ImGui : : Checkbox ( " Anti-aliased lines " , & style . AntiAliasedLines ) ; ImGui : : SameLine ( ) ; ShowHelpMarker ( " When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well. " ) ;
2017-12-23 23:05:41 +03:00
ImGui : : Checkbox ( " Anti-aliased fill " , & style . AntiAliasedFill ) ;
2015-08-30 03:00:23 +03:00
ImGui : : PushItemWidth ( 100 ) ;
ImGui : : DragFloat ( " Curve Tessellation Tolerance " , & style . CurveTessellationTol , 0.02f , 0.10f , FLT_MAX , NULL , 2.0f ) ;
if ( style . CurveTessellationTol < 0.0f ) style . CurveTessellationTol = 0.10f ;
2015-12-15 09:56:16 +03:00
ImGui : : DragFloat ( " Global Alpha " , & style . Alpha , 0.005f , 0.20f , 1.0f , " %.2f " ) ; // Not exposing zero here so user doesn't "lose" the UI (zero alpha clips all widgets). But application code could have a toggle to switch between zero and non-zero.
2015-08-30 03:00:23 +03:00
ImGui : : PopItemWidth ( ) ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
2016-09-26 05:41:51 +03:00
if ( ImGui : : TreeNode ( " Settings " ) )
2015-08-08 19:56:09 +03:00
{
ImGui : : SliderFloat2 ( " WindowPadding " , ( float * ) & style . WindowPadding , 0.0f , 20.0f , " %.0f " ) ;
2017-11-20 19:29:10 +03:00
ImGui : : SliderFloat ( " PopupRounding " , & style . PopupRounding , 0.0f , 16.0f , " %.0f " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : SliderFloat2 ( " FramePadding " , ( float * ) & style . FramePadding , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat2 ( " ItemSpacing " , ( float * ) & style . ItemSpacing , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat2 ( " ItemInnerSpacing " , ( float * ) & style . ItemInnerSpacing , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat2 ( " TouchExtraPadding " , ( float * ) & style . TouchExtraPadding , 0.0f , 10.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " IndentSpacing " , & style . IndentSpacing , 0.0f , 30.0f , " %.0f " ) ;
2015-10-03 03:57:00 +03:00
ImGui : : SliderFloat ( " ScrollbarSize " , & style . ScrollbarSize , 1.0f , 20.0f , " %.0f " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : SliderFloat ( " GrabMinSize " , & style . GrabMinSize , 1.0f , 20.0f , " %.0f " ) ;
2017-11-20 19:29:10 +03:00
ImGui : : Text ( " BorderSize " ) ;
ImGui : : SliderFloat ( " WindowBorderSize " , & style . WindowBorderSize , 0.0f , 1.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " ChildBorderSize " , & style . ChildBorderSize , 0.0f , 1.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " PopupBorderSize " , & style . PopupBorderSize , 0.0f , 1.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " FrameBorderSize " , & style . FrameBorderSize , 0.0f , 1.0f , " %.0f " ) ;
ImGui : : Text ( " Rounding " ) ;
ImGui : : SliderFloat ( " WindowRounding " , & style . WindowRounding , 0.0f , 14.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " ChildRounding " , & style . ChildRounding , 0.0f , 16.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " FrameRounding " , & style . FrameRounding , 0.0f , 12.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " ScrollbarRounding " , & style . ScrollbarRounding , 0.0f , 12.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " GrabRounding " , & style . GrabRounding , 0.0f , 12.0f , " %.0f " ) ;
2016-09-26 05:41:51 +03:00
ImGui : : Text ( " Alignment " ) ;
ImGui : : SliderFloat2 ( " WindowTitleAlign " , ( float * ) & style . WindowTitleAlign , 0.0f , 1.0f , " %.2f " ) ;
ImGui : : SliderFloat2 ( " ButtonTextAlign " , ( float * ) & style . ButtonTextAlign , 0.0f , 1.0f , " %.2f " ) ; ImGui : : SameLine ( ) ; ShowHelpMarker ( " Alignment applies when a button is larger than its text content. " ) ;
2018-04-18 18:58:03 +03:00
ImGui : : Text ( " Safe Area Padding " ) ; ImGui : : SameLine ( ) ; ShowHelpMarker ( " Adjust if you cannot see the edges of your screen (e.g. on a TV where scaling has not been configured). " ) ;
ImGui : : SliderFloat2 ( " DisplaySafeAreaPadding " , ( float * ) & style . DisplaySafeAreaPadding , 0.0f , 30.0f , " %.0f " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Colors " ) )
{
static int output_dest = 0 ;
2017-11-20 19:29:10 +03:00
static bool output_only_modified = true ;
if ( ImGui : : Button ( " Export Unsaved " ) )
2015-08-08 19:56:09 +03:00
{
if ( output_dest = = 0 )
ImGui : : LogToClipboard ( ) ;
else
ImGui : : LogToTTY ( ) ;
2017-09-18 19:21:06 +03:00
ImGui : : LogText ( " ImVec4* colors = ImGui::GetStyle().Colors; " IM_NEWLINE ) ;
2015-08-08 19:56:09 +03:00
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
{
const ImVec4 & col = style . Colors [ i ] ;
2017-08-20 20:25:00 +03:00
const char * name = ImGui : : GetStyleColorName ( i ) ;
2017-11-20 19:29:10 +03:00
if ( ! output_only_modified | | memcmp ( & col , & ref - > Colors [ i ] , sizeof ( ImVec4 ) ) ! = 0 )
2017-09-18 19:21:06 +03:00
ImGui : : LogText ( " colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff); " IM_NEWLINE , name , 23 - ( int ) strlen ( name ) , " " , col . x , col . y , col . z , col . w ) ;
2015-08-08 19:56:09 +03:00
}
ImGui : : LogFinish ( ) ;
}
2016-08-23 19:06:04 +03:00
ImGui : : SameLine ( ) ; ImGui : : PushItemWidth ( 120 ) ; ImGui : : Combo ( " ##output_type " , & output_dest , " To Clipboard \0 To TTY \0 " ) ; ImGui : : PopItemWidth ( ) ;
2017-11-20 19:29:10 +03:00
ImGui : : SameLine ( ) ; ImGui : : Checkbox ( " Only Modified Colors " , & output_only_modified ) ;
2015-08-08 19:56:09 +03:00
2017-08-08 19:11:10 +03:00
ImGui : : Text ( " Tip: Left-click on colored square to open color picker, \n Right-click to open edit options menu. " ) ;
2015-08-08 19:56:09 +03:00
static ImGuiTextFilter filter ;
filter . Draw ( " Filter colors " , 200 ) ;
2017-08-08 19:11:10 +03:00
static ImGuiColorEditFlags alpha_flags = 0 ;
2018-05-17 18:47:13 +03:00
ImGui : : RadioButton ( " Opaque " , & alpha_flags , 0 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " Alpha " , & alpha_flags , ImGuiColorEditFlags_AlphaPreview ) ; ImGui : : SameLine ( ) ;
2017-08-08 19:11:10 +03:00
ImGui : : RadioButton ( " Both " , & alpha_flags , ImGuiColorEditFlags_AlphaPreviewHalf ) ;
2018-02-07 00:24:05 +03:00
ImGui : : BeginChild ( " #colors " , ImVec2 ( 0 , 300 ) , true , ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar | ImGuiWindowFlags_NavFlattened ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PushItemWidth ( - 160 ) ;
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
{
2017-08-20 20:25:00 +03:00
const char * name = ImGui : : GetStyleColorName ( i ) ;
2015-08-08 19:56:09 +03:00
if ( ! filter . PassFilter ( name ) )
continue ;
ImGui : : PushID ( i ) ;
2017-11-20 19:29:10 +03:00
ImGui : : ColorEdit4 ( " ##color " , ( float * ) & style . Colors [ i ] , ImGuiColorEditFlags_AlphaBar | alpha_flags ) ;
if ( memcmp ( & style . Colors [ i ] , & ref - > Colors [ i ] , sizeof ( ImVec4 ) ) ! = 0 )
2015-08-08 19:56:09 +03:00
{
2017-11-20 19:29:10 +03:00
// Tips: in a real user application, you may want to merge and use an icon font into the main font, so instead of "Save"/"Revert" you'd use icons.
2018-02-02 08:03:15 +03:00
// Read the FAQ and misc/fonts/README.txt about using icon fonts. It's really easy and super convenient!
2017-11-20 19:29:10 +03:00
ImGui : : SameLine ( 0.0f , style . ItemInnerSpacing . x ) ; if ( ImGui : : Button ( " Save " ) ) ref - > Colors [ i ] = style . Colors [ i ] ;
ImGui : : SameLine ( 0.0f , style . ItemInnerSpacing . x ) ; if ( ImGui : : Button ( " Revert " ) ) style . Colors [ i ] = ref - > Colors [ i ] ;
2015-08-08 19:56:09 +03:00
}
2017-11-20 19:29:10 +03:00
ImGui : : SameLine ( 0.0f , style . ItemInnerSpacing . x ) ;
ImGui : : TextUnformatted ( name ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PopID ( ) ;
}
ImGui : : PopItemWidth ( ) ;
ImGui : : EndChild ( ) ;
ImGui : : TreePop ( ) ;
}
2017-08-18 08:04:22 +03:00
bool fonts_opened = ImGui : : TreeNode ( " Fonts " , " Fonts (%d) " , ImGui : : GetIO ( ) . Fonts - > Fonts . Size ) ;
if ( fonts_opened )
2016-05-04 05:29:37 +03:00
{
ImFontAtlas * atlas = ImGui : : GetIO ( ) . Fonts ;
if ( ImGui : : TreeNode ( " Atlas texture " , " Atlas texture (%dx%d pixels) " , atlas - > TexWidth , atlas - > TexHeight ) )
{
ImGui : : Image ( atlas - > TexID , ImVec2 ( ( float ) atlas - > TexWidth , ( float ) atlas - > TexHeight ) , ImVec2 ( 0 , 0 ) , ImVec2 ( 1 , 1 ) , ImColor ( 255 , 255 , 255 , 255 ) , ImColor ( 255 , 255 , 255 , 128 ) ) ;
ImGui : : TreePop ( ) ;
}
ImGui : : PushItemWidth ( 100 ) ;
for ( int i = 0 ; i < atlas - > Fonts . Size ; i + + )
{
ImFont * font = atlas - > Fonts [ i ] ;
2017-10-23 03:53:32 +03:00
ImGui : : PushID ( font ) ;
2017-08-18 08:04:22 +03:00
bool font_details_opened = ImGui : : TreeNode ( font , " Font %d: \' %s \' , %.2f px, %d glyphs " , i , font - > ConfigData ? font - > ConfigData [ 0 ] . Name : " " , font - > FontSize , font - > Glyphs . Size ) ;
2016-11-07 08:09:19 +03:00
ImGui : : SameLine ( ) ; if ( ImGui : : SmallButton ( " Set as default " ) ) ImGui : : GetIO ( ) . FontDefault = font ;
2017-08-18 08:04:22 +03:00
if ( font_details_opened )
2016-05-04 05:29:37 +03:00
{
2017-08-18 08:04:22 +03:00
ImGui : : PushFont ( font ) ;
ImGui : : Text ( " The quick brown fox jumps over the lazy dog " ) ;
ImGui : : PopFont ( ) ;
2016-09-26 05:41:51 +03:00
ImGui : : DragFloat ( " Font scale " , & font - > Scale , 0.005f , 0.3f , 2.0f , " %.1f " ) ; // Scale only this font
2018-02-14 20:50:55 +03:00
ImGui : : InputFloat ( " Font offset " , & font - > DisplayOffset . y , 1 , 1 , 0 ) ;
2016-09-26 05:41:51 +03:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Note than the default embedded font is NOT meant to be scaled. \n \n Font are currently rendered into bitmaps at a given size at the time of building the atlas. You may oversample them to get some flexibility with scaling. You can also render at multiple sizes and select which one to use at runtime. \n \n (Glimmer of hope: the atlas system should hopefully be rewritten in the future to make scaling more natural and automatic.) " ) ;
2016-05-04 05:29:37 +03:00
ImGui : : Text ( " Ascent: %f, Descent: %f, Height: %f " , font - > Ascent , font - > Descent , font - > Ascent - font - > Descent ) ;
ImGui : : Text ( " Fallback character: '%c' (%d) " , font - > FallbackChar , font - > FallbackChar ) ;
2017-05-15 22:52:34 +03:00
ImGui : : Text ( " Texture surface: %d pixels (approx) ~ %dx%d " , font - > MetricsTotalSurface , ( int ) sqrtf ( ( float ) font - > MetricsTotalSurface ) , ( int ) sqrtf ( ( float ) font - > MetricsTotalSurface ) ) ;
2016-05-04 05:29:37 +03:00
for ( int config_i = 0 ; config_i < font - > ConfigDataCount ; config_i + + )
2018-03-01 07:06:17 +03:00
if ( ImFontConfig * cfg = & font - > ConfigData [ config_i ] )
ImGui : : BulletText ( " Input %d: \' %s \' , Oversample: (%d,%d), PixelSnapH: %d " , config_i , cfg - > Name , cfg - > OversampleH , cfg - > OversampleV , cfg - > PixelSnapH ) ;
2016-09-26 05:41:51 +03:00
if ( ImGui : : TreeNode ( " Glyphs " , " Glyphs (%d) " , font - > Glyphs . Size ) )
{
// Display all glyphs of the fonts in separate pages of 256 characters
for ( int base = 0 ; base < 0x10000 ; base + = 256 )
{
int count = 0 ;
for ( int n = 0 ; n < 256 ; n + + )
2018-03-10 21:40:49 +03:00
count + = font - > FindGlyphNoFallback ( ( ImWchar ) ( base + n ) ) ? 1 : 0 ;
2016-09-26 05:41:51 +03:00
if ( count > 0 & & ImGui : : TreeNode ( ( void * ) ( intptr_t ) base , " U+%04X..U+%04X (%d %s) " , base , base + 255 , count , count > 1 ? " glyphs " : " glyph " ) )
{
2018-03-13 05:30:50 +03:00
float cell_size = font - > FontSize * 1 ;
2016-09-26 05:41:51 +03:00
float cell_spacing = style . ItemSpacing . y ;
ImVec2 base_pos = ImGui : : GetCursorScreenPos ( ) ;
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
for ( int n = 0 ; n < 256 ; n + + )
{
2018-03-13 05:30:50 +03:00
ImVec2 cell_p1 ( base_pos . x + ( n % 16 ) * ( cell_size + cell_spacing ) , base_pos . y + ( n / 16 ) * ( cell_size + cell_spacing ) ) ;
ImVec2 cell_p2 ( cell_p1 . x + cell_size , cell_p1 . y + cell_size ) ;
2018-03-10 21:40:49 +03:00
const ImFontGlyph * glyph = font - > FindGlyphNoFallback ( ( ImWchar ) ( base + n ) ) ;
2016-09-26 05:41:51 +03:00
draw_list - > AddRect ( cell_p1 , cell_p2 , glyph ? IM_COL32 ( 255 , 255 , 255 , 100 ) : IM_COL32 ( 255 , 255 , 255 , 50 ) ) ;
2018-05-08 18:23:45 +03:00
if ( glyph )
font - > RenderChar ( draw_list , cell_size , cell_p1 , ImGui : : GetColorU32 ( ImGuiCol_Text ) , ( ImWchar ) ( base + n ) ) ; // We use ImFont::RenderChar as a shortcut because we don't have UTF-8 conversion functions available to generate a string.
2016-09-26 05:41:51 +03:00
if ( glyph & & ImGui : : IsMouseHoveringRect ( cell_p1 , cell_p2 ) )
{
ImGui : : BeginTooltip ( ) ;
ImGui : : Text ( " Codepoint: U+%04X " , base + n ) ;
ImGui : : Separator ( ) ;
2017-09-28 05:42:53 +03:00
ImGui : : Text ( " AdvanceX: %.1f " , glyph - > AdvanceX ) ;
2016-09-26 05:41:51 +03:00
ImGui : : Text ( " Pos: (%.2f,%.2f)->(%.2f,%.2f) " , glyph - > X0 , glyph - > Y0 , glyph - > X1 , glyph - > Y1 ) ;
ImGui : : Text ( " UV: (%.3f,%.3f)->(%.3f,%.3f) " , glyph - > U0 , glyph - > V0 , glyph - > U1 , glyph - > V1 ) ;
ImGui : : EndTooltip ( ) ;
}
}
2018-03-13 05:30:50 +03:00
ImGui : : Dummy ( ImVec2 ( ( cell_size + cell_spacing ) * 16 , ( cell_size + cell_spacing ) * 16 ) ) ;
2016-09-26 05:41:51 +03:00
ImGui : : TreePop ( ) ;
}
}
ImGui : : TreePop ( ) ;
}
2016-05-04 05:29:37 +03:00
ImGui : : TreePop ( ) ;
}
2017-10-23 03:53:32 +03:00
ImGui : : PopID ( ) ;
2016-05-04 05:29:37 +03:00
}
static float window_scale = 1.0f ;
ImGui : : DragFloat ( " this window scale " , & window_scale , 0.005f , 0.3f , 2.0f , " %.1f " ) ; // scale only this window
ImGui : : DragFloat ( " global scale " , & ImGui : : GetIO ( ) . FontGlobalScale , 0.005f , 0.3f , 2.0f , " %.1f " ) ; // scale everything
ImGui : : PopItemWidth ( ) ;
ImGui : : SetWindowFontScale ( window_scale ) ;
ImGui : : TreePop ( ) ;
}
2015-08-08 19:56:09 +03:00
ImGui : : PopItemWidth ( ) ;
}
2018-07-12 19:05:12 +03:00
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: MAIN MENU BAR
//-----------------------------------------------------------------------------
2016-11-11 08:10:26 +03:00
// Demonstrate creating a fullscreen menu bar and populating it.
2015-08-08 19:56:09 +03:00
static void ShowExampleAppMainMenuBar ( )
{
if ( ImGui : : BeginMainMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " File " ) )
{
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Edit " ) )
{
if ( ImGui : : MenuItem ( " Undo " , " CTRL+Z " ) ) { }
if ( ImGui : : MenuItem ( " Redo " , " CTRL+Y " , false , false ) ) { } // Disabled item
ImGui : : Separator ( ) ;
if ( ImGui : : MenuItem ( " Cut " , " CTRL+X " ) ) { }
if ( ImGui : : MenuItem ( " Copy " , " CTRL+C " ) ) { }
if ( ImGui : : MenuItem ( " Paste " , " CTRL+V " ) ) { }
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMainMenuBar ( ) ;
}
}
static void ShowExampleMenuFile ( )
{
ImGui : : MenuItem ( " (dummy menu) " , NULL , false , false ) ;
if ( ImGui : : MenuItem ( " New " ) ) { }
if ( ImGui : : MenuItem ( " Open " , " Ctrl+O " ) ) { }
if ( ImGui : : BeginMenu ( " Open Recent " ) )
{
ImGui : : MenuItem ( " fish_hat.c " ) ;
ImGui : : MenuItem ( " fish_hat.inl " ) ;
ImGui : : MenuItem ( " fish_hat.h " ) ;
if ( ImGui : : BeginMenu ( " More.. " ) )
{
ImGui : : MenuItem ( " Hello " ) ;
ImGui : : MenuItem ( " Sailor " ) ;
if ( ImGui : : BeginMenu ( " Recurse.. " ) )
{
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : MenuItem ( " Save " , " Ctrl+S " ) ) { }
if ( ImGui : : MenuItem ( " Save As.. " ) ) { }
ImGui : : Separator ( ) ;
if ( ImGui : : BeginMenu ( " Options " ) )
{
static bool enabled = true ;
ImGui : : MenuItem ( " Enabled " , " " , & enabled ) ;
ImGui : : BeginChild ( " child " , ImVec2 ( 0 , 60 ) , true ) ;
for ( int i = 0 ; i < 10 ; i + + )
ImGui : : Text ( " Scrolling Text %d " , i ) ;
ImGui : : EndChild ( ) ;
static float f = 0.5f ;
static int n = 0 ;
2017-08-08 19:11:10 +03:00
static bool b = true ;
2015-08-08 19:56:09 +03:00
ImGui : : SliderFloat ( " Value " , & f , 0.0f , 1.0f ) ;
ImGui : : InputFloat ( " Input " , & f , 0.1f ) ;
ImGui : : Combo ( " Combo " , & n , " Yes \0 No \0 Maybe \0 \0 " ) ;
2017-08-08 19:11:10 +03:00
ImGui : : Checkbox ( " Check " , & b ) ;
2015-08-08 19:56:09 +03:00
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Colors " ) )
{
2018-02-07 00:24:05 +03:00
float sz = ImGui : : GetTextLineHeight ( ) ;
2015-08-08 19:56:09 +03:00
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
2017-11-20 19:29:10 +03:00
{
const char * name = ImGui : : GetStyleColorName ( ( ImGuiCol ) i ) ;
2018-02-07 00:24:05 +03:00
ImVec2 p = ImGui : : GetCursorScreenPos ( ) ;
ImGui : : GetWindowDrawList ( ) - > AddRectFilled ( p , ImVec2 ( p . x + sz , p . y + sz ) , ImGui : : GetColorU32 ( ( ImGuiCol ) i ) ) ;
ImGui : : Dummy ( ImVec2 ( sz , sz ) ) ;
2017-11-20 19:29:10 +03:00
ImGui : : SameLine ( ) ;
ImGui : : MenuItem ( name ) ;
}
2015-08-08 19:56:09 +03:00
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Disabled " , false ) ) // Disabled
{
IM_ASSERT ( 0 ) ;
}
if ( ImGui : : MenuItem ( " Checked " , NULL , true ) ) { }
if ( ImGui : : MenuItem ( " Quit " , " Alt+F4 " ) ) { }
}
2018-07-12 19:05:12 +03:00
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: CONSOLE
//-----------------------------------------------------------------------------
2015-08-08 19:56:09 +03:00
2016-11-11 08:10:26 +03:00
// Demonstrating creating a simple console window, with scrolling, filtering, completion and history.
2015-08-08 19:56:09 +03:00
// For the console example, here we are using a more C++ like approach of declaring a class to hold the data and the functions.
struct ExampleAppConsole
{
char InputBuf [ 256 ] ;
ImVector < char * > Items ;
bool ScrollToBottom ;
ImVector < char * > History ;
int HistoryPos ; // -1: new line, 0..History.Size-1 browsing history.
ImVector < const char * > Commands ;
ExampleAppConsole ( )
{
ClearLog ( ) ;
2016-01-04 00:20:15 +03:00
memset ( InputBuf , 0 , sizeof ( InputBuf ) ) ;
2015-08-08 19:56:09 +03:00
HistoryPos = - 1 ;
Commands . push_back ( " HELP " ) ;
Commands . push_back ( " HISTORY " ) ;
Commands . push_back ( " CLEAR " ) ;
2018-07-12 19:05:12 +03:00
Commands . push_back ( " CLASSIFY " ) ; // "classify" is only here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
2018-05-11 08:08:24 +03:00
AddLog ( " Welcome to Dear ImGui! " ) ;
2015-08-08 19:56:09 +03:00
}
~ ExampleAppConsole ( )
{
ClearLog ( ) ;
2016-03-09 01:27:49 +03:00
for ( int i = 0 ; i < History . Size ; i + + )
2015-08-26 06:44:36 +03:00
free ( History [ i ] ) ;
2015-08-08 19:56:09 +03:00
}
2016-02-11 05:27:18 +03:00
// Portable helpers
static int Stricmp ( const char * str1 , const char * str2 ) { int d ; while ( ( d = toupper ( * str2 ) - toupper ( * str1 ) ) = = 0 & & * str1 ) { str1 + + ; str2 + + ; } return d ; }
static int Strnicmp ( const char * str1 , const char * str2 , int n ) { int d = 0 ; while ( n > 0 & & ( d = toupper ( * str2 ) - toupper ( * str1 ) ) = = 0 & & * str1 ) { str1 + + ; str2 + + ; n - - ; } return d ; }
2016-03-09 01:27:49 +03:00
static char * Strdup ( const char * str ) { size_t len = strlen ( str ) + 1 ; void * buff = malloc ( len ) ; return ( char * ) memcpy ( buff , ( const void * ) str , len ) ; }
2018-05-11 08:08:24 +03:00
static void Strtrim ( char * str ) { char * str_end = str + strlen ( str ) ; while ( str_end > str & & str_end [ - 1 ] = = ' ' ) str_end - - ; * str_end = 0 ; }
2016-02-11 05:27:18 +03:00
2015-08-08 19:56:09 +03:00
void ClearLog ( )
{
2015-08-26 06:44:36 +03:00
for ( int i = 0 ; i < Items . Size ; i + + )
free ( Items [ i ] ) ;
2015-08-08 19:56:09 +03:00
Items . clear ( ) ;
ScrollToBottom = true ;
}
2017-08-25 19:42:27 +03:00
void AddLog ( const char * fmt , . . . ) IM_FMTARGS ( 2 )
2015-08-08 19:56:09 +03:00
{
2017-10-25 07:33:18 +03:00
// FIXME-OPT
2015-08-08 19:56:09 +03:00
char buf [ 1024 ] ;
va_list args ;
va_start ( args , fmt ) ;
vsnprintf ( buf , IM_ARRAYSIZE ( buf ) , fmt , args ) ;
buf [ IM_ARRAYSIZE ( buf ) - 1 ] = 0 ;
va_end ( args ) ;
2016-02-11 05:27:18 +03:00
Items . push_back ( Strdup ( buf ) ) ;
2015-08-08 19:56:09 +03:00
ScrollToBottom = true ;
}
2016-05-04 05:29:37 +03:00
void Draw ( const char * title , bool * p_open )
2015-08-08 19:56:09 +03:00
{
2017-08-13 04:22:03 +03:00
ImGui : : SetNextWindowSize ( ImVec2 ( 520 , 600 ) , ImGuiCond_FirstUseEver ) ;
2016-05-04 05:29:37 +03:00
if ( ! ImGui : : Begin ( title , p_open ) )
2015-08-08 19:56:09 +03:00
{
ImGui : : End ( ) ;
return ;
}
2017-11-16 04:10:11 +03:00
// As a specific feature guaranteed by the library, after calling Begin() the last Item represent the title bar. So e.g. IsItemHovered() will return true when hovering the title bar.
// Here we create a context menu only available from the title bar.
if ( ImGui : : BeginPopupContextItem ( ) )
{
2018-07-09 17:38:59 +03:00
if ( ImGui : : MenuItem ( " Close Console " ) )
2017-11-16 04:10:11 +03:00
* p_open = false ;
ImGui : : EndPopup ( ) ;
}
2015-08-08 19:56:09 +03:00
ImGui : : TextWrapped ( " This example implements a console with basic coloring, completion and history. A more elaborate implementation may want to store entries along with extra data such as timestamp, emitter, etc. " ) ;
ImGui : : TextWrapped ( " Enter 'HELP' for help, press TAB to use text completion. " ) ;
// TODO: display items starting from the bottom
2015-08-26 06:44:36 +03:00
if ( ImGui : : SmallButton ( " Add Dummy Text " ) ) { AddLog ( " %d some text " , Items . Size ) ; AddLog ( " some more text " ) ; AddLog ( " display very important message here! " ) ; } ImGui : : SameLine ( ) ;
2016-10-21 09:16:18 +03:00
if ( ImGui : : SmallButton ( " Add Dummy Error " ) ) { AddLog ( " [error] something went wrong " ) ; } ImGui : : SameLine ( ) ;
if ( ImGui : : SmallButton ( " Clear " ) ) { ClearLog ( ) ; } ImGui : : SameLine ( ) ;
2017-08-13 04:22:03 +03:00
bool copy_to_clipboard = ImGui : : SmallButton ( " Copy " ) ; ImGui : : SameLine ( ) ;
2016-05-21 19:27:18 +03:00
if ( ImGui : : SmallButton ( " Scroll to bottom " ) ) ScrollToBottom = true ;
2015-08-08 19:56:09 +03:00
//static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
ImGui : : Separator ( ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 0 , 0 ) ) ;
static ImGuiTextFilter filter ;
filter . Draw ( " Filter ( \" incl,-excl \" ) ( \" error \" ) " , 180 ) ;
ImGui : : PopStyleVar ( ) ;
ImGui : : Separator ( ) ;
2017-12-14 06:13:37 +03:00
const float footer_height_to_reserve = ImGui : : GetStyle ( ) . ItemSpacing . y + ImGui : : GetFrameHeightWithSpacing ( ) ; // 1 separator, 1 input text
ImGui : : BeginChild ( " ScrollingRegion " , ImVec2 ( 0 , - footer_height_to_reserve ) , false , ImGuiWindowFlags_HorizontalScrollbar ) ; // Leave room for 1 separator + 1 InputText
2015-08-08 19:56:09 +03:00
if ( ImGui : : BeginPopupContextWindow ( ) )
{
if ( ImGui : : Selectable ( " Clear " ) ) ClearLog ( ) ;
ImGui : : EndPopup ( ) ;
}
2016-05-21 19:27:18 +03:00
// Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
// NB- if you have thousands of entries this approach may be too inefficient and may require user-side clipping to only process visible items.
// You can seek and display only the lines that are visible using the ImGuiListClipper helper, if your elements are evenly spaced and you have cheap random access to the elements.
// To use the clipper we could replace the 'for (int i = 0; i < Items.Size; i++)' loop with:
// ImGuiListClipper clipper(Items.Size);
// while (clipper.Step())
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
2018-05-11 18:26:25 +03:00
// However, note that you can not use this code as is if a filter is active because it breaks the 'cheap random-access' property. We would need random-access on the post-filtered list.
2016-05-21 19:27:18 +03:00
// A typical application wanting coarse clipping and filtering may want to pre-compute an array of indices that passed the filtering test, recomputing this array when user changes the filter,
// and appending newly elements as they are inserted. This is left as a task to the user until we can manage to improve this example code!
// If your items are of variable size you may want to implement code similar to what ImGuiListClipper does. Or split your data into fixed height items to allow random-seeking into your list.
2015-08-08 19:56:09 +03:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 4 , 1 ) ) ; // Tighten spacing
2017-08-13 04:22:03 +03:00
if ( copy_to_clipboard )
ImGui : : LogToClipboard ( ) ;
2017-12-25 21:41:53 +03:00
ImVec4 col_default_text = ImGui : : GetStyleColorVec4 ( ImGuiCol_Text ) ;
2015-08-08 19:56:09 +03:00
for ( int i = 0 ; i < Items . Size ; i + + )
{
const char * item = Items [ i ] ;
if ( ! filter . PassFilter ( item ) )
continue ;
2017-12-25 21:41:53 +03:00
ImVec4 col = col_default_text ;
2016-05-21 19:27:18 +03:00
if ( strstr ( item , " [error] " ) ) col = ImColor ( 1.0f , 0.4f , 0.4f , 1.0f ) ;
else if ( strncmp ( item , " # " , 2 ) = = 0 ) col = ImColor ( 1.0f , 0.78f , 0.58f , 1.0f ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PushStyleColor ( ImGuiCol_Text , col ) ;
ImGui : : TextUnformatted ( item ) ;
ImGui : : PopStyleColor ( ) ;
}
2017-08-13 04:22:03 +03:00
if ( copy_to_clipboard )
ImGui : : LogFinish ( ) ;
2015-08-08 19:56:09 +03:00
if ( ScrollToBottom )
2018-05-11 08:08:24 +03:00
ImGui : : SetScrollHere ( 1.0f ) ;
2015-08-08 19:56:09 +03:00
ScrollToBottom = false ;
ImGui : : PopStyleVar ( ) ;
ImGui : : EndChild ( ) ;
ImGui : : Separator ( ) ;
// Command-line
2018-02-07 00:24:05 +03:00
bool reclaim_focus = false ;
2015-08-08 19:56:09 +03:00
if ( ImGui : : InputText ( " Input " , InputBuf , IM_ARRAYSIZE ( InputBuf ) , ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory , & TextEditCallbackStub , ( void * ) this ) )
{
2018-05-11 08:08:24 +03:00
Strtrim ( InputBuf ) ;
2015-08-08 19:56:09 +03:00
if ( InputBuf [ 0 ] )
ExecCommand ( InputBuf ) ;
strcpy ( InputBuf , " " ) ;
2018-02-07 00:24:05 +03:00
reclaim_focus = true ;
2015-08-08 19:56:09 +03:00
}
2018-02-07 00:24:05 +03:00
// Demonstrate keeping focus on the input box
ImGui : : SetItemDefaultFocus ( ) ;
if ( reclaim_focus )
2015-12-30 05:45:16 +03:00
ImGui : : SetKeyboardFocusHere ( - 1 ) ; // Auto focus previous widget
2015-08-08 19:56:09 +03:00
ImGui : : End ( ) ;
}
void ExecCommand ( const char * command_line )
{
AddLog ( " # %s \n " , command_line ) ;
// Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal.
HistoryPos = - 1 ;
for ( int i = History . Size - 1 ; i > = 0 ; i - - )
if ( Stricmp ( History [ i ] , command_line ) = = 0 )
{
free ( History [ i ] ) ;
History . erase ( History . begin ( ) + i ) ;
break ;
}
2016-02-11 05:27:18 +03:00
History . push_back ( Strdup ( command_line ) ) ;
2015-08-08 19:56:09 +03:00
// Process command
if ( Stricmp ( command_line , " CLEAR " ) = = 0 )
{
ClearLog ( ) ;
}
else if ( Stricmp ( command_line , " HELP " ) = = 0 )
{
AddLog ( " Commands: " ) ;
for ( int i = 0 ; i < Commands . Size ; i + + )
AddLog ( " - %s " , Commands [ i ] ) ;
}
else if ( Stricmp ( command_line , " HISTORY " ) = = 0 )
{
2016-08-07 06:07:03 +03:00
int first = History . Size - 10 ;
for ( int i = first > 0 ? first : 0 ; i < History . Size ; i + + )
2015-08-08 19:56:09 +03:00
AddLog ( " %3d: %s \n " , i , History [ i ] ) ;
}
else
{
AddLog ( " Unknown command: '%s' \n " , command_line ) ;
}
}
static int TextEditCallbackStub ( ImGuiTextEditCallbackData * data ) // In C++11 you are better off using lambdas for this sort of forwarding callbacks
{
ExampleAppConsole * console = ( ExampleAppConsole * ) data - > UserData ;
return console - > TextEditCallback ( data ) ;
}
int TextEditCallback ( ImGuiTextEditCallbackData * data )
{
//AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
switch ( data - > EventFlag )
{
case ImGuiInputTextFlags_CallbackCompletion :
{
// Example of TEXT COMPLETION
// Locate beginning of current word
const char * word_end = data - > Buf + data - > CursorPos ;
const char * word_start = word_end ;
while ( word_start > data - > Buf )
{
const char c = word_start [ - 1 ] ;
if ( c = = ' ' | | c = = ' \t ' | | c = = ' , ' | | c = = ' ; ' )
break ;
word_start - - ;
}
// Build a list of candidates
ImVector < const char * > candidates ;
for ( int i = 0 ; i < Commands . Size ; i + + )
if ( Strnicmp ( Commands [ i ] , word_start , ( int ) ( word_end - word_start ) ) = = 0 )
candidates . push_back ( Commands [ i ] ) ;
if ( candidates . Size = = 0 )
{
// No match
2015-08-13 09:58:39 +03:00
AddLog ( " No match for \" %.*s \" ! \n " , ( int ) ( word_end - word_start ) , word_start ) ;
2015-08-08 19:56:09 +03:00
}
else if ( candidates . Size = = 1 )
{
// Single match. Delete the beginning of the word and replace it entirely so we've got nice casing
data - > DeleteChars ( ( int ) ( word_start - data - > Buf ) , ( int ) ( word_end - word_start ) ) ;
data - > InsertChars ( data - > CursorPos , candidates [ 0 ] ) ;
data - > InsertChars ( data - > CursorPos , " " ) ;
}
else
{
// Multiple matches. Complete as much as we can, so inputing "C" will complete to "CL" and display "CLEAR" and "CLASSIFY"
int match_len = ( int ) ( word_end - word_start ) ;
for ( ; ; )
{
int c = 0 ;
bool all_candidates_matches = true ;
for ( int i = 0 ; i < candidates . Size & & all_candidates_matches ; i + + )
if ( i = = 0 )
c = toupper ( candidates [ i ] [ match_len ] ) ;
2017-01-12 06:47:30 +03:00
else if ( c = = 0 | | c ! = toupper ( candidates [ i ] [ match_len ] ) )
2015-08-08 19:56:09 +03:00
all_candidates_matches = false ;
if ( ! all_candidates_matches )
break ;
match_len + + ;
}
if ( match_len > 0 )
{
data - > DeleteChars ( ( int ) ( word_start - data - > Buf ) , ( int ) ( word_end - word_start ) ) ;
data - > InsertChars ( data - > CursorPos , candidates [ 0 ] , candidates [ 0 ] + match_len ) ;
}
// List matches
AddLog ( " Possible matches: \n " ) ;
for ( int i = 0 ; i < candidates . Size ; i + + )
AddLog ( " - %s \n " , candidates [ i ] ) ;
}
break ;
}
case ImGuiInputTextFlags_CallbackHistory :
{
// Example of HISTORY
const int prev_history_pos = HistoryPos ;
if ( data - > EventKey = = ImGuiKey_UpArrow )
{
if ( HistoryPos = = - 1 )
HistoryPos = History . Size - 1 ;
else if ( HistoryPos > 0 )
HistoryPos - - ;
}
else if ( data - > EventKey = = ImGuiKey_DownArrow )
{
if ( HistoryPos ! = - 1 )
if ( + + HistoryPos > = History . Size )
HistoryPos = - 1 ;
}
// A better implementation would preserve the data on the current input line along with cursor position.
if ( prev_history_pos ! = HistoryPos )
{
2016-05-05 06:10:06 +03:00
data - > CursorPos = data - > SelectionStart = data - > SelectionEnd = data - > BufTextLen = ( int ) snprintf ( data - > Buf , ( size_t ) data - > BufSize , " %s " , ( HistoryPos > = 0 ) ? History [ HistoryPos ] : " " ) ;
2015-08-08 19:56:09 +03:00
data - > BufDirty = true ;
}
}
}
return 0 ;
}
} ;
2016-05-04 05:29:37 +03:00
static void ShowExampleAppConsole ( bool * p_open )
2015-08-08 19:56:09 +03:00
{
static ExampleAppConsole console ;
2016-05-04 05:29:37 +03:00
console . Draw ( " Example: Console " , p_open ) ;
2015-08-20 07:51:25 +03:00
}
2018-07-12 19:05:12 +03:00
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: LOG
//-----------------------------------------------------------------------------
2015-08-20 07:51:25 +03:00
// Usage:
// static ExampleAppLog my_log;
// my_log.AddLog("Hello %d world\n", 123);
// my_log.Draw("title");
struct ExampleAppLog
{
ImGuiTextBuffer Buf ;
ImGuiTextFilter Filter ;
ImVector < int > LineOffsets ; // Index to lines offset
bool ScrollToBottom ;
void Clear ( ) { Buf . clear ( ) ; LineOffsets . clear ( ) ; }
2017-08-25 19:42:27 +03:00
void AddLog ( const char * fmt , . . . ) IM_FMTARGS ( 2 )
2015-08-20 07:51:25 +03:00
{
int old_size = Buf . size ( ) ;
va_list args ;
va_start ( args , fmt ) ;
2017-11-28 19:13:21 +03:00
Buf . appendfv ( fmt , args ) ;
2015-08-20 07:51:25 +03:00
va_end ( args ) ;
for ( int new_size = Buf . size ( ) ; old_size < new_size ; old_size + + )
if ( Buf [ old_size ] = = ' \n ' )
LineOffsets . push_back ( old_size ) ;
ScrollToBottom = true ;
}
2016-05-04 05:29:37 +03:00
void Draw ( const char * title , bool * p_open = NULL )
2015-08-20 07:51:25 +03:00
{
2017-08-13 04:22:03 +03:00
ImGui : : SetNextWindowSize ( ImVec2 ( 500 , 400 ) , ImGuiCond_FirstUseEver ) ;
2018-07-09 17:38:59 +03:00
if ( ! ImGui : : Begin ( title , p_open ) )
{
ImGui : : End ( ) ;
return ;
}
2015-08-20 07:51:25 +03:00
if ( ImGui : : Button ( " Clear " ) ) Clear ( ) ;
ImGui : : SameLine ( ) ;
bool copy = ImGui : : Button ( " Copy " ) ;
ImGui : : SameLine ( ) ;
Filter . Draw ( " Filter " , - 100.0f ) ;
ImGui : : Separator ( ) ;
2015-09-01 23:34:54 +03:00
ImGui : : BeginChild ( " scrolling " , ImVec2 ( 0 , 0 ) , false , ImGuiWindowFlags_HorizontalScrollbar ) ;
2015-08-20 07:51:25 +03:00
if ( copy ) ImGui : : LogToClipboard ( ) ;
if ( Filter . IsActive ( ) )
{
const char * buf_begin = Buf . begin ( ) ;
const char * line = buf_begin ;
for ( int line_no = 0 ; line ! = NULL ; line_no + + )
{
const char * line_end = ( line_no < LineOffsets . Size ) ? buf_begin + LineOffsets [ line_no ] : NULL ;
if ( Filter . PassFilter ( line , line_end ) )
ImGui : : TextUnformatted ( line , line_end ) ;
line = line_end & & line_end [ 1 ] ? line_end + 1 : NULL ;
}
}
else
{
ImGui : : TextUnformatted ( Buf . begin ( ) ) ;
}
if ( ScrollToBottom )
ImGui : : SetScrollHere ( 1.0f ) ;
ScrollToBottom = false ;
ImGui : : EndChild ( ) ;
ImGui : : End ( ) ;
}
} ;
2016-11-11 08:10:26 +03:00
// Demonstrate creating a simple log window with basic filtering.
2016-05-04 05:29:37 +03:00
static void ShowExampleAppLog ( bool * p_open )
2015-08-20 07:51:25 +03:00
{
static ExampleAppLog log ;
2017-08-08 19:11:10 +03:00
// Demo: add random items (unless Ctrl is held)
2018-07-23 17:27:28 +03:00
static double last_time = - 1.0 ;
double time = ImGui : : GetTime ( ) ;
2017-08-08 19:11:10 +03:00
if ( time - last_time > = 0.20f & & ! ImGui : : GetIO ( ) . KeyCtrl )
2015-08-20 07:51:25 +03:00
{
const char * random_words [ ] = { " system " , " info " , " warning " , " error " , " fatal " , " notice " , " log " } ;
2017-12-11 20:27:48 +03:00
log . AddLog ( " [%s] Hello, time is %.1f, frame count is %d \n " , random_words [ rand ( ) % IM_ARRAYSIZE ( random_words ) ] , time , ImGui : : GetFrameCount ( ) ) ;
2015-08-20 07:51:25 +03:00
last_time = time ;
}
2016-05-04 05:29:37 +03:00
log . Draw ( " Example: Log " , p_open ) ;
2015-08-08 19:56:09 +03:00
}
2018-07-12 19:05:12 +03:00
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: SIMPLE LAYOUT
//-----------------------------------------------------------------------------
2016-11-11 08:10:26 +03:00
// Demonstrate create a window with multiple child windows.
2016-05-04 05:29:37 +03:00
static void ShowExampleAppLayout ( bool * p_open )
2015-08-08 19:56:09 +03:00
{
2017-08-13 04:22:03 +03:00
ImGui : : SetNextWindowSize ( ImVec2 ( 500 , 440 ) , ImGuiCond_FirstUseEver ) ;
2016-05-04 05:29:37 +03:00
if ( ImGui : : Begin ( " Example: Layout " , p_open , ImGuiWindowFlags_MenuBar ) )
2015-08-08 19:56:09 +03:00
{
if ( ImGui : : BeginMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " File " ) )
{
2016-05-04 05:29:37 +03:00
if ( ImGui : : MenuItem ( " Close " ) ) * p_open = false ;
2015-08-08 19:56:09 +03:00
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenuBar ( ) ;
}
// left
static int selected = 0 ;
ImGui : : BeginChild ( " left pane " , ImVec2 ( 150 , 0 ) , true ) ;
for ( int i = 0 ; i < 100 ; i + + )
{
char label [ 128 ] ;
sprintf ( label , " MyObject %d " , i ) ;
if ( ImGui : : Selectable ( label , selected = = i ) )
selected = i ;
}
ImGui : : EndChild ( ) ;
ImGui : : SameLine ( ) ;
2015-08-26 06:44:36 +03:00
2015-08-08 19:56:09 +03:00
// right
ImGui : : BeginGroup ( ) ;
2017-12-12 19:54:29 +03:00
ImGui : : BeginChild ( " item view " , ImVec2 ( 0 , - ImGui : : GetFrameHeightWithSpacing ( ) ) ) ; // Leave room for 1 line below us
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " MyObject: %d " , selected ) ;
ImGui : : Separator ( ) ;
ImGui : : TextWrapped ( " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " ) ;
ImGui : : EndChild ( ) ;
2017-11-30 09:41:55 +03:00
if ( ImGui : : Button ( " Revert " ) ) { }
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Save " ) ) { }
2015-08-08 19:56:09 +03:00
ImGui : : EndGroup ( ) ;
}
ImGui : : End ( ) ;
}
2018-07-12 19:05:12 +03:00
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: PROPERTY EDITOR
//-----------------------------------------------------------------------------
2016-11-11 08:10:26 +03:00
// Demonstrate create a simple property editor.
2016-05-04 05:29:37 +03:00
static void ShowExampleAppPropertyEditor ( bool * p_open )
2015-11-29 04:58:18 +03:00
{
2017-08-13 04:22:03 +03:00
ImGui : : SetNextWindowSize ( ImVec2 ( 430 , 450 ) , ImGuiCond_FirstUseEver ) ;
2016-05-04 05:29:37 +03:00
if ( ! ImGui : : Begin ( " Example: Property editor " , p_open ) )
2015-11-29 04:58:18 +03:00
{
ImGui : : End ( ) ;
return ;
}
ShowHelpMarker ( " This example shows how you may implement a property editor using two columns. \n All objects/fields data are dummies here. \n Remember that in many simple cases, you can use ImGui::SameLine(xxx) to position \n your cursor horizontally instead of using the Columns() API. " ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 2 , 2 ) ) ;
ImGui : : Columns ( 2 ) ;
ImGui : : Separator ( ) ;
struct funcs
{
2016-05-05 06:10:06 +03:00
static void ShowDummyObject ( const char * prefix , int uid )
2015-11-29 04:58:18 +03:00
{
2015-12-04 05:33:57 +03:00
ImGui : : PushID ( uid ) ; // Use object uid as identifier. Most commonly you could also use the object pointer as a base ID.
2017-10-12 09:33:45 +03:00
ImGui : : AlignTextToFramePadding ( ) ; // Text and Tree nodes are less high than regular widgets, here we add vertical spacing to make the tree lines equal high.
2016-05-04 05:29:37 +03:00
bool node_open = ImGui : : TreeNode ( " Object " , " %s_%u " , prefix , uid ) ;
2015-11-29 04:58:18 +03:00
ImGui : : NextColumn ( ) ;
2017-10-12 09:33:45 +03:00
ImGui : : AlignTextToFramePadding ( ) ;
2015-11-29 04:58:18 +03:00
ImGui : : Text ( " my sailor is rich " ) ;
ImGui : : NextColumn ( ) ;
2016-05-04 05:29:37 +03:00
if ( node_open )
2015-11-29 04:58:18 +03:00
{
static float dummy_members [ 8 ] = { 0.0f , 0.0f , 1.0f , 3.1416f , 100.0f , 999.0f } ;
for ( int i = 0 ; i < 8 ; i + + )
{
ImGui : : PushID ( i ) ; // Use field index as identifier.
if ( i < 2 )
{
2016-05-05 06:10:06 +03:00
ShowDummyObject ( " Child " , 424242 ) ;
2015-11-29 04:58:18 +03:00
}
else
{
2018-05-15 18:26:24 +03:00
// Here we use a TreeNode to highlight on hover (we could use e.g. Selectable as well)
2017-10-12 09:33:45 +03:00
ImGui : : AlignTextToFramePadding ( ) ;
2018-06-25 19:20:07 +03:00
ImGui : : TreeNodeEx ( " Field " , ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Bullet , " Field_%d " , i ) ;
2015-11-29 04:58:18 +03:00
ImGui : : NextColumn ( ) ;
ImGui : : PushItemWidth ( - 1 ) ;
if ( i > = 5 )
ImGui : : InputFloat ( " ##value " , & dummy_members [ i ] , 1.0f ) ;
else
ImGui : : DragFloat ( " ##value " , & dummy_members [ i ] , 0.01f ) ;
ImGui : : PopItemWidth ( ) ;
ImGui : : NextColumn ( ) ;
}
ImGui : : PopID ( ) ;
}
ImGui : : TreePop ( ) ;
}
ImGui : : PopID ( ) ;
2016-03-26 20:44:17 +03:00
}
2015-11-29 04:58:18 +03:00
} ;
// Iterate dummy objects with dummy members (all the same data)
for ( int obj_i = 0 ; obj_i < 3 ; obj_i + + )
funcs : : ShowDummyObject ( " Object " , obj_i ) ;
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : PopStyleVar ( ) ;
ImGui : : End ( ) ;
}
2018-07-12 19:05:12 +03:00
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: LONG TEXT
//-----------------------------------------------------------------------------
2016-11-11 08:10:26 +03:00
// Demonstrate/test rendering huge amount of text, and the incidence of clipping.
2016-05-04 05:29:37 +03:00
static void ShowExampleAppLongText ( bool * p_open )
2015-08-08 19:56:09 +03:00
{
2017-08-13 04:22:03 +03:00
ImGui : : SetNextWindowSize ( ImVec2 ( 520 , 600 ) , ImGuiCond_FirstUseEver ) ;
2016-05-04 05:29:37 +03:00
if ( ! ImGui : : Begin ( " Example: Long text display " , p_open ) )
2015-08-08 19:56:09 +03:00
{
ImGui : : End ( ) ;
return ;
}
static int test_type = 0 ;
static ImGuiTextBuffer log ;
static int lines = 0 ;
ImGui : : Text ( " Printing unusually long amount of text. " ) ;
2017-11-16 04:10:11 +03:00
ImGui : : Combo ( " Test type " , & test_type , " Single call to TextUnformatted() \0 Multiple calls to Text(), clipped manually \0 Multiple calls to Text(), not clipped (slow) \0 " ) ;
2015-08-08 19:56:09 +03:00
ImGui : : Text ( " Buffer contents: %d lines, %d bytes " , lines , log . size ( ) ) ;
if ( ImGui : : Button ( " Clear " ) ) { log . clear ( ) ; lines = 0 ; }
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Add 1000 lines " ) )
{
for ( int i = 0 ; i < 1000 ; i + + )
2017-11-28 19:13:21 +03:00
log . appendf ( " %i The quick brown fox jumps over the lazy dog \n " , lines + i ) ;
2015-08-08 19:56:09 +03:00
lines + = 1000 ;
}
ImGui : : BeginChild ( " Log " ) ;
switch ( test_type )
{
case 0 :
// Single call to TextUnformatted() with a big buffer
ImGui : : TextUnformatted ( log . begin ( ) , log . end ( ) ) ;
break ;
case 1 :
2015-09-01 23:34:54 +03:00
{
// Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGuiListClipper helper.
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 0 , 0 ) ) ;
2016-05-21 19:27:18 +03:00
ImGuiListClipper clipper ( lines ) ;
while ( clipper . Step ( ) )
for ( int i = clipper . DisplayStart ; i < clipper . DisplayEnd ; i + + )
ImGui : : Text ( " %i The quick brown fox jumps over the lazy dog " , i ) ;
2015-09-01 23:34:54 +03:00
ImGui : : PopStyleVar ( ) ;
break ;
}
2015-08-08 19:56:09 +03:00
case 2 :
// Multiple calls to Text(), not clipped (slow)
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 0 , 0 ) ) ;
for ( int i = 0 ; i < lines ; i + + )
2016-05-21 19:27:18 +03:00
ImGui : : Text ( " %i The quick brown fox jumps over the lazy dog " , i ) ;
2015-08-08 19:56:09 +03:00
ImGui : : PopStyleVar ( ) ;
break ;
}
ImGui : : EndChild ( ) ;
ImGui : : End ( ) ;
}
2018-07-12 19:05:12 +03:00
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: AUTO RESIZE
//-----------------------------------------------------------------------------
// Demonstrate creating a window which gets auto-resized according to its content.
static void ShowExampleAppAutoResize ( bool * p_open )
{
if ( ! ImGui : : Begin ( " Example: Auto-resizing window " , p_open , ImGuiWindowFlags_AlwaysAutoResize ) )
{
ImGui : : End ( ) ;
return ;
}
static int lines = 10 ;
ImGui : : Text ( " Window will resize every-frame to the size of its content. \n Note that you probably don't want to query the window size to \n output your content because that would create a feedback loop. " ) ;
ImGui : : SliderInt ( " Number of lines " , & lines , 1 , 20 ) ;
for ( int i = 0 ; i < lines ; i + + )
ImGui : : Text ( " %*sThis is line %d " , i * 4 , " " , i ) ; // Pad with space to extend size horizontally
ImGui : : End ( ) ;
}
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: CONSTRAINED RESIZE
//-----------------------------------------------------------------------------
// Demonstrate creating a window with custom resize constraints.
static void ShowExampleAppConstrainedResize ( bool * p_open )
{
struct CustomConstraints // Helper functions to demonstrate programmatic constraints
{
static void Square ( ImGuiSizeCallbackData * data ) { data - > DesiredSize = ImVec2 ( IM_MAX ( data - > DesiredSize . x , data - > DesiredSize . y ) , IM_MAX ( data - > DesiredSize . x , data - > DesiredSize . y ) ) ; }
static void Step ( ImGuiSizeCallbackData * data ) { float step = ( float ) ( int ) ( intptr_t ) data - > UserData ; data - > DesiredSize = ImVec2 ( ( int ) ( data - > DesiredSize . x / step + 0.5f ) * step , ( int ) ( data - > DesiredSize . y / step + 0.5f ) * step ) ; }
} ;
static bool auto_resize = false ;
static int type = 0 ;
static int display_lines = 10 ;
if ( type = = 0 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( - 1 , 0 ) , ImVec2 ( - 1 , FLT_MAX ) ) ; // Vertical only
if ( type = = 1 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0 , - 1 ) , ImVec2 ( FLT_MAX , - 1 ) ) ; // Horizontal only
if ( type = = 2 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 100 , 100 ) , ImVec2 ( FLT_MAX , FLT_MAX ) ) ; // Width > 100, Height > 100
if ( type = = 3 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 400 , - 1 ) , ImVec2 ( 500 , - 1 ) ) ; // Width 400-500
if ( type = = 4 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( - 1 , 400 ) , ImVec2 ( - 1 , 500 ) ) ; // Height 400-500
if ( type = = 5 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0 , 0 ) , ImVec2 ( FLT_MAX , FLT_MAX ) , CustomConstraints : : Square ) ; // Always Square
if ( type = = 6 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0 , 0 ) , ImVec2 ( FLT_MAX , FLT_MAX ) , CustomConstraints : : Step , ( void * ) 100 ) ; // Fixed Step
ImGuiWindowFlags flags = auto_resize ? ImGuiWindowFlags_AlwaysAutoResize : 0 ;
if ( ImGui : : Begin ( " Example: Constrained Resize " , p_open , flags ) )
{
const char * desc [ ] =
{
" Resize vertical only " ,
" Resize horizontal only " ,
" Width > 100, Height > 100 " ,
" Width 400-500 " ,
" Height 400-500 " ,
" Custom: Always Square " ,
" Custom: Fixed Steps (100) " ,
} ;
if ( ImGui : : Button ( " 200x200 " ) ) { ImGui : : SetWindowSize ( ImVec2 ( 200 , 200 ) ) ; } ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " 500x500 " ) ) { ImGui : : SetWindowSize ( ImVec2 ( 500 , 500 ) ) ; } ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " 800x200 " ) ) { ImGui : : SetWindowSize ( ImVec2 ( 800 , 200 ) ) ; }
ImGui : : PushItemWidth ( 200 ) ;
ImGui : : Combo ( " Constraint " , & type , desc , IM_ARRAYSIZE ( desc ) ) ;
ImGui : : DragInt ( " Lines " , & display_lines , 0.2f , 1 , 100 ) ;
ImGui : : PopItemWidth ( ) ;
ImGui : : Checkbox ( " Auto-resize " , & auto_resize ) ;
for ( int i = 0 ; i < display_lines ; i + + )
ImGui : : Text ( " %*sHello, sailor! Making this line long enough for the example. " , i * 4 , " " ) ;
}
ImGui : : End ( ) ;
}
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: SIMPLE OVERLAY
//-----------------------------------------------------------------------------
// Demonstrate creating a simple static window with no decoration + a context-menu to choose which corner of the screen to use.
static void ShowExampleAppSimpleOverlay ( bool * p_open )
{
const float DISTANCE = 10.0f ;
static int corner = 0 ;
ImVec2 window_pos = ImVec2 ( ( corner & 1 ) ? ImGui : : GetIO ( ) . DisplaySize . x - DISTANCE : DISTANCE , ( corner & 2 ) ? ImGui : : GetIO ( ) . DisplaySize . y - DISTANCE : DISTANCE ) ;
ImVec2 window_pos_pivot = ImVec2 ( ( corner & 1 ) ? 1.0f : 0.0f , ( corner & 2 ) ? 1.0f : 0.0f ) ;
if ( corner ! = - 1 )
ImGui : : SetNextWindowPos ( window_pos , ImGuiCond_Always , window_pos_pivot ) ;
ImGui : : SetNextWindowBgAlpha ( 0.3f ) ; // Transparent background
if ( ImGui : : Begin ( " Example: Simple Overlay " , p_open , ( corner ! = - 1 ? ImGuiWindowFlags_NoMove : 0 ) | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav ) )
{
ImGui : : Text ( " Simple overlay \n " " in the corner of the screen. \n " " (right-click to change position) " ) ;
ImGui : : Separator ( ) ;
if ( ImGui : : IsMousePosValid ( ) )
ImGui : : Text ( " Mouse Position: (%.1f,%.1f) " , ImGui : : GetIO ( ) . MousePos . x , ImGui : : GetIO ( ) . MousePos . y ) ;
else
ImGui : : Text ( " Mouse Position: <invalid> " ) ;
if ( ImGui : : BeginPopupContextWindow ( ) )
{
if ( ImGui : : MenuItem ( " Custom " , NULL , corner = = - 1 ) ) corner = - 1 ;
if ( ImGui : : MenuItem ( " Top-left " , NULL , corner = = 0 ) ) corner = 0 ;
if ( ImGui : : MenuItem ( " Top-right " , NULL , corner = = 1 ) ) corner = 1 ;
if ( ImGui : : MenuItem ( " Bottom-left " , NULL , corner = = 2 ) ) corner = 2 ;
if ( ImGui : : MenuItem ( " Bottom-right " , NULL , corner = = 3 ) ) corner = 3 ;
if ( p_open & & ImGui : : MenuItem ( " Close " ) ) * p_open = false ;
ImGui : : EndPopup ( ) ;
}
}
ImGui : : End ( ) ;
}
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: WINDOW TITLES
//-----------------------------------------------------------------------------
// Demonstrate using "##" and "###" in identifiers to manipulate ID generation.
// This apply to all regular items as well. Read FAQ section "How can I have multiple widgets with the same label? Can I have widget without a label? (Yes). A primer on the purpose of labels/IDs." for details.
static void ShowExampleAppWindowTitles ( bool * )
{
// By default, Windows are uniquely identified by their title.
// You can use the "##" and "###" markers to manipulate the display/ID.
// Using "##" to display same title but have unique identifier.
ImGui : : SetNextWindowPos ( ImVec2 ( 100 , 100 ) , ImGuiCond_FirstUseEver ) ;
ImGui : : Begin ( " Same title as another window##1 " ) ;
ImGui : : Text ( " This is window 1. \n My title is the same as window 2, but my identifier is unique. " ) ;
ImGui : : End ( ) ;
ImGui : : SetNextWindowPos ( ImVec2 ( 100 , 200 ) , ImGuiCond_FirstUseEver ) ;
ImGui : : Begin ( " Same title as another window##2 " ) ;
ImGui : : Text ( " This is window 2. \n My title is the same as window 1, but my identifier is unique. " ) ;
ImGui : : End ( ) ;
// Using "###" to display a changing title but keep a static identifier "AnimatedTitle"
char buf [ 128 ] ;
sprintf ( buf , " Animated title %c %d###AnimatedTitle " , " |/- \\ " [ ( int ) ( ImGui : : GetTime ( ) / 0.25f ) & 3 ] , ImGui : : GetFrameCount ( ) ) ;
ImGui : : SetNextWindowPos ( ImVec2 ( 100 , 300 ) , ImGuiCond_FirstUseEver ) ;
ImGui : : Begin ( buf ) ;
ImGui : : Text ( " This window has a changing title. " ) ;
ImGui : : End ( ) ;
}
//-----------------------------------------------------------------------------
// EXAMPLE APP CODE: CUSTOM RENDERING
//-----------------------------------------------------------------------------
// Demonstrate using the low-level ImDrawList to draw custom shapes.
static void ShowExampleAppCustomRendering ( bool * p_open )
{
ImGui : : SetNextWindowSize ( ImVec2 ( 350 , 560 ) , ImGuiCond_FirstUseEver ) ;
if ( ! ImGui : : Begin ( " Example: Custom rendering " , p_open ) )
{
ImGui : : End ( ) ;
return ;
}
// Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of overloaded operators, etc.
// Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your types and ImVec2/ImVec4.
// ImGui defines overloaded operators but they are internal to imgui.cpp and not exposed outside (to avoid messing with your types)
// In this example we are not using the maths operators!
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
// Primitives
ImGui : : Text ( " Primitives " ) ;
static float sz = 36.0f ;
static float thickness = 4.0f ;
static ImVec4 col = ImVec4 ( 1.0f , 1.0f , 0.4f , 1.0f ) ;
ImGui : : DragFloat ( " Size " , & sz , 0.2f , 2.0f , 72.0f , " %.0f " ) ;
ImGui : : DragFloat ( " Thickness " , & thickness , 0.05f , 1.0f , 8.0f , " %.02f " ) ;
ImGui : : ColorEdit3 ( " Color " , & col . x ) ;
{
const ImVec2 p = ImGui : : GetCursorScreenPos ( ) ;
const ImU32 col32 = ImColor ( col ) ;
float x = p . x + 4.0f , y = p . y + 4.0f , spacing = 8.0f ;
for ( int n = 0 ; n < 2 ; n + + )
{
float curr_thickness = ( n = = 0 ) ? 1.0f : thickness ;
2018-07-17 19:18:14 +03:00
draw_list - > AddCircle ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , sz * 0.5f , col32 , 20 , curr_thickness ) ; x + = sz + spacing ;
draw_list - > AddRect ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col32 , 0.0f , ImDrawCornerFlags_All , curr_thickness ) ; x + = sz + spacing ;
draw_list - > AddRect ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col32 , 10.0f , ImDrawCornerFlags_All , curr_thickness ) ; x + = sz + spacing ;
draw_list - > AddRect ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col32 , 10.0f , ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotRight , curr_thickness ) ; x + = sz + spacing ;
draw_list - > AddTriangle ( ImVec2 ( x + sz * 0.5f , y ) , ImVec2 ( x + sz , y + sz - 0.5f ) , ImVec2 ( x , y + sz - 0.5f ) , col32 , curr_thickness ) ; x + = sz + spacing ;
draw_list - > AddLine ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y ) , col32 , curr_thickness ) ; x + = sz + spacing ; // Horizontal line (note: drawing a filled rectangle will be faster!)
draw_list - > AddLine ( ImVec2 ( x , y ) , ImVec2 ( x , y + sz ) , col32 , curr_thickness ) ; x + = spacing ; // Vertical line (note: drawing a filled rectangle will be faster!)
draw_list - > AddLine ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col32 , curr_thickness ) ; x + = sz + spacing ; // Diagonal line
draw_list - > AddBezierCurve ( ImVec2 ( x , y ) , ImVec2 ( x + sz * 1.3f , y + sz * 0.3f ) , ImVec2 ( x + sz - sz * 1.3f , y + sz - sz * 0.3f ) , ImVec2 ( x + sz , y + sz ) , col32 , curr_thickness ) ;
2018-07-12 19:05:12 +03:00
x = p . x + 4 ;
2018-07-17 19:18:14 +03:00
y + = sz + spacing ;
}
draw_list - > AddCircleFilled ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , sz * 0.5f , col32 , 32 ) ; x + = sz + spacing ;
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col32 ) ; x + = sz + spacing ;
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col32 , 10.0f ) ; x + = sz + spacing ;
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col32 , 10.0f , ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotRight ) ; x + = sz + spacing ;
draw_list - > AddTriangleFilled ( ImVec2 ( x + sz * 0.5f , y ) , ImVec2 ( x + sz , y + sz - 0.5f ) , ImVec2 ( x , y + sz - 0.5f ) , col32 ) ; x + = sz + spacing ;
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + thickness ) , col32 ) ; x + = sz + spacing ; // Horizontal line (faster than AddLine, but only handle integer thickness)
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + thickness , y + sz ) , col32 ) ; x + = spacing + spacing ; // Vertical line (faster than AddLine, but only handle integer thickness)
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + 1 , y + 1 ) , col32 ) ; x + = sz ; // Pixel (faster than AddLine)
draw_list - > AddRectFilledMultiColor ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , IM_COL32 ( 0 , 0 , 0 , 255 ) , IM_COL32 ( 255 , 0 , 0 , 255 ) , IM_COL32 ( 255 , 255 , 0 , 255 ) , IM_COL32 ( 0 , 255 , 0 , 255 ) ) ;
ImGui : : Dummy ( ImVec2 ( ( sz + spacing ) * 8 , ( sz + spacing ) * 3 ) ) ;
2018-07-12 19:05:12 +03:00
}
ImGui : : Separator ( ) ;
{
static ImVector < ImVec2 > points ;
static bool adding_line = false ;
ImGui : : Text ( " Canvas example " ) ;
if ( ImGui : : Button ( " Clear " ) ) points . clear ( ) ;
if ( points . Size > = 2 ) { ImGui : : SameLine ( ) ; if ( ImGui : : Button ( " Undo " ) ) { points . pop_back ( ) ; points . pop_back ( ) ; } }
ImGui : : Text ( " Left-click and drag to add lines, \n Right-click to undo " ) ;
// Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use IsItemHovered()
// But you can also draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
// If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max).
ImVec2 canvas_pos = ImGui : : GetCursorScreenPos ( ) ; // ImDrawList API uses screen coordinates!
ImVec2 canvas_size = ImGui : : GetContentRegionAvail ( ) ; // Resize canvas to what's available
if ( canvas_size . x < 50.0f ) canvas_size . x = 50.0f ;
if ( canvas_size . y < 50.0f ) canvas_size . y = 50.0f ;
draw_list - > AddRectFilledMultiColor ( canvas_pos , ImVec2 ( canvas_pos . x + canvas_size . x , canvas_pos . y + canvas_size . y ) , IM_COL32 ( 50 , 50 , 50 , 255 ) , IM_COL32 ( 50 , 50 , 60 , 255 ) , IM_COL32 ( 60 , 60 , 70 , 255 ) , IM_COL32 ( 50 , 50 , 60 , 255 ) ) ;
draw_list - > AddRect ( canvas_pos , ImVec2 ( canvas_pos . x + canvas_size . x , canvas_pos . y + canvas_size . y ) , IM_COL32 ( 255 , 255 , 255 , 255 ) ) ;
bool adding_preview = false ;
ImGui : : InvisibleButton ( " canvas " , canvas_size ) ;
ImVec2 mouse_pos_in_canvas = ImVec2 ( ImGui : : GetIO ( ) . MousePos . x - canvas_pos . x , ImGui : : GetIO ( ) . MousePos . y - canvas_pos . y ) ;
if ( adding_line )
{
adding_preview = true ;
points . push_back ( mouse_pos_in_canvas ) ;
if ( ! ImGui : : IsMouseDown ( 0 ) )
adding_line = adding_preview = false ;
}
if ( ImGui : : IsItemHovered ( ) )
{
if ( ! adding_line & & ImGui : : IsMouseClicked ( 0 ) )
{
points . push_back ( mouse_pos_in_canvas ) ;
adding_line = true ;
}
if ( ImGui : : IsMouseClicked ( 1 ) & & ! points . empty ( ) )
{
adding_line = adding_preview = false ;
points . pop_back ( ) ;
points . pop_back ( ) ;
}
}
draw_list - > PushClipRect ( canvas_pos , ImVec2 ( canvas_pos . x + canvas_size . x , canvas_pos . y + canvas_size . y ) , true ) ; // clip lines within the canvas (if we resize it, etc.)
for ( int i = 0 ; i < points . Size - 1 ; i + = 2 )
draw_list - > AddLine ( ImVec2 ( canvas_pos . x + points [ i ] . x , canvas_pos . y + points [ i ] . y ) , ImVec2 ( canvas_pos . x + points [ i + 1 ] . x , canvas_pos . y + points [ i + 1 ] . y ) , IM_COL32 ( 255 , 255 , 0 , 255 ) , 2.0f ) ;
draw_list - > PopClipRect ( ) ;
if ( adding_preview )
points . pop_back ( ) ;
}
ImGui : : End ( ) ;
}
2015-08-08 19:56:09 +03:00
// End of Demo code
# else
2017-12-25 00:46:50 +03:00
void ImGui : : ShowDemoWindow ( bool * ) { }
2016-05-13 18:03:36 +03:00
void ImGui : : ShowUserGuide ( ) { }
void ImGui : : ShowStyleEditor ( ImGuiStyle * ) { }
2015-08-08 19:56:09 +03:00
# endif