2016-05-30 19:38:36 +02:00
// dear imgui, v1.50 WIP
2015-12-24 19:56:47 +01:00
// (demo code)
2015-07-22 01:00:28 +02:00
// Don't remove this file from your project! It is useful reference code that you can execute.
// You can call ImGui::ShowTestWindow() in your code to learn about various features of ImGui.
// Everything in this file will be stripped out by the linker if you don't call ImGui::ShowTestWindow().
# if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
# endif
# include "imgui.h"
2015-11-13 17:08:54 +01:00
# include <ctype.h> // toupper, isprint
2016-05-31 00:00:44 +02:00
# include <math.h> // sqrtf, powf, cosf, sinf, floorf, ceilf
2015-11-13 17:08:54 +01:00
# include <stdio.h> // vsnprintf, sscanf, printf
# include <stdlib.h> // NULL, malloc, free, qsort, atoi
2015-11-29 11:20:50 +01: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-07-22 01:00:28 +02: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
2015-07-22 01:13:56 +02:00
# ifdef __clang__
2016-05-04 23:17:53 +02:00
# pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
2015-08-02 05:37:32 +02: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-08 20:30:56 +02:00
# pragma clang diagnostic ignored "-Wformat-security" // warning : warning: format string is not a string literal
2016-05-04 23:17:53 +02: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.
# pragma clang diagnostic ignored "-Wreserved-id-macro" // warning : macro name is a reserved identifier //
2016-05-09 22:27:44 +02:00
# elif defined(__GNUC__)
2015-08-02 05:37:32 +02:00
# pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size
2015-08-08 20:26:22 +02:00
# pragma GCC diagnostic ignored "-Wformat-security" // warning : format string is not a string literal (potentially insecure)
2016-05-07 17:57:13 +02: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
2015-07-22 01:13:56 +02:00
# endif
2015-07-22 01:00:28 +02:00
// Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
2015-08-09 17:24:10 +02:00
# ifdef _WIN32
2015-07-22 01:00:28 +02:00
# define IM_NEWLINE "\r\n"
# else
# define IM_NEWLINE "\n"
# endif
# define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR) / sizeof(*_ARR)))
2016-05-21 22:53:08 +02:00
# define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B))
2015-07-22 01:00:28 +02:00
//-----------------------------------------------------------------------------
// DEMO CODE
//-----------------------------------------------------------------------------
# ifndef IMGUI_DISABLE_TEST_WINDOWS
2016-05-02 12:32:16 +02: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-21 22:53:08 +02:00
static void ShowExampleAppConstrainedResize ( bool * p_open ) ;
2016-05-02 12:32:16 +02:00
static void ShowExampleAppFixedOverlay ( bool * p_open ) ;
static void ShowExampleAppManipulatingWindowTitle ( bool * p_open ) ;
static void ShowExampleAppCustomRendering ( bool * p_open ) ;
2015-07-22 01:00:28 +02:00
static void ShowExampleAppMainMenuBar ( ) ;
static void ShowExampleMenuFile ( ) ;
2016-07-18 14:31:15 +02:00
static void ShowHelpMarker ( const char * desc , float wrap_width = 450.0f )
2015-07-22 01:00:28 +02:00
{
2015-08-24 13:50:18 +02:00
ImGui : : TextDisabled ( " (?) " ) ;
if ( ImGui : : IsItemHovered ( ) )
2016-07-18 14:31:15 +02:00
{
ImGui : : BeginTooltip ( ) ;
ImGui : : PushTextWrapPos ( wrap_width ) ;
ImGui : : TextUnformatted ( desc ) ;
ImGui : : PopTextWrapPos ( ) ;
ImGui : : EndTooltip ( ) ;
}
2015-07-22 01:00:28 +02:00
}
void ImGui : : ShowUserGuide ( )
{
ImGui : : BulletText ( " Double-click on title bar to collapse window. " ) ;
ImGui : : BulletText ( " Click and drag on lower right corner to resize window. " ) ;
ImGui : : BulletText ( " Click and drag on any empty space to move window. " ) ;
ImGui : : BulletText ( " Mouse Wheel to scroll. " ) ;
if ( ImGui : : GetIO ( ) . FontAllowUserScaling )
ImGui : : BulletText ( " CTRL+Mouse Wheel to zoom window contents. " ) ;
ImGui : : BulletText ( " TAB/SHIFT+TAB to cycle through keyboard editable fields. " ) ;
ImGui : : BulletText ( " CTRL+Click on a slider or drag box to input text. " ) ;
ImGui : : BulletText (
" While editing text: \n "
" - 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 "
" - You can apply arithmetic operators +,*,/ on numerical values. \n "
" Use +- to subtract. \n " ) ;
}
// Demonstrate most ImGui features (big function!)
2016-05-02 12:32:16 +02:00
void ImGui : : ShowTestWindow ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
// Examples apps
static bool show_app_main_menu_bar = false ;
static bool show_app_console = false ;
2015-08-14 04:59:37 +02:00
static bool show_app_log = false ;
2015-07-22 01:00:28 +02:00
static bool show_app_layout = false ;
2015-11-28 18:16:59 +01:00
static bool show_app_property_editor = false ;
2015-07-22 01:00:28 +02:00
static bool show_app_long_text = false ;
static bool show_app_auto_resize = false ;
2016-05-21 22:53:08 +02:00
static bool show_app_constrained_resize = false ;
2015-07-22 01:00:28 +02:00
static bool show_app_fixed_overlay = false ;
static bool show_app_manipulating_window_title = false ;
2015-12-13 14:36:00 +01:00
static bool show_app_custom_rendering = false ;
static bool show_app_style_editor = false ;
static bool show_app_metrics = false ;
2015-07-22 01:00:28 +02:00
static bool show_app_about = false ;
2015-12-13 14:36:00 +01:00
2015-07-22 01:00:28 +02:00
if ( show_app_main_menu_bar ) ShowExampleAppMainMenuBar ( ) ;
if ( show_app_console ) ShowExampleAppConsole ( & show_app_console ) ;
2015-08-14 04:59:37 +02:00
if ( show_app_log ) ShowExampleAppLog ( & show_app_log ) ;
2015-07-22 01:00:28 +02:00
if ( show_app_layout ) ShowExampleAppLayout ( & show_app_layout ) ;
2015-11-28 18:16:59 +01:00
if ( show_app_property_editor ) ShowExampleAppPropertyEditor ( & show_app_property_editor ) ;
2015-07-22 01:00:28 +02:00
if ( show_app_long_text ) ShowExampleAppLongText ( & show_app_long_text ) ;
if ( show_app_auto_resize ) ShowExampleAppAutoResize ( & show_app_auto_resize ) ;
2016-05-21 22:53:08 +02:00
if ( show_app_constrained_resize ) ShowExampleAppConstrainedResize ( & show_app_constrained_resize ) ;
2015-07-22 01:00:28 +02:00
if ( show_app_fixed_overlay ) ShowExampleAppFixedOverlay ( & show_app_fixed_overlay ) ;
if ( show_app_manipulating_window_title ) ShowExampleAppManipulatingWindowTitle ( & show_app_manipulating_window_title ) ;
if ( show_app_custom_rendering ) ShowExampleAppCustomRendering ( & show_app_custom_rendering ) ;
2015-12-13 14:36:00 +01: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-07-22 01:00:28 +02:00
if ( show_app_about )
{
ImGui : : Begin ( " About ImGui " , & show_app_about , ImGuiWindowFlags_AlwaysAutoResize ) ;
2015-12-24 19:56:47 +01:00
ImGui : : Text ( " dear imgui, %s " , ImGui : : GetVersion ( ) ) ;
2015-07-22 01:00:28 +02:00
ImGui : : Separator ( ) ;
ImGui : : Text ( " By Omar Cornut and all github contributors. " ) ;
ImGui : : Text ( " ImGui is licensed under the MIT License, see LICENSE for more information. " ) ;
ImGui : : End ( ) ;
}
static bool no_titlebar = false ;
static bool no_border = true ;
static bool no_resize = false ;
static bool no_move = false ;
static bool no_scrollbar = false ;
static bool no_collapse = false ;
static bool no_menu = false ;
2016-07-20 00:02:59 +02:00
static bool no_nav = false ;
2015-07-22 01:00:28 +02:00
// Demonstrate the various window flags. Typically you would just use the default.
2015-08-30 19:07:51 +02:00
ImGuiWindowFlags window_flags = 0 ;
2015-07-22 01:00:28 +02:00
if ( no_titlebar ) window_flags | = ImGuiWindowFlags_NoTitleBar ;
if ( ! no_border ) window_flags | = ImGuiWindowFlags_ShowBorders ;
if ( no_resize ) window_flags | = ImGuiWindowFlags_NoResize ;
if ( no_move ) window_flags | = ImGuiWindowFlags_NoMove ;
if ( no_scrollbar ) window_flags | = ImGuiWindowFlags_NoScrollbar ;
if ( no_collapse ) window_flags | = ImGuiWindowFlags_NoCollapse ;
if ( ! no_menu ) window_flags | = ImGuiWindowFlags_MenuBar ;
2016-07-30 18:06:05 +02:00
if ( no_nav ) window_flags | = ImGuiWindowFlags_NoNavInputs ;
2016-04-04 01:37:02 +02:00
ImGui : : SetNextWindowSize ( ImVec2 ( 550 , 680 ) , ImGuiSetCond_FirstUseEver ) ;
2016-05-02 12:32:16 +02:00
if ( ! ImGui : : Begin ( " ImGui Demo " , p_open , window_flags ) )
2015-07-22 01:00:28 +02:00
{
// Early out if the window is collapsed, as an optimization.
ImGui : : End ( ) ;
return ;
}
2015-08-24 13:50:18 +02:00
2015-07-22 01:00:28 +02:00
//ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // 2/3 of the space for widget and 1/3 for labels
ImGui : : PushItemWidth ( - 140 ) ; // Right align, keep 140 pixels for labels
2015-12-24 19:56:47 +01:00
ImGui : : Text ( " Dear ImGui says hello. " ) ;
2015-07-22 01:00:28 +02: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-14 04:59:37 +02:00
ImGui : : MenuItem ( " Log " , NULL , & show_app_log ) ;
2015-07-22 01:00:28 +02:00
ImGui : : MenuItem ( " Simple layout " , NULL , & show_app_layout ) ;
2015-11-28 18:16:59 +01:00
ImGui : : MenuItem ( " Property editor " , NULL , & show_app_property_editor ) ;
2015-07-22 01:00:28 +02:00
ImGui : : MenuItem ( " Long text display " , NULL , & show_app_long_text ) ;
ImGui : : MenuItem ( " Auto-resizing window " , NULL , & show_app_auto_resize ) ;
2016-05-21 22:53:08 +02:00
ImGui : : MenuItem ( " Constrained-resizing window " , NULL , & show_app_constrained_resize ) ;
2015-07-22 01:00:28 +02:00
ImGui : : MenuItem ( " Simple overlay " , NULL , & show_app_fixed_overlay ) ;
ImGui : : MenuItem ( " Manipulating window title " , NULL , & show_app_manipulating_window_title ) ;
ImGui : : MenuItem ( " Custom rendering " , NULL , & show_app_custom_rendering ) ;
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Help " ) )
{
ImGui : : MenuItem ( " Metrics " , NULL , & show_app_metrics ) ;
2015-12-13 14:36:00 +01:00
ImGui : : MenuItem ( " Style Editor " , NULL , & show_app_style_editor ) ;
2015-07-22 01:00:28 +02:00
ImGui : : MenuItem ( " About ImGui " , NULL , & show_app_about ) ;
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenuBar ( ) ;
}
ImGui : : Spacing ( ) ;
if ( ImGui : : CollapsingHeader ( " Help " ) )
{
ImGui : : TextWrapped ( " This window is being created by the ShowTestWindow() function. Please refer to the code for programming reference. \n \n User Guide: " ) ;
ImGui : : ShowUserGuide ( ) ;
}
if ( ImGui : : CollapsingHeader ( " Window options " ) )
{
2015-12-13 15:03:26 +01:00
ImGui : : Checkbox ( " No titlebar " , & no_titlebar ) ; ImGui : : SameLine ( 150 ) ;
ImGui : : Checkbox ( " No border " , & no_border ) ; ImGui : : SameLine ( 300 ) ;
ImGui : : Checkbox ( " No resize " , & no_resize ) ;
ImGui : : Checkbox ( " No move " , & no_move ) ; ImGui : : SameLine ( 150 ) ;
ImGui : : Checkbox ( " No scrollbar " , & no_scrollbar ) ; ImGui : : SameLine ( 300 ) ;
ImGui : : Checkbox ( " No collapse " , & no_collapse ) ;
2016-07-20 00:02:59 +02:00
ImGui : : Checkbox ( " No menu " , & no_menu ) ; ImGui : : SameLine ( 150 ) ;
ImGui : : Checkbox ( " No nav " , & no_nav ) ;
2015-12-13 15:03:26 +01:00
2015-07-22 01:00:28 +02:00
if ( ImGui : : TreeNode ( " Style " ) )
{
ImGui : : ShowStyleEditor ( ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Logging " ) )
{
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 " ) )
{
2016-04-24 22:36:46 +02:00
if ( ImGui : : TreeNode ( " Trees " ) )
2015-07-22 01:00:28 +02:00
{
2016-05-01 17:55:04 +02:00
if ( ImGui : : TreeNode ( " Basic trees " ) )
2015-07-22 01:00:28 +02:00
{
2016-05-01 17:55:04 +02:00
for ( int i = 0 ; i < 5 ; i + + )
if ( ImGui : : TreeNode ( ( void * ) ( intptr_t ) i , " Child %d " , i ) )
{
ImGui : : Text ( " blah blah " ) ;
ImGui : : SameLine ( ) ;
if ( ImGui : : SmallButton ( " print " ) ) printf ( " Child %d pressed " , i ) ;
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
2016-05-28 19:30:01 +02:00
if ( ImGui : : TreeNode ( " Advanced, with Selectable nodes " ) )
2016-05-01 17:55:04 +02:00
{
2016-05-28 17:12:13 +02: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-28 19:30:01 +02: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 17:12:13 +02: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-28 19:30:01 +02:00
ImGui : : PushStyleVar ( ImGuiStyleVar_IndentSpacing , ImGui : : GetFontSize ( ) * 3 ) ; // Increase spacing to differentiate leaves from expanded contents.
2016-05-01 20:12:14 +02:00
for ( int i = 0 ; i < 6 ; i + + )
2015-07-22 01:00:28 +02:00
{
2016-05-28 17:12:13 +02:00
// Disable the default open on single-click behavior and pass in Selected flag according to our selection state.
2016-05-28 19:30:01 +02:00
ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ( ( selection_mask & ( 1 < < i ) ) ? ImGuiTreeNodeFlags_Selected : 0 ) ;
2016-05-28 17:12:13 +02:00
if ( i < 3 )
2016-05-01 17:55:04 +02:00
{
2016-05-28 17:12:13 +02:00
// Node
bool node_open = ImGui : : TreeNodeEx ( ( void * ) ( intptr_t ) i , node_flags , " Selectable Node %d " , i ) ;
if ( ImGui : : IsItemClicked ( ) )
node_clicked = i ;
if ( node_open )
{
ImGui : : Text ( " Blah blah \n Blah Blah " ) ;
ImGui : : TreePop ( ) ;
}
}
else
{
2016-05-28 18:15:54 +02: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().
ImGui : : TreeNodeEx ( ( void * ) ( intptr_t ) i , node_flags | ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen , " Selectable Leaf %d " , i ) ;
2016-05-28 17:12:13 +02:00
if ( ImGui : : IsItemClicked ( ) )
node_clicked = i ;
2016-05-01 17:55:04 +02:00
}
2015-07-22 01:00:28 +02:00
}
2016-05-01 17:55:04 +02: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 14:18:46 +02:00
selection_mask ^ = ( 1 < < node_clicked ) ; // CTRL+click to toggle
2016-05-28 17:12:13 +02:00
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
2016-05-28 14:18:46 +02:00
selection_mask = ( 1 < < node_clicked ) ; // Click to single-select
2016-05-01 17:55:04 +02:00
}
2016-05-28 17:12:13 +02:00
ImGui : : PopStyleVar ( ) ;
2016-05-28 19:30:01 +02:00
if ( align_label_with_current_x_position )
ImGui : : Indent ( ImGui : : GetTreeNodeToLabelSpacing ( ) ) ;
2016-05-01 17:55:04 +02:00
ImGui : : TreePop ( ) ;
2015-07-22 01:00:28 +02:00
}
ImGui : : TreePop ( ) ;
}
2016-05-01 14:34:55 +02:00
if ( ImGui : : TreeNode ( " Collapsing Headers " ) )
{
static bool closable_group = true ;
if ( ImGui : : CollapsingHeader ( " Header " ) )
{
ImGui : : Checkbox ( " Enable extra group " , & closable_group ) ;
for ( int i = 0 ; i < 5 ; i + + )
ImGui : : Text ( " Some content %d " , i ) ;
}
if ( ImGui : : CollapsingHeader ( " Header with a close button " , & closable_group ) )
{
for ( int i = 0 ; i < 5 ; i + + )
ImGui : : Text ( " More content %d " , i ) ;
}
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
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 ( ) ;
}
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 : : TreePop ( ) ;
}
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 ( ) ) , 0xFFFF00FF ) ;
ImGui : : PushTextWrapPos ( ImGui : : GetCursorPos ( ) . x + wrap_width ) ;
ImGui : : Text ( " lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog. " , wrap_width ) ;
ImGui : : GetWindowDrawList ( ) - > AddRect ( ImGui : : GetItemRectMin ( ) , ImGui : : GetItemRectMax ( ) , 0xFF00FFFF ) ;
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 ( ) ) , 0xFFFF00FF ) ;
ImGui : : PushTextWrapPos ( ImGui : : GetCursorPos ( ) . x + wrap_width ) ;
ImGui : : Text ( " aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh " ) ;
ImGui : : GetWindowDrawList ( ) - > AddRect ( ImGui : : GetItemRectMin ( ) , ImGui : : GetItemRectMax ( ) , 0xFF00FFFF ) ;
ImGui : : PopTextWrapPos ( ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " UTF-8 Text " ) )
{
// UTF-8 test with Japanese characters
// (needs a suitable font, try Arial Unicode or M+ fonts http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html)
// Most compiler appears to support UTF-8 in source code (with Visual Studio you need to save your file as 'UTF-8 without signature')
// However for the sake for maximum portability here we are *not* including raw UTF-8 character in this source file, instead we encode the string with hexadecimal constants.
// In your own application be reasonable and use UTF-8 in source or retrieve the data from file system!
// Note that characters values are preserved even if the font cannot be displayed, so you can safely copy & paste garbled characters into another application.
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. " ) ;
ImGui : : Text ( " Hiragana: \xe3 \x81 \x8b \xe3 \x81 \x8d \xe3 \x81 \x8f \xe3 \x81 \x91 \xe3 \x81 \x93 (kakikukeko) " ) ;
ImGui : : Text ( " Kanjis: \xe6 \x97 \xa5 \xe6 \x9c \xac \xe8 \xaa \x9e (nihongo) " ) ;
static char buf [ 32 ] = " \xe6 \x97 \xa5 \xe6 \x9c \xac \xe8 \xaa \x9e " ;
ImGui : : InputText ( " UTF-8 input " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Images " ) )
{
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! " ) ;
ImVec2 tex_screen_pos = ImGui : : GetCursorScreenPos ( ) ;
float tex_w = ( float ) ImGui : : GetIO ( ) . Fonts - > TexWidth ;
float tex_h = ( float ) ImGui : : GetIO ( ) . Fonts - > TexHeight ;
ImTextureID tex_id = ImGui : : GetIO ( ) . Fonts - > TexID ;
ImGui : : Text ( " %.0fx%.0f " , tex_w , tex_h ) ;
ImGui : : Image ( tex_id , ImVec2 ( tex_w , tex_h ) , ImVec2 ( 0 , 0 ) , ImVec2 ( 1 , 1 ) , ImColor ( 255 , 255 , 255 , 255 ) , ImColor ( 255 , 255 , 255 , 128 ) ) ;
if ( ImGui : : IsItemHovered ( ) )
{
ImGui : : BeginTooltip ( ) ;
float focus_sz = 32.0f ;
2015-08-05 17:28:19 +02:00
float focus_x = ImGui : : GetMousePos ( ) . x - tex_screen_pos . x - focus_sz * 0.5f ; if ( focus_x < 0.0f ) focus_x = 0.0f ; else if ( focus_x > tex_w - focus_sz ) focus_x = tex_w - focus_sz ;
float focus_y = ImGui : : GetMousePos ( ) . y - tex_screen_pos . y - focus_sz * 0.5f ; if ( focus_y < 0.0f ) focus_y = 0.0f ; else if ( focus_y > tex_h - focus_sz ) focus_y = tex_h - focus_sz ;
2015-07-22 01:00:28 +02:00
ImGui : : Text ( " Min: (%.2f, %.2f) " , focus_x , focus_y ) ;
ImGui : : Text ( " Max: (%.2f, %.2f) " , focus_x + focus_sz , focus_y + focus_sz ) ;
ImVec2 uv0 = ImVec2 ( ( focus_x ) / tex_w , ( focus_y ) / tex_h ) ;
ImVec2 uv1 = ImVec2 ( ( focus_x + focus_sz ) / tex_w , ( focus_y + focus_sz ) / tex_h ) ;
ImGui : : Image ( tex_id , ImVec2 ( 128 , 128 ) , uv0 , uv1 , ImColor ( 255 , 255 , 255 , 255 ) , ImColor ( 255 , 255 , 255 , 128 ) ) ;
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
if ( ImGui : : ImageButton ( tex_id , ImVec2 ( 32 , 32 ) , ImVec2 ( 0 , 0 ) , ImVec2 ( 32.0f / tex_w , 32 / tex_h ) , frame_padding , ImColor ( 0 , 0 , 0 , 255 ) ) )
pressed_count + = 1 ;
ImGui : : PopID ( ) ;
2016-05-16 20:14:07 +02:00
ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
}
2016-05-16 20:14:07 +02:00
ImGui : : NewLine ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : Text ( " Pressed %d times. " , pressed_count ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Selectables " ) )
{
if ( ImGui : : TreeNode ( " Basic " ) )
{
2016-01-31 22:08:35 +01:00
static bool selected [ 4 ] = { false , true , false , false } ;
2015-07-22 01:00:28 +02:00
ImGui : : Selectable ( " 1. I am selectable " , & selected [ 0 ] ) ;
ImGui : : Selectable ( " 2. I am selectable " , & selected [ 1 ] ) ;
ImGui : : Text ( " 3. I am not selectable " ) ;
ImGui : : Selectable ( " 4. I am selectable " , & selected [ 2 ] ) ;
2016-03-03 00:30:08 +01:00
if ( ImGui : : Selectable ( " 5. I am double clickable " , selected [ 3 ] , ImGuiSelectableFlags_AllowDoubleClick ) )
2016-01-31 22:08:35 +01:00
if ( ImGui : : IsMouseDoubleClicked ( 0 ) )
selected [ 3 ] = ! selected [ 3 ] ;
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Rendering more text into the same block " ) )
{
static bool selected [ 3 ] = { false , false , false } ;
ImGui : : Selectable ( " main.c " , & selected [ 0 ] ) ; ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " 2,345 bytes " ) ;
ImGui : : Selectable ( " Hello.cpp " , & selected [ 1 ] ) ; ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " 12,345 bytes " ) ;
ImGui : : Selectable ( " Hello.h " , & selected [ 2 ] ) ; ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " 2,345 bytes " ) ;
ImGui : : TreePop ( ) ;
}
2016-06-07 09:05:36 +02: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-07-22 01:00:28 +02: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-24 22:36:46 +02:00
if ( ImGui : : Selectable ( " Sailor " , & selected [ i ] , 0 , ImVec2 ( 50 , 50 ) ) )
2015-07-22 01:00:28 +02: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-19 23:09:59 +01:00
ImGui : : Text ( " Password input " ) ;
2016-03-26 15:38:52 +01:00
static char bufpass [ 64 ] = " password123 " ;
2016-02-03 09:24:57 +01:00
ImGui : : InputText ( " password " , bufpass , 64 , ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank ) ;
2015-11-19 23:09:59 +01:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Display all characters as '*'. \n Disable clipboard cut and copy. \n Disable logging. \n " ) ;
2016-02-03 09:24:57 +01:00
ImGui : : InputText ( " password (clear) " , bufpass , 64 , ImGuiInputTextFlags_CharsNoBlank ) ;
2015-11-19 23:09:59 +01:00
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Multi-line Text Input " ) )
{
2015-09-09 10:08:08 +02:00
static bool read_only = false ;
2016-03-26 15:38:52 +01:00
static char text [ 1024 * 16 ] =
2015-10-18 11:57:29 +02: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-09 10:08:08 +02: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-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
2016-08-07 19:07:24 +02:00
static int clicked = 0 ;
if ( ImGui : : Button ( " Button " ) )
clicked + + ;
if ( clicked & 1 )
2015-07-22 01:00:28 +02:00
{
2015-08-24 13:50:18 +02:00
ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
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 ) ;
ImGui : : PushStyleColor ( ImGuiCol_Button , ImColor : : HSV ( i / 7.0f , 0.6f , 0.6f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonHovered , ImColor : : HSV ( i / 7.0f , 0.7f , 0.7f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonActive , ImColor : : HSV ( i / 7.0f , 0.8f , 0.8f ) ) ;
ImGui : : Button ( " Click " ) ;
ImGui : : PopStyleColor ( 3 ) ;
ImGui : : PopID ( ) ;
}
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 ( ) ;
}
// Testing IMGUI_ONCE_UPON_A_FRAME macro
//for (int i = 0; i < 5; i++)
//{
// IMGUI_ONCE_UPON_A_FRAME
// {
// ImGui::Text("This will be displayed only once.");
// }
//}
ImGui : : Separator ( ) ;
ImGui : : LabelText ( " label " , " Value " ) ;
static int item = 1 ;
ImGui : : Combo ( " combo " , & item , " aaaa \0 bbbb \0 cccc \0 dddd \0 eeee \0 \0 " ) ; // Combo using values packed in a single constant string (for really quick combo)
const char * items [ ] = { " AAAA " , " BBBB " , " CCCC " , " DDDD " , " EEEE " , " FFFF " , " GGGG " , " HHHH " , " IIII " , " JJJJ " , " KKKK " } ;
static int item2 = - 1 ;
ImGui : : Combo ( " combo scroll " , & item2 , items , IM_ARRAYSIZE ( items ) ) ; // Combo using proper array. You can also pass a callback to retrieve array value, no need to create/copy an array just for that.
{
static char str0 [ 128 ] = " Hello, world! " ;
static int i0 = 123 ;
static float f0 = 0.001f ;
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 " ) ;
ImGui : : InputFloat ( " input float " , & f0 , 0.01f , 1.0f ) ;
static float vec4a [ 4 ] = { 0.10f , 0.20f , 0.30f , 0.44f } ;
ImGui : : InputFloat3 ( " input float3 " , vec4a ) ;
}
{
static int i1 = 50 , i2 = 42 ;
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. " ) ;
ImGui : : DragInt ( " drag int 0..100 " , & i2 , 1 , 0 , 100 , " %.0f%% " ) ;
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 " ) ;
ImGui : : SliderFloat ( " slider log float " , & f2 , - 10.0f , 10.0f , " %.4f " , 3.0f ) ;
static float angle = 0.0f ;
ImGui : : SliderAngle ( " slider angle " , & angle ) ;
}
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 : : SameLine ( ) ; ShowHelpMarker ( " Click on the colored square to change edit mode. \n CTRL+click on individual component to input value. \n " ) ;
2015-08-24 13:50:18 +02:00
2015-07-22 01:00:28 +02:00
ImGui : : ColorEdit4 ( " color 2 " , col2 ) ;
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();
if ( ImGui : : TreeNode ( " Range Widgets " ) )
{
ImGui : : Unindent ( ) ;
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 %% " ) ;
ImGui : : DragIntRange2 ( " range int (no bounds) " , & begin_i , & end_i , 5 , 0 , 0 , " Min: %.0f units " , " Max: %.0f units " ) ;
ImGui : : Indent ( ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Multi-component Widgets " ) )
{
ImGui : : Unindent ( ) ;
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 : : DragInt2 ( " drag int2 " , vec4i , 1 , 0 , 255 ) ;
ImGui : : InputInt2 ( " input int2 " , vec4i ) ;
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 : : DragInt3 ( " drag int3 " , vec4i , 1 , 0 , 255 ) ;
ImGui : : InputInt3 ( " input int3 " , vec4i ) ;
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 : : Indent ( ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Vertical Sliders " ) )
{
ImGui : : Unindent ( ) ;
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 ) ;
ImGui : : PushStyleColor ( ImGuiCol_FrameBg , ImColor : : HSV ( i / 7.0f , 0.5f , 0.5f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_FrameBgHovered , ImColor : : HSV ( i / 7.0f , 0.6f , 0.5f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_FrameBgActive , ImColor : : HSV ( i / 7.0f , 0.7f , 0.5f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_SliderGrab , ImColor : : HSV ( i / 7.0f , 0.9f , 0.9f ) ) ;
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-16 12:05:26 +02:00
ImGui : : VSliderFloat ( " ##v " , ImVec2 ( 40 , 160 ) , & values [ i ] , 0.0f , 1.0f , " %.2f \n sec " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PopStyleVar ( ) ;
ImGui : : PopID ( ) ;
}
ImGui : : PopID ( ) ;
ImGui : : PopStyleVar ( ) ;
ImGui : : Indent ( ) ;
ImGui : : TreePop ( ) ;
}
}
2016-08-21 15:26:40 +02:00
if ( ImGui : : CollapsingHeader ( " Plots widgets " ) )
2015-07-22 01:00:28 +02:00
{
2015-12-13 22:41:45 +01:00
static bool animate = true ;
ImGui : : Checkbox ( " Animate " , & animate ) ;
2015-07-22 01:00:28 +02:00
static float arr [ ] = { 0.6f , 0.1f , 1.0f , 0.5f , 0.92f , 0.1f , 0.2f } ;
ImGui : : PlotLines ( " Frame Times " , arr , IM_ARRAYSIZE ( arr ) ) ;
2016-02-29 12:53:05 +01:00
// 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 } ;
2015-08-24 13:50:18 +02:00
static int values_offset = 0 ;
2016-08-01 20:55:54 +02:00
static float refresh_time = 0.0f ;
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
2015-07-22 01:00:28 +02:00
{
2016-08-01 20:55:54 +02:00
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 ;
2015-07-22 01:00:28 +02:00
}
2016-02-29 12:53:05 +01:00
ImGui : : PlotLines ( " Lines " , values , IM_ARRAYSIZE ( values ) , values_offset , " avg 0.0 " , - 1.0f , 1.0f , ImVec2 ( 0 , 80 ) ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PlotHistogram ( " Histogram " , arr , IM_ARRAYSIZE ( arr ) , 0 , NULL , 0.0f , 1.0f , ImVec2 ( 0 , 80 ) ) ;
2015-09-20 13:29:18 +02: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 ) ; }
2016-07-16 10:46:51 +02:00
static float Saw ( void * , int i ) { return ( i & 1 ) ? 1.0f : - 1.0f ; }
2015-09-20 13:29:18 +02:00
} ;
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 , 500 ) ;
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 ) ) ;
2015-12-13 22:41:45 +01:00
ImGui : : Separator ( ) ;
// 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 ; }
}
// 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 " ) ;
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 ) ;
2015-07-22 01:00:28 +02:00
}
if ( ImGui : : CollapsingHeader ( " Layout " ) )
{
if ( ImGui : : TreeNode ( " Child regions " ) )
{
ImGui : : Text ( " Without border " ) ;
static int line = 50 ;
bool goto_line = ImGui : : Button ( " Goto " ) ;
2015-08-24 13:50:18 +02:00
ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PushItemWidth ( 100 ) ;
goto_line | = ImGui : : InputInt ( " ##Line " , & line , 0 , 0 , ImGuiInputTextFlags_EnterReturnsTrue ) ;
ImGui : : PopItemWidth ( ) ;
2015-08-30 17:38:55 +02:00
ImGui : : BeginChild ( " Sub1 " , ImVec2 ( ImGui : : GetWindowContentRegionWidth ( ) * 0.5f , 300 ) , false , ImGuiWindowFlags_HorizontalScrollbar ) ;
2015-07-22 01:00:28 +02:00
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 )
ImGui : : SetScrollHere ( ) ;
ImGui : : EndChild ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_ChildWindowRounding , 5.0f ) ;
ImGui : : BeginChild ( " Sub2 " , ImVec2 ( 0 , 300 ) , true ) ;
ImGui : : Text ( " With border " ) ;
ImGui : : Columns ( 2 ) ;
for ( int i = 0 ; i < 100 ; i + + )
{
if ( i = = 50 )
ImGui : : NextColumn ( ) ;
char buf [ 32 ] ;
sprintf ( buf , " %08x " , i * 5731 ) ;
2016-07-18 14:31:15 +02:00
if ( ImGui : : Button ( buf , ImVec2 ( - 1.0f , 0.0f ) ) )
printf ( " Pressed '%s' \n " , buf ) ;
2015-07-22 01:00:28 +02:00
}
ImGui : : EndChild ( ) ;
ImGui : : PopStyleVar ( ) ;
ImGui : : TreePop ( ) ;
}
2015-11-29 22:02:15 +01:00
if ( ImGui : : TreeNode ( " Widgets Width " ) )
2015-07-22 01:00:28 +02:00
{
static float f = 0.0f ;
2016-03-26 15:38:52 +01:00
ImGui : : Text ( " PushItemWidth(100) " ) ;
2016-01-06 01:24:49 +01:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Fixed width. " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PushItemWidth ( 100 ) ;
2015-08-30 18:38:42 +02:00
ImGui : : DragFloat ( " float##1 " , & f ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PopItemWidth ( ) ;
2016-01-06 01:24:49 +01:00
ImGui : : Text ( " PushItemWidth(GetWindowWidth() * 0.5f) " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Half of window width. " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PushItemWidth ( ImGui : : GetWindowWidth ( ) * 0.5f ) ;
2015-08-30 18:38:42 +02:00
ImGui : : DragFloat ( " float##2 " , & f ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PopItemWidth ( ) ;
2016-01-06 01:24:49 +01: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-08-30 16:35:59 +02:00
ImGui : : PushItemWidth ( ImGui : : GetContentRegionAvailWidth ( ) * 0.5f ) ;
2015-08-30 18:38:42 +02:00
ImGui : : DragFloat ( " float##3 " , & f ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PopItemWidth ( ) ;
2016-01-06 01:24:49 +01:00
ImGui : : Text ( " PushItemWidth(-100) " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Align to right edge minus 100 " ) ;
2015-08-30 16:35:59 +02:00
ImGui : : PushItemWidth ( - 100 ) ;
2015-08-30 18:38:42 +02:00
ImGui : : DragFloat ( " float##4 " , & f ) ;
2015-08-30 16:35:59 +02:00
ImGui : : PopItemWidth ( ) ;
2016-01-06 01:24:49 +01:00
ImGui : : Text ( " PushItemWidth(-1) " ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Align to right edge " ) ;
ImGui : : PushItemWidth ( - 1 ) ;
ImGui : : DragFloat ( " float##5 " , & f ) ;
ImGui : : PopItemWidth ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Basic Horizontal Layout " ) )
{
ImGui : : TextWrapped ( " (Use ImGui::SameLine() to keep adding items to the right of the preceeding item) " ) ;
// 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
ImGui : : AlignFirstTextHeightToWidgets ( ) ;
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-24 13:50:18 +02:00
ImGui : : Text ( " Aligned " ) ;
2015-07-22 01:00:28 +02: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-24 13:50:18 +02:00
ImGui : : SliderFloat ( " Z " , & f2 , 0.0f , 5.0f ) ;
2015-07-22 01:00:28 +02: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-24 13:50:18 +02:00
//if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i);
2015-07-22 01:00:28 +02: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-10 11:26:09 +02: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-07-22 01:00:28 +02: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 ( ) ;
if ( ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( " Group hovered " ) ;
ImGui : : SameLine ( ) ;
ImGui : : Button ( " EEE " ) ;
ImGui : : EndGroup ( ) ;
}
// 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 ( ) ;
ImGui : : ListBoxHeader ( " List " , size ) ;
ImGui : : Selectable ( " Selected " , true ) ;
ImGui : : Selectable ( " Not Selected " , false ) ;
ImGui : : ListBoxFooter ( ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Text Baseline Alignment " ) )
{
2015-08-24 13:50:18 +02: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-07-22 01:00:28 +02:00
2015-08-24 13:50:18 +02:00
ImGui : : Text ( " One \n Two \n Three " ) ; ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02: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-25 17:03:49 +02:00
ImGui : : Button ( " HOP##1 " ) ; ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : Text ( " Banana " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Hello \n World " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Banana " ) ;
2016-06-25 17:03:49 +02:00
ImGui : : Button ( " HOP##2 " ) ; ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : Text ( " Hello \n World " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Banana " ) ;
2016-06-25 17:03:49 +02:00
ImGui : : Button ( " TEST##1 " ) ; ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : Text ( " TEST " ) ; ImGui : : SameLine ( ) ;
2016-06-25 17:03:49 +02:00
ImGui : : SmallButton ( " TEST##2 " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : AlignFirstTextHeightToWidgets ( ) ; // If your line starts with text, call this to align it to upcoming widgets.
ImGui : : Text ( " Text aligned to Widget " ) ; ImGui : : SameLine ( ) ;
2016-06-25 17:03:49 +02:00
ImGui : : Button ( " Widget##1 " ) ; ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : Text ( " Widget " ) ; ImGui : : SameLine ( ) ;
2016-06-25 17:03:49 +02:00
ImGui : : SmallButton ( " Widget##2 " ) ;
2015-07-22 01:00:28 +02:00
2015-11-29 22:02:15 +01:00
// Tree
const float spacing = ImGui : : GetStyle ( ) . ItemInnerSpacing . x ;
2016-03-26 15:38:52 +01:00
ImGui : : Button ( " Button##1 " ) ;
ImGui : : SameLine ( 0.0f , spacing ) ;
2015-11-29 22:02:15 +01:00
if ( ImGui : : TreeNode ( " Node##1 " ) ) { for ( int i = 0 ; i < 6 ; i + + ) ImGui : : BulletText ( " Item %d.. " , i ) ; ImGui : : TreePop ( ) ; } // Dummy tree data
ImGui : : AlignFirstTextHeightToWidgets ( ) ; // 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-02 12:32:16 +02: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-11-29 22:02:15 +01:00
ImGui : : SameLine ( 0.0f , spacing ) ; ImGui : : Button ( " Button##2 " ) ;
2016-05-02 12:32:16 +02:00
if ( node_open ) { for ( int i = 0 ; i < 6 ; i + + ) ImGui : : BulletText ( " Item %d.. " , i ) ; ImGui : : TreePop ( ) ; } // Dummy tree data
2015-11-29 22:02:15 +01:00
2015-12-14 00:41:02 +01:00
// Bullet
2016-03-26 15:38:52 +01:00
ImGui : : Button ( " Button##3 " ) ;
ImGui : : SameLine ( 0.0f , spacing ) ;
2015-12-14 00:41:02 +01:00
ImGui : : BulletText ( " Bullet text " ) ;
ImGui : : AlignFirstTextHeightToWidgets ( ) ;
ImGui : : BulletText ( " Node " ) ;
ImGui : : SameLine ( 0.0f , spacing ) ; ImGui : : Button ( " Button##4 " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Scrolling " ) )
{
2015-08-29 14:31:30 +02:00
ImGui : : TextWrapped ( " (Use SetScrollHere() or SetScrollFromPosY() to scroll to a given position.) " ) ;
2015-07-22 01:00:28 +02:00
static bool track = true ;
static int track_line = 50 , scroll_to_px = 200 ;
ImGui : : Checkbox ( " Track " , & track ) ;
2016-05-07 18:10:32 +02:00
ImGui : : PushItemWidth ( 100 ) ;
2015-08-30 19:33:38 +02:00
ImGui : : SameLine ( 130 ) ; track | = ImGui : : DragInt ( " ##line " , & track_line , 0.25f , 0 , 99 , " Line %.0f " ) ;
2015-07-22 01:00:28 +02:00
bool scroll_to = ImGui : : Button ( " Scroll To " ) ;
ImGui : : SameLine ( 130 ) ; scroll_to | = ImGui : : DragInt ( " ##pos_y " , & scroll_to_px , 1.00f , 0 , 9999 , " y = %.0f px " ) ;
2016-05-07 18:10:32 +02:00
ImGui : : PopItemWidth ( ) ;
2015-07-22 01:00:28 +02: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-11-29 11:20:50 +01:00
ImGui : : BeginChild ( ImGui : : GetID ( ( void * ) ( intptr_t ) i ) , ImVec2 ( ImGui : : GetWindowWidth ( ) * 0.17f , 200.0f ) , true ) ;
2015-07-22 01:00:28 +02: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 ) ;
}
}
ImGui : : EndChild ( ) ;
ImGui : : EndGroup ( ) ;
}
ImGui : : TreePop ( ) ;
}
2015-08-30 17:38:55 +02: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. " ) ;
2015-08-30 19:07:51 +02:00
ImGui : : Bullet ( ) ; ImGui : : TextWrapped ( " You may want to explicitly specify content width by calling SetNextWindowContentWidth() before Begin(). " ) ;
2015-09-30 21:15:47 +02:00
static int lines = 7 ;
ImGui : : SliderInt ( " Lines " , & lines , 1 , 15 ) ;
2015-08-30 19:43:42 +02:00
ImGui : : PushStyleVar ( ImGuiStyleVar_FrameRounding , 3.0f ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 2.0f , 1.0f ) ) ;
ImGui : : BeginChild ( " scrolling " , ImVec2 ( 0 , ImGui : : GetItemsLineHeightWithSpacing ( ) * 7 + 30 ) , true , ImGuiWindowFlags_HorizontalScrollbar ) ;
2015-09-30 21:15:47 +02:00
for ( int line = 0 ; line < lines ; line + + )
2015-08-30 17:38:55 +02:00
{
// Display random stuff
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 ] ;
2015-08-30 19:55:46 +02:00
const char * label = ( ! ( n % 15 ) ) ? " FizzBuzz " : ( ! ( n % 3 ) ) ? " Fizz " : ( ! ( n % 5 ) ) ? " Buzz " : ( sprintf ( num_buf , " %d " , n ) , num_buf ) ;
2015-08-30 17:38:55 +02:00
float hue = n * 0.05f ;
ImGui : : PushStyleColor ( ImGuiCol_Button , ImColor : : HSV ( hue , 0.6f , 0.6f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonHovered , ImColor : : HSV ( hue , 0.7f , 0.7f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonActive , ImColor : : HSV ( hue , 0.8f , 0.8f ) ) ;
2015-08-30 19:43:42 +02:00
ImGui : : Button ( label , ImVec2 ( 40.0f + sinf ( ( float ) ( line + n ) ) * 20.0f , 0.0f ) ) ;
2015-08-30 17:38:55 +02:00
ImGui : : PopStyleColor ( 3 ) ;
ImGui : : PopID ( ) ;
}
}
ImGui : : EndChild ( ) ;
2015-08-30 19:43:42 +02:00
ImGui : : PopStyleVar ( 2 ) ;
2015-08-30 19:33:38 +02:00
float scroll_x_delta = 0.0f ;
ImGui : : SmallButton ( " << " ) ; if ( ImGui : : IsItemActive ( ) ) scroll_x_delta = - ImGui : : GetIO ( ) . DeltaTime * 1000.0f ;
2016-03-26 15:38:52 +01:00
ImGui : : SameLine ( ) ; ImGui : : Text ( " Scroll from code " ) ; ImGui : : SameLine ( ) ;
2015-08-30 19:33:38 +02:00
ImGui : : SmallButton ( " >> " ) ; if ( ImGui : : IsItemActive ( ) ) scroll_x_delta = + ImGui : : GetIO ( ) . DeltaTime * 1000.0f ;
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 ( ) ;
}
2015-08-30 17:38:55 +02:00
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02: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-11-29 11:29:06 +01:00
ImGui : : TextWrapped ( " (Click and drag) " ) ;
2015-07-22 01:00:28 +02:00
ImVec2 pos = ImGui : : GetCursorScreenPos ( ) ;
ImVec4 clip_rect ( pos . x , pos . y , pos . x + size . x , pos . y + size . y ) ;
2015-09-08 00:33:44 +02:00
ImGui : : InvisibleButton ( " ##dummy " , size ) ;
if ( ImGui : : IsItemActive ( ) & & ImGui : : IsMouseDragging ( ) ) { offset . x + = ImGui : : GetIO ( ) . MouseDelta . x ; offset . y + = ImGui : : GetIO ( ) . MouseDelta . y ; }
2015-11-29 11:29:06 +01:00
ImGui : : GetWindowDrawList ( ) - > AddRectFilled ( pos , ImVec2 ( pos . x + size . x , pos . y + size . y ) , ImColor ( 90 , 90 , 120 , 255 ) ) ;
2016-03-21 22:29:11 +01:00
ImGui : : GetWindowDrawList ( ) - > AddText ( ImGui : : GetFont ( ) , ImGui : : GetFontSize ( ) * 2.0f , ImVec2 ( pos . x + offset . x , pos . y + offset . y ) , ImColor ( 255 , 255 , 255 , 255 ) , " Line 1 hello \n Line 2 clip me! " , NULL , 0.0f , & clip_rect ) ;
2015-07-22 01:00:28 +02: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 } ;
if ( ImGui : : Button ( " Select.. " ) )
ImGui : : OpenPopup ( " select " ) ;
ImGui : : SameLine ( ) ;
ImGui : : Text ( selected_fish = = - 1 ? " <None> " : names [ selected_fish ] ) ;
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 ( ) ;
}
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.. " ) )
ImGui : : OpenPopup ( " popup from button " ) ;
if ( ImGui : : BeginPopup ( " popup from button " ) )
{
ShowExampleMenuFile ( ) ;
ImGui : : EndPopup ( ) ;
}
2015-11-16 22:43:42 +01:00
ImGui : : Spacing ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : TextWrapped ( " Below we are testing adding menu items to a regular window. It's rather unusual but should work! " ) ;
ImGui : : Separator ( ) ;
2016-03-26 15:38:52 +01:00
// 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.
2015-11-16 22:43:42 +01:00
// 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 " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : MenuItem ( " Menu item " , " CTRL+M " ) ;
2015-11-16 22:43:42 +01:00
if ( ImGui : : BeginMenu ( " Menu inside a regular window " ) )
2015-07-22 01:00:28 +02:00
{
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
}
2015-11-16 22:43:42 +01:00
ImGui : : PopID ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Context menus " ) )
{
static float value = 0.5f ;
ImGui : : Text ( " Value = %.3f (<-- right-click here) " , value ) ;
if ( ImGui : : BeginPopupContextItem ( " item context menu " ) )
{
2015-08-24 13:50:18 +02:00
if ( ImGui : : Selectable ( " Set to zero " ) ) value = 0.0f ;
if ( ImGui : : Selectable ( " Set to PI " ) ) value = 3.1415f ;
2015-07-22 01:00:28 +02:00
ImGui : : EndPopup ( ) ;
}
2016-05-12 23:13:54 +02:00
static ImVec4 color = ImColor ( 0.8f , 0.5f , 1.0f , 1.0f ) ;
2015-07-22 01:00:28 +02:00
ImGui : : ColorButton ( color ) ;
if ( ImGui : : BeginPopupContextItem ( " color context menu " ) )
{
ImGui : : Text ( " Edit color " ) ;
ImGui : : ColorEdit3 ( " ##edit " , ( float * ) & color ) ;
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
ImGui : : EndPopup ( ) ;
}
ImGui : : SameLine ( ) ; ImGui : : Text ( " (<-- right-click here) " ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Modals " ) )
2015-08-24 13:50:18 +02:00
{
2015-07-22 01:00:28 +02: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 ) )
{
ImGui : : Text ( " All those beautiful files will be deleted. \n This operation cannot be undone! \n \n " ) ;
ImGui : : Separator ( ) ;
2015-08-24 13:50:18 +02:00
2016-05-10 17:02:10 +02:00
//static int dummy_i = 0;
//ImGui::Combo("Combo", &dummy_i, "Delete\0Delete harder\0");
2015-07-22 01:00:28 +02: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 ( ) ; }
2016-07-20 00:02:59 +02:00
ImGui : : SetItemDefaultFocus ( ) ;
2015-07-22 01:00:28 +02: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 " ) )
{
2016-07-18 14:31:15 +02:00
ImGui : : Text ( " Hello from Stacked The First \n Using style.Colors[ImGuiCol_ModalWindowDarkening] for darkening. " ) ;
static int item = 1 ;
ImGui : : Combo ( " Combo " , & item , " aaaa \0 bbbb \0 cccc \0 dddd \0 eeee \0 \0 " ) ;
2015-07-22 01:00:28 +02:00
2016-07-18 14:31:15 +02:00
if ( ImGui : : Button ( " Add another modal.. " ) )
2015-07-22 01:00:28 +02:00
ImGui : : OpenPopup ( " Stacked 2 " ) ;
if ( ImGui : : BeginPopupModal ( " Stacked 2 " ) )
{
2016-07-18 14:31:15 +02:00
ImGui : : Text ( " Hello from Stacked The Second! \n We are piling a modal over another here, \n and also testing if the menu-bar works. " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
ImGui : : EndPopup ( ) ;
}
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
ImGui : : EndPopup ( ) ;
}
ImGui : : TreePop ( ) ;
}
}
if ( ImGui : : CollapsingHeader ( " Columns " ) )
{
// Basic columns
2015-11-28 17:44:09 +01:00
if ( ImGui : : TreeNode ( " Basic " ) )
2015-07-22 01:00:28 +02:00
{
2016-06-07 08:46:50 +02: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-28 17:44:09 +01:00
ImGui : : Separator ( ) ;
ImGui : : Text ( " ID " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Name " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Path " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Flags " ) ; ImGui : : NextColumn ( ) ;
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 ;
ImGui : : NextColumn ( ) ;
ImGui : : Text ( names [ i ] ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( paths [ i ] ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " .... " ) ; ImGui : : NextColumn ( ) ;
}
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
2015-07-22 01:00:28 +02:00
}
// Scrolling columns
/*
2015-11-28 17:44:09 +01:00
if ( ImGui : : TreeNode ( " Scrolling " ) )
2015-07-22 01:00:28 +02:00
{
2015-11-28 17:44:09 +01:00
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 ( ) ;
2015-07-22 01:00:28 +02:00
}
*/
// Create multiple items in a same cell before switching to next column
2015-11-28 17:44:09 +01:00
if ( ImGui : : TreeNode ( " Mixed items " ) )
{
ImGui : : Columns ( 3 , " mixed " ) ;
ImGui : : Separator ( ) ;
2015-07-22 01:00:28 +02:00
2015-11-28 17:44:09 +01:00
ImGui : : Text ( " Hello " ) ;
ImGui : : Button ( " Banana " ) ;
ImGui : : NextColumn ( ) ;
2015-07-22 01:00:28 +02:00
2015-11-28 17:44:09 +01:00
ImGui : : Text ( " ImGui " ) ;
ImGui : : Button ( " Apple " ) ;
static float foo = 1.0f ;
ImGui : : InputFloat ( " red " , & foo , 0.05f , 0 , 3 ) ;
ImGui : : Text ( " An extra line here. " ) ;
ImGui : : NextColumn ( ) ;
2015-07-22 01:00:28 +02:00
2015-11-28 17:44:09 +01:00
ImGui : : Text ( " Sailor " ) ;
ImGui : : Button ( " Corniflower " ) ;
static float bar = 1.0f ;
ImGui : : InputFloat ( " blue " , & bar , 0.05f , 0 , 3 ) ;
ImGui : : NextColumn ( ) ;
2015-07-22 01:00:28 +02:00
2015-11-28 17:44:09 +01: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 ( ) ;
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2015-08-30 16:35:59 +02:00
// Word wrapping
2015-11-28 17:44:09 +01: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-07-22 01:00:28 +02:00
2015-11-28 17:44:09 +01:00
if ( ImGui : : TreeNode ( " Borders " ) )
2015-07-22 01:00:28 +02:00
{
2015-11-28 17:44:09 +01: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 ) ;
if ( h_borders ) ImGui : : Separator ( ) ;
for ( int i = 0 ; i < 8 ; i + + )
2015-07-22 01:00:28 +02:00
{
2015-11-28 17:44:09 +01:00
ImGui : : Text ( " %c%c%c " , ' a ' + i , ' a ' + i , ' a ' + i ) ;
ImGui : : NextColumn ( ) ;
2015-07-22 01:00:28 +02:00
}
2015-11-28 17:44:09 +01:00
ImGui : : Columns ( 1 ) ;
if ( h_borders ) ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
2016-05-02 12:32:16 +02:00
bool node_open = ImGui : : TreeNode ( " Tree within single cell " ) ;
2016-07-18 14:31:15 +02:00
ImGui : : SameLine ( ) ; ShowHelpMarker ( " NB: Tree node must be poped before ending the cell. There's no storage of state per-cell. " ) ;
2016-05-02 12:32:16 +02:00
if ( node_open )
2015-11-28 17:44:09 +01:00
{
2016-03-26 15:38:52 +01:00
ImGui : : Columns ( 2 , " tree items " ) ;
2015-11-28 17:44:09 +01: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-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
}
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 ] ) ;
}
2016-08-03 20:55:54 +02:00
if ( ImGui : : CollapsingHeader ( " Inputs, Navigation & Focus " ) )
2015-07-22 01:00:28 +02:00
{
2016-07-18 14:31:15 +02:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
2016-07-20 00:02:59 +02:00
ImGui : : Checkbox ( " io.NavMovesMouse " , & io . NavMovesMouse ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Request ImGui to move your move cursor when using gamepad/keyboard navigation. NewFrame() will change io.MousePos and set the io.WantMoveMouse flag, your backend will need to apply the new mouse position. " ) ;
2016-07-18 14:31:15 +02:00
ImGui : : Checkbox ( " io.MouseDrawCursor " , & io . MouseDrawCursor ) ;
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Request ImGui to render a mouse cursor for you in software. Note that a mouse cursor rendered via regular GPU rendering will feel more laggy than hardware cursor, but will be more in sync with your other visuals. " ) ;
2016-08-03 20:55:54 +02:00
ImGui : : Text ( " WantCaptureMouse: %d " , io . WantCaptureMouse ) ;
ImGui : : Text ( " WantCaptureKeyboard: %d " , io . WantCaptureKeyboard ) ;
ImGui : : Text ( " WantTextInput: %d " , io . WantTextInput ) ;
ImGui : : Text ( " WantMoveMouse: %d " , io . WantMoveMouse ) ;
if ( ImGui : : TreeNode ( " Keyboard, Mouse & Navigation State " ) )
{
ImGui : : Text ( " Mouse pos: (%g, %g) " , io . MousePos . x , io . MousePos . y ) ;
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 " : " " ) ;
ImGui : : Text ( " NavUsable: %d, NavActive: %d " , io . NavUsable , io . NavActive ) ;
2016-08-03 23:23:04 +02: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 ] ) ; }
2016-08-03 20:55:54 +02: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-07-22 01:00:28 +02: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-24 13:50:18 +02:00
2015-07-22 01:00:28 +02:00
if ( focus_1 ) ImGui : : SetKeyboardFocusHere ( ) ;
ImGui : : InputText ( " 1 " , buf , IM_ARRAYSIZE ( buf ) ) ;
if ( ImGui : : IsItemActive ( ) ) has_focus = 1 ;
2015-08-24 13:50:18 +02:00
2015-07-22 01:00:28 +02: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 ( ) ;
if ( has_focus )
ImGui : : Text ( " Item with focus: %d " , has_focus ) ;
2015-08-24 13:50:18 +02:00
else
2015-07-22 01:00:28 +02:00
ImGui : : Text ( " Item with focus: <none> " ) ;
ImGui : : TextWrapped ( " Cursor & selection are preserved when refocusing last used item in code. " ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Dragging " ) )
{
ImGui : : TextWrapped ( " You can use ImGui::GetItemActiveDragDelta() to query for the dragged amount on any widget. " ) ;
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 ( ) ;
2016-07-18 14:31:15 +02:00
draw_list - > AddLine ( ImGui : : CalcItemRectClosestPoint ( io . MousePos , true , - 2.0f ) , io . MousePos , ImColor ( ImGui : : GetStyle ( ) . Colors [ ImGuiCol_Button ] ) , 4.0f ) ;
2015-07-22 01:00:28 +02:00
draw_list - > PopClipRect ( ) ;
ImVec2 value_raw = ImGui : : GetMouseDragDelta ( 0 , 0.0f ) ;
ImVec2 value_with_lock_threshold = ImGui : : GetMouseDragDelta ( 0 ) ;
2016-07-18 14:31:15 +02:00
ImVec2 mouse_delta = io . MouseDelta ;
2015-09-08 00:33:44 +02: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-07-22 01:00:28 +02:00
}
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Mouse cursors " ) )
{
ImGui : : Text ( " Hover to see mouse cursors: " ) ;
2016-07-18 14:31:15 +02: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. " ) ;
2015-07-22 01:00:28 +02:00
for ( int i = 0 ; i < ImGuiMouseCursor_Count_ ; i + + )
{
char label [ 32 ] ;
sprintf ( label , " Mouse cursor %d " , i ) ;
2015-08-24 13:50:18 +02:00
ImGui : : Bullet ( ) ; ImGui : : Selectable ( label , false ) ;
2016-07-20 00:02:59 +02:00
if ( ImGui : : IsItemHovered ( ) | | ImGui : : IsItemFocused ( ) )
2015-07-22 01:00:28 +02:00
ImGui : : SetMouseCursor ( i ) ;
}
ImGui : : TreePop ( ) ;
}
}
ImGui : : End ( ) ;
}
2015-08-05 17:31:03 +02:00
void ImGui : : ShowStyleEditor ( ImGuiStyle * ref )
{
ImGuiStyle & style = ImGui : : GetStyle ( ) ;
2016-05-12 20:59:20 +02:00
// You can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it compares to the default style)
const ImGuiStyle default_style ; // Default style
2015-08-05 17:31:03 +02:00
if ( ImGui : : Button ( " Revert Style " ) )
2016-05-12 20:59:20 +02:00
style = ref ? * ref : default_style ;
2015-08-05 17:31:03 +02:00
if ( ref )
{
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Save Style " ) )
* ref = style ;
}
ImGui : : PushItemWidth ( ImGui : : GetWindowWidth ( ) * 0.55f ) ;
if ( ImGui : : TreeNode ( " Rendering " ) )
{
ImGui : : Checkbox ( " Anti-aliased lines " , & style . AntiAliasedLines ) ;
ImGui : : Checkbox ( " Anti-aliased shapes " , & style . AntiAliasedShapes ) ;
2015-08-28 14:18:34 +02: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-13 15:03:26 +01: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-28 14:18:34 +02:00
ImGui : : PopItemWidth ( ) ;
2015-08-05 17:31:03 +02:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Sizes " ) )
{
ImGui : : SliderFloat2 ( " WindowPadding " , ( float * ) & style . WindowPadding , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " WindowRounding " , & style . WindowRounding , 0.0f , 16.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " ChildWindowRounding " , & style . ChildWindowRounding , 0.0f , 16.0f , " %.0f " ) ;
ImGui : : SliderFloat2 ( " FramePadding " , ( float * ) & style . FramePadding , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " FrameRounding " , & style . FrameRounding , 0.0f , 16.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-09-30 21:47:44 +02:00
ImGui : : SliderFloat ( " ScrollbarSize " , & style . ScrollbarSize , 1.0f , 20.0f , " %.0f " ) ;
2015-08-05 17:31:03 +02:00
ImGui : : SliderFloat ( " ScrollbarRounding " , & style . ScrollbarRounding , 0.0f , 16.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " GrabMinSize " , & style . GrabMinSize , 1.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " GrabRounding " , & style . GrabRounding , 0.0f , 16.0f , " %.0f " ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Colors " ) )
{
static int output_dest = 0 ;
static bool output_only_modified = false ;
2015-12-13 14:36:00 +01:00
if ( ImGui : : Button ( " Copy Colors " ) )
2015-08-05 17:31:03 +02:00
{
if ( output_dest = = 0 )
ImGui : : LogToClipboard ( ) ;
else
ImGui : : LogToTTY ( ) ;
ImGui : : LogText ( " ImGuiStyle& style = ImGui::GetStyle(); " IM_NEWLINE ) ;
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
{
const ImVec4 & col = style . Colors [ i ] ;
const char * name = ImGui : : GetStyleColName ( i ) ;
2016-05-12 20:59:20 +02:00
if ( ! output_only_modified | | memcmp ( & col , ( ref ? & ref - > Colors [ i ] : & default_style . Colors [ i ] ) , sizeof ( ImVec4 ) ) ! = 0 )
2015-08-08 19:29:11 +02:00
ImGui : : LogText ( " style.Colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff); " IM_NEWLINE , name , 22 - ( int ) strlen ( name ) , " " , col . x , col . y , col . z , col . w ) ;
2015-08-05 17:31:03 +02:00
}
ImGui : : LogFinish ( ) ;
}
2016-08-18 20:00:23 +02:00
ImGui : : SameLine ( ) ; ImGui : : PushItemWidth ( 120 ) ; ImGui : : Combo ( " ##output_type " , & output_dest , " To Clipboard \0 To TTY \0 " ) ; ImGui : : PopItemWidth ( ) ;
2015-08-05 17:31:03 +02:00
ImGui : : SameLine ( ) ; ImGui : : Checkbox ( " Only Modified Fields " , & output_only_modified ) ;
static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB ;
ImGui : : RadioButton ( " RGB " , & edit_mode , ImGuiColorEditMode_RGB ) ;
ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " HSV " , & edit_mode , ImGuiColorEditMode_HSV ) ;
ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " HEX " , & edit_mode , ImGuiColorEditMode_HEX ) ;
//ImGui::Text("Tip: Click on colored square to change edit mode.");
static ImGuiTextFilter filter ;
filter . Draw ( " Filter colors " , 200 ) ;
2016-04-04 01:37:02 +02:00
ImGui : : BeginChild ( " #colors " , ImVec2 ( 0 , 300 ) , true , ImGuiWindowFlags_AlwaysVerticalScrollbar ) ;
2015-08-05 17:31:03 +02:00
ImGui : : PushItemWidth ( - 160 ) ;
ImGui : : ColorEditMode ( edit_mode ) ;
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
{
const char * name = ImGui : : GetStyleColName ( i ) ;
if ( ! filter . PassFilter ( name ) )
continue ;
ImGui : : PushID ( i ) ;
ImGui : : ColorEdit4 ( name , ( float * ) & style . Colors [ i ] , true ) ;
2016-05-12 20:59:20 +02:00
if ( memcmp ( & style . Colors [ i ] , ( ref ? & ref - > Colors [ i ] : & default_style . Colors [ i ] ) , sizeof ( ImVec4 ) ) ! = 0 )
2015-08-05 17:31:03 +02:00
{
2016-05-12 20:59:20 +02:00
ImGui : : SameLine ( ) ; if ( ImGui : : Button ( " Revert " ) ) style . Colors [ i ] = ref ? ref - > Colors [ i ] : default_style . Colors [ i ] ;
2015-08-05 17:31:03 +02:00
if ( ref ) { ImGui : : SameLine ( ) ; if ( ImGui : : Button ( " Save " ) ) ref - > Colors [ i ] = style . Colors [ i ] ; }
}
ImGui : : PopID ( ) ;
}
ImGui : : PopItemWidth ( ) ;
ImGui : : EndChild ( ) ;
ImGui : : TreePop ( ) ;
}
2016-05-03 20:22:35 +02:00
if ( ImGui : : TreeNode ( " Fonts " , " Fonts (%d) " , ImGui : : GetIO ( ) . Fonts - > Fonts . Size ) )
{
ImGui : : SameLine ( ) ; ShowHelpMarker ( " Tip: Load fonts with io.Fonts->AddFontFromFileTTF() \n before calling io.Fonts->GetTex* functions. " ) ;
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 ] ;
ImGui : : BulletText ( " Font %d: \' %s \' , %.2f px, %d glyphs " , i , font - > ConfigData ? font - > ConfigData [ 0 ] . Name : " " , font - > FontSize , font - > Glyphs . Size ) ;
ImGui : : TreePush ( ( void * ) ( intptr_t ) i ) ;
if ( i > 0 ) { ImGui : : SameLine ( ) ; if ( ImGui : : SmallButton ( " Set as default " ) ) { atlas - > Fonts [ i ] = atlas - > Fonts [ 0 ] ; atlas - > Fonts [ 0 ] = font ; } }
ImGui : : PushFont ( font ) ;
ImGui : : Text ( " The quick brown fox jumps over the lazy dog " ) ;
ImGui : : PopFont ( ) ;
if ( ImGui : : TreeNode ( " Details " ) )
{
ImGui : : DragFloat ( " font scale " , & font - > Scale , 0.005f , 0.3f , 2.0f , " %.1f " ) ; // scale only this font
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 ) ;
for ( int config_i = 0 ; config_i < font - > ConfigDataCount ; config_i + + )
{
ImFontConfig * cfg = & font - > ConfigData [ config_i ] ;
ImGui : : BulletText ( " Input %d: \' %s \' \n Oversample: (%d,%d), PixelSnapH: %d " , config_i , cfg - > Name , cfg - > OversampleH , cfg - > OversampleV , cfg - > PixelSnapH ) ;
}
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
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-05 17:31:03 +02:00
ImGui : : PopItemWidth ( ) ;
}
2015-07-22 01:00:28 +02: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 ;
2016-08-07 19:07:24 +02:00
static bool b = true ;
2015-07-22 01:00:28 +02: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 " ) ;
2016-08-07 19:07:24 +02:00
ImGui : : Checkbox ( " Check " , & b ) ;
2015-07-22 01:00:28 +02:00
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Colors " ) )
{
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
ImGui : : MenuItem ( ImGui : : GetStyleColName ( ( ImGuiCol ) i ) ) ;
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Disabled " , false ) ) // Disabled
{
IM_ASSERT ( 0 ) ;
}
if ( ImGui : : MenuItem ( " Checked " , NULL , true ) ) { }
if ( ImGui : : MenuItem ( " Quit " , " Alt+F4 " ) ) { }
}
2016-05-02 12:32:16 +02:00
static void ShowExampleAppAutoResize ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
2016-05-02 12:32:16 +02:00
if ( ! ImGui : : Begin ( " Example: Auto-resizing window " , p_open , ImGuiWindowFlags_AlwaysAutoResize ) )
2015-07-22 01:00:28 +02:00
{
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 ( ) ;
}
2016-05-21 22:53:08 +02:00
static void ShowExampleAppConstrainedResize ( bool * p_open )
{
struct CustomConstraints // Helper functions to demonstrate programmatic constraints
{
static void Square ( ImGuiSizeConstraintCallbackData * data ) { data - > DesiredSize = ImVec2 ( IM_MAX ( data - > DesiredSize . x , data - > DesiredSize . y ) , IM_MAX ( data - > DesiredSize . x , data - > DesiredSize . y ) ) ; }
2016-05-21 23:13:11 +02:00
static void Step ( ImGuiSizeConstraintCallbackData * 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 ) ; }
2016-05-21 22:53:08 +02:00
} ;
static int type = 0 ;
2016-05-28 14:02:14 +02:00
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 ( 300 , 0 ) , ImVec2 ( 400 , FLT_MAX ) ) ; // Width 300-400
if ( type = = 4 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0 , 0 ) , ImVec2 ( FLT_MAX , FLT_MAX ) , CustomConstraints : : Square ) ; // Always Square
if ( type = = 5 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0 , 0 ) , ImVec2 ( FLT_MAX , FLT_MAX ) , CustomConstraints : : Step , ( void * ) 100 ) ; // Fixed Step
2016-05-21 22:53:08 +02:00
if ( ImGui : : Begin ( " Example: Constrained Resize " , p_open ) )
{
const char * desc [ ] =
{
" Resize vertical only " ,
" Resize horizontal only " ,
" Width > 100, Height > 100 " ,
" Width 300-400 " ,
" Custom: Always Square " ,
" Custom: Fixed Steps (100) " ,
} ;
ImGui : : Combo ( " Constraint " , & type , desc , IM_ARRAYSIZE ( desc ) ) ;
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 ) ) ;
for ( int i = 0 ; i < 10 ; i + + )
ImGui : : Text ( " Hello, sailor! Making this line long enough for the example. " ) ;
}
ImGui : : End ( ) ;
}
2016-05-02 12:32:16 +02:00
static void ShowExampleAppFixedOverlay ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
ImGui : : SetNextWindowPos ( ImVec2 ( 10 , 10 ) ) ;
2016-07-30 18:06:05 +02:00
if ( ! ImGui : : Begin ( " Example: Fixed Overlay " , p_open , ImVec2 ( 0 , 0 ) , 0.3f , ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoNavInputs ) )
2015-07-22 01:00:28 +02:00
{
ImGui : : End ( ) ;
return ;
}
ImGui : : Text ( " Simple overlay \n on the top-left side of the screen. " ) ;
ImGui : : Separator ( ) ;
2015-08-24 13:50:18 +02:00
ImGui : : Text ( " Mouse Position: (%.1f,%.1f) " , ImGui : : GetIO ( ) . MousePos . x , ImGui : : GetIO ( ) . MousePos . y ) ;
2015-07-22 01:00:28 +02:00
ImGui : : End ( ) ;
}
2016-05-21 20:50:15 +02:00
static void ShowExampleAppManipulatingWindowTitle ( bool * )
2015-07-22 01:00:28 +02:00
{
// By default, Windows are uniquely identified by their title.
// You can use the "##" and "###" markers to manipulate the display/ID. Read FAQ at the top of this file!
// Using "##" to display same title but have unique identifier.
ImGui : : SetNextWindowPos ( ImVec2 ( 100 , 100 ) , ImGuiSetCond_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 ) , ImGuiSetCond_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 ] , rand ( ) ) ;
ImGui : : SetNextWindowPos ( ImVec2 ( 100 , 300 ) , ImGuiSetCond_FirstUseEver ) ;
ImGui : : Begin ( buf ) ;
ImGui : : Text ( " This window has a changing title. " ) ;
ImGui : : End ( ) ;
}
2016-05-02 12:32:16 +02:00
static void ShowExampleAppCustomRendering ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
2015-12-27 19:49:31 +01:00
ImGui : : SetNextWindowSize ( ImVec2 ( 350 , 560 ) , ImGuiSetCond_FirstUseEver ) ;
2016-05-02 12:32:16 +02:00
if ( ! ImGui : : Begin ( " Example: Custom rendering " , p_open ) )
2015-07-22 01:00:28 +02:00
{
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)
2015-12-27 19:49:31 +01:00
// In this example we are not using the maths operators!
2015-07-22 01:00:28 +02:00
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
2015-12-27 19:49:31 +01:00
// Primitives
ImGui : : Text ( " Primitives " ) ;
static float sz = 36.0f ;
static ImVec4 col = ImVec4 ( 1.0f , 1.0f , 0.4f , 1.0f ) ;
2016-03-26 15:38:52 +01:00
ImGui : : DragFloat ( " Size " , & sz , 0.2f , 2.0f , 72.0f , " %.0f " ) ;
2015-12-27 19:49:31 +01:00
ImGui : : ColorEdit3 ( " Color " , & col . x ) ;
2015-07-22 01:00:28 +02:00
{
2015-12-27 19:49:31 +01:00
const ImVec2 p = ImGui : : GetCursorScreenPos ( ) ;
const ImU32 col32 = ImColor ( col ) ;
float x = p . x + 4.0f , y = p . y + 4.0f , spacing = 8.0f ;
2016-03-21 21:56:23 +01:00
for ( int n = 0 ; n < 2 ; n + + )
{
float thickness = ( n = = 0 ) ? 1.0f : 4.0f ;
draw_list - > AddCircle ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , sz * 0.5f , col32 , 20 , thickness ) ; x + = sz + spacing ;
draw_list - > AddRect ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col32 , 0.0f , ~ 0 , thickness ) ; x + = sz + spacing ;
draw_list - > AddRect ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col32 , 10.0f , ~ 0 , thickness ) ; x + = sz + spacing ;
2016-03-22 20:10:06 +01:00
draw_list - > AddTriangle ( ImVec2 ( x + sz * 0.5f , y ) , ImVec2 ( x + sz , y + sz - 0.5f ) , ImVec2 ( x , y + sz - 0.5f ) , col32 , thickness ) ; x + = sz + spacing ;
2016-03-21 21:56:23 +01:00
draw_list - > AddLine ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y ) , col32 , thickness ) ; x + = sz + spacing ;
draw_list - > AddLine ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col32 , thickness ) ; x + = sz + spacing ;
draw_list - > AddLine ( ImVec2 ( x , y ) , ImVec2 ( x , y + sz ) , col32 , thickness ) ; x + = spacing ;
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 , thickness ) ;
x = p . x + 4 ;
y + = sz + spacing ;
}
2015-12-27 19:49:31 +01:00
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 ;
2016-03-22 20:10:06 +01:00
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 ;
2015-12-27 19:49:31 +01:00
draw_list - > AddRectFilledMultiColor ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , ImColor ( 0 , 0 , 0 ) , ImColor ( 255 , 0 , 0 ) , ImColor ( 255 , 255 , 0 ) , ImColor ( 0 , 255 , 0 ) ) ;
2016-03-21 21:56:23 +01:00
ImGui : : Dummy ( ImVec2 ( ( sz + spacing ) * 8 , ( sz + spacing ) * 3 ) ) ;
2015-12-27 19:49:31 +01: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()
// However you can 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 ) , ImColor ( 50 , 50 , 50 ) , ImColor ( 50 , 50 , 60 ) , ImColor ( 60 , 60 , 70 ) , ImColor ( 50 , 50 , 60 ) ) ;
draw_list - > AddRect ( canvas_pos , ImVec2 ( canvas_pos . x + canvas_size . x , canvas_pos . y + canvas_size . y ) , ImColor ( 255 , 255 , 255 ) ) ;
bool adding_preview = false ;
ImGui : : InvisibleButton ( " canvas " , canvas_size ) ;
if ( ImGui : : IsItemHovered ( ) )
2015-07-22 01:00:28 +02:00
{
2015-12-27 19:49:31 +01:00
ImVec2 mouse_pos_in_canvas = ImVec2 ( ImGui : : GetIO ( ) . MousePos . x - canvas_pos . x , ImGui : : GetIO ( ) . MousePos . y - canvas_pos . y ) ;
if ( ! adding_line & & ImGui : : IsMouseClicked ( 0 ) )
{
points . push_back ( mouse_pos_in_canvas ) ;
adding_line = true ;
}
if ( adding_line )
{
adding_preview = true ;
points . push_back ( mouse_pos_in_canvas ) ;
if ( ! ImGui : : GetIO ( ) . MouseDown [ 0 ] )
adding_line = adding_preview = false ;
}
if ( ImGui : : IsMouseClicked ( 1 ) & & ! points . empty ( ) )
{
2015-07-22 01:00:28 +02:00
adding_line = adding_preview = false ;
2015-12-27 19:49:31 +01:00
points . pop_back ( ) ;
points . pop_back ( ) ;
}
2015-07-22 01:00:28 +02:00
}
2016-04-26 11:03:51 +02:00
draw_list - > PushClipRect ( canvas_pos , ImVec2 ( canvas_pos . x + canvas_size . x , canvas_pos . y + canvas_size . y ) ) ; // clip lines within the canvas (if we resize it, etc.)
2015-12-27 19:49:31 +01:00
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 ) , 0xFF00FFFF , 2.0f ) ;
draw_list - > PopClipRect ( ) ;
if ( adding_preview )
2015-07-22 01:00:28 +02:00
points . pop_back ( ) ;
}
ImGui : : End ( ) ;
}
// 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 ( ) ;
2015-12-30 11:55:37 +01:00
memset ( InputBuf , 0 , sizeof ( InputBuf ) ) ;
2015-07-22 01:00:28 +02:00
HistoryPos = - 1 ;
Commands . push_back ( " HELP " ) ;
Commands . push_back ( " HISTORY " ) ;
Commands . push_back ( " CLEAR " ) ;
Commands . push_back ( " CLASSIFY " ) ; // "classify" is here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
2016-03-02 23:34:29 +01:00
AddLog ( " Welcome to ImGui! " ) ;
2015-07-22 01:00:28 +02:00
}
~ ExampleAppConsole ( )
{
ClearLog ( ) ;
2016-02-24 11:50:21 +01:00
for ( int i = 0 ; i < History . Size ; i + + )
2015-08-24 13:50:18 +02:00
free ( History [ i ] ) ;
2015-07-22 01:00:28 +02:00
}
2016-02-08 08:44:45 +01: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-02-24 11:50:21 +01: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 ) ; }
2016-02-08 08:44:45 +01:00
2015-07-22 01:00:28 +02:00
void ClearLog ( )
{
2015-08-24 13:50:18 +02:00
for ( int i = 0 ; i < Items . Size ; i + + )
free ( Items [ i ] ) ;
2015-07-22 01:00:28 +02:00
Items . clear ( ) ;
ScrollToBottom = true ;
}
2015-08-08 20:26:22 +02:00
void AddLog ( const char * fmt , . . . ) IM_PRINTFARGS ( 2 )
2015-07-22 01:00:28 +02: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-08 08:44:45 +01:00
Items . push_back ( Strdup ( buf ) ) ;
2015-07-22 01:00:28 +02:00
ScrollToBottom = true ;
}
2016-05-02 12:32:16 +02:00
void Draw ( const char * title , bool * p_open )
2015-07-22 01:00:28 +02:00
{
ImGui : : SetNextWindowSize ( ImVec2 ( 520 , 600 ) , ImGuiSetCond_FirstUseEver ) ;
2016-05-02 12:32:16 +02:00
if ( ! ImGui : : Begin ( title , p_open ) )
2015-07-22 01:00:28 +02:00
{
ImGui : : End ( ) ;
return ;
}
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-24 13:50:18 +02: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 ( ) ;
if ( ImGui : : SmallButton ( " Add Dummy Error " ) ) AddLog ( " [error] something went wrong " ) ; ImGui : : SameLine ( ) ;
2016-05-15 18:08:41 +02:00
if ( ImGui : : SmallButton ( " Clear " ) ) ClearLog ( ) ; ImGui : : SameLine ( ) ;
if ( ImGui : : SmallButton ( " Scroll to bottom " ) ) ScrollToBottom = true ;
2015-07-22 01:00:28 +02: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 ( ) ;
2015-08-30 17:38:55 +02:00
ImGui : : BeginChild ( " ScrollingRegion " , ImVec2 ( 0 , - ImGui : : GetItemsLineHeightWithSpacing ( ) ) , false , ImGuiWindowFlags_HorizontalScrollbar ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : BeginPopupContextWindow ( ) )
{
if ( ImGui : : Selectable ( " Clear " ) ) ClearLog ( ) ;
ImGui : : EndPopup ( ) ;
}
2016-05-16 19:22:51 +02: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++)
// However take 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.
// 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-07-22 01:00:28 +02:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 4 , 1 ) ) ; // Tighten spacing
for ( int i = 0 ; i < Items . Size ; i + + )
{
const char * item = Items [ i ] ;
if ( ! filter . PassFilter ( item ) )
continue ;
2016-05-16 19:22:51 +02:00
ImVec4 col = ImVec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) ; // A better implementation may store a type per-item. For the sample let's just parse the text.
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-07-22 01:00:28 +02:00
ImGui : : PushStyleColor ( ImGuiCol_Text , col ) ;
ImGui : : TextUnformatted ( item ) ;
ImGui : : PopStyleColor ( ) ;
}
if ( ScrollToBottom )
ImGui : : SetScrollHere ( ) ;
ScrollToBottom = false ;
ImGui : : PopStyleVar ( ) ;
ImGui : : EndChild ( ) ;
ImGui : : Separator ( ) ;
// Command-line
2016-07-30 19:17:26 +02:00
bool reclaim_focus = false ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : InputText ( " Input " , InputBuf , IM_ARRAYSIZE ( InputBuf ) , ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory , & TextEditCallbackStub , ( void * ) this ) )
{
char * input_end = InputBuf + strlen ( InputBuf ) ;
while ( input_end > InputBuf & & input_end [ - 1 ] = = ' ' ) input_end - - ; * input_end = 0 ;
if ( InputBuf [ 0 ] )
ExecCommand ( InputBuf ) ;
strcpy ( InputBuf , " " ) ;
2016-07-30 19:17:26 +02:00
reclaim_focus = true ;
2015-07-22 01:00:28 +02:00
}
2016-07-30 19:17:26 +02:00
// Demonstrate keeping focus on the input box
ImGui : : SetItemDefaultFocus ( ) ;
if ( ImGui : : IsItemHovered ( ) | | reclaim_focus )
2015-12-27 21:41:01 +01:00
ImGui : : SetKeyboardFocusHere ( - 1 ) ; // Auto focus previous widget
2015-07-22 01:00:28 +02: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 - - )
2015-08-05 17:28:19 +02:00
if ( Stricmp ( History [ i ] , command_line ) = = 0 )
2015-07-22 01:00:28 +02:00
{
free ( History [ i ] ) ;
History . erase ( History . begin ( ) + i ) ;
break ;
}
2016-02-08 08:44:45 +01:00
History . push_back ( Strdup ( command_line ) ) ;
2015-07-22 01:00:28 +02:00
// Process command
2015-08-05 17:28:19 +02:00
if ( Stricmp ( command_line , " CLEAR " ) = = 0 )
2015-07-22 01:00:28 +02:00
{
ClearLog ( ) ;
}
2015-08-05 17:28:19 +02:00
else if ( Stricmp ( command_line , " HELP " ) = = 0 )
2015-07-22 01:00:28 +02:00
{
AddLog ( " Commands: " ) ;
for ( int i = 0 ; i < Commands . Size ; i + + )
AddLog ( " - %s " , Commands [ i ] ) ;
}
2015-08-05 17:28:19 +02:00
else if ( Stricmp ( command_line , " HISTORY " ) = = 0 )
2015-07-22 01:00:28 +02:00
{
for ( int i = History . Size > = 10 ? History . Size - 10 : 0 ; i < History . Size ; i + + )
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 ] ;
2015-07-22 01:13:56 +02:00
if ( c = = ' ' | | c = = ' \t ' | | c = = ' , ' | | c = = ' ; ' )
2015-07-22 01:00:28 +02:00
break ;
word_start - - ;
}
// Build a list of candidates
ImVector < const char * > candidates ;
for ( int i = 0 ; i < Commands . Size ; i + + )
2015-08-05 17:28:19 +02:00
if ( Strnicmp ( Commands [ i ] , word_start , ( int ) ( word_end - word_start ) ) = = 0 )
2015-07-22 01:00:28 +02:00
candidates . push_back ( Commands [ i ] ) ;
if ( candidates . Size = = 0 )
{
// No match
2015-08-08 19:29:11 +02:00
AddLog ( " No match for \" %.*s \" ! \n " , ( int ) ( word_end - word_start ) , word_start ) ;
2015-07-22 01:00:28 +02: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 ] ) ;
else if ( c ! = toupper ( candidates [ i ] [ match_len ] ) )
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-04 23:17:53 +02:00
data - > CursorPos = data - > SelectionStart = data - > SelectionEnd = data - > BufTextLen = ( int ) snprintf ( data - > Buf , ( size_t ) data - > BufSize , " %s " , ( HistoryPos > = 0 ) ? History [ HistoryPos ] : " " ) ;
2015-07-22 01:00:28 +02:00
data - > BufDirty = true ;
}
}
}
return 0 ;
}
} ;
2016-05-02 12:32:16 +02:00
static void ShowExampleAppConsole ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
static ExampleAppConsole console ;
2016-05-02 12:32:16 +02:00
console . Draw ( " Example: Console " , p_open ) ;
2015-08-14 04:59:37 +02:00
}
// Usage:
// static ExampleAppLog my_log;
// my_log.AddLog("Hello %d world\n", 123);
// my_log.Draw("title");
struct ExampleAppLog
{
ImGuiTextBuffer Buf ;
2015-08-14 05:47:50 +02:00
ImGuiTextFilter Filter ;
ImVector < int > LineOffsets ; // Index to lines offset
2015-08-14 04:59:37 +02:00
bool ScrollToBottom ;
2015-08-14 05:47:50 +02:00
void Clear ( ) { Buf . clear ( ) ; LineOffsets . clear ( ) ; }
2015-08-14 04:59:37 +02:00
void AddLog ( const char * fmt , . . . ) IM_PRINTFARGS ( 2 )
{
2015-08-14 05:47:50 +02:00
int old_size = Buf . size ( ) ;
2015-08-14 04:59:37 +02:00
va_list args ;
va_start ( args , fmt ) ;
Buf . appendv ( fmt , args ) ;
va_end ( args ) ;
2015-08-14 05:47:50 +02:00
for ( int new_size = Buf . size ( ) ; old_size < new_size ; old_size + + )
if ( Buf [ old_size ] = = ' \n ' )
LineOffsets . push_back ( old_size ) ;
2015-08-14 04:59:37 +02:00
ScrollToBottom = true ;
}
2016-05-02 12:32:16 +02:00
void Draw ( const char * title , bool * p_open = NULL )
2015-08-14 04:59:37 +02:00
{
ImGui : : SetNextWindowSize ( ImVec2 ( 500 , 400 ) , ImGuiSetCond_FirstUseEver ) ;
2016-05-02 12:32:16 +02:00
ImGui : : Begin ( title , p_open ) ;
2015-08-14 05:47:50 +02:00
if ( ImGui : : Button ( " Clear " ) ) Clear ( ) ;
2015-08-14 04:59:37 +02:00
ImGui : : SameLine ( ) ;
bool copy = ImGui : : Button ( " Copy " ) ;
2015-08-14 05:47:50 +02:00
ImGui : : SameLine ( ) ;
2015-08-14 05:51:34 +02:00
Filter . Draw ( " Filter " , - 100.0f ) ;
2015-08-14 04:59:37 +02:00
ImGui : : Separator ( ) ;
2015-08-30 17:38:55 +02:00
ImGui : : BeginChild ( " scrolling " , ImVec2 ( 0 , 0 ) , false , ImGuiWindowFlags_HorizontalScrollbar ) ;
2015-08-14 05:47:50 +02: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 ) )
2015-08-14 06:04:31 +02:00
ImGui : : TextUnformatted ( line , line_end ) ;
line = line_end & & line_end [ 1 ] ? line_end + 1 : NULL ;
2015-08-14 05:47:50 +02:00
}
}
else
{
ImGui : : TextUnformatted ( Buf . begin ( ) ) ;
}
2015-08-14 04:59:37 +02:00
if ( ScrollToBottom )
ImGui : : SetScrollHere ( 1.0f ) ;
ScrollToBottom = false ;
ImGui : : EndChild ( ) ;
ImGui : : End ( ) ;
}
} ;
2016-05-02 12:32:16 +02:00
static void ShowExampleAppLog ( bool * p_open )
2015-08-14 04:59:37 +02:00
{
static ExampleAppLog log ;
// Demo fill
static float last_time = - 1.0f ;
float time = ImGui : : GetTime ( ) ;
if ( time - last_time > = 0.3f )
{
2015-08-14 05:47:50 +02:00
const char * random_words [ ] = { " system " , " info " , " warning " , " error " , " fatal " , " notice " , " log " } ;
log . AddLog ( " [%s] Hello, time is %.1f, rand() %d \n " , random_words [ rand ( ) % IM_ARRAYSIZE ( random_words ) ] , time , ( int ) rand ( ) ) ;
2015-08-14 04:59:37 +02:00
last_time = time ;
}
2016-05-02 12:32:16 +02:00
log . Draw ( " Example: Log " , p_open ) ;
2015-07-22 01:00:28 +02:00
}
2016-05-02 12:32:16 +02:00
static void ShowExampleAppLayout ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
ImGui : : SetNextWindowSize ( ImVec2 ( 500 , 440 ) , ImGuiSetCond_FirstUseEver ) ;
2016-05-02 12:32:16 +02:00
if ( ImGui : : Begin ( " Example: Layout " , p_open , ImGuiWindowFlags_MenuBar ) )
2015-07-22 01:00:28 +02:00
{
if ( ImGui : : BeginMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " File " ) )
{
2016-05-02 12:32:16 +02:00
if ( ImGui : : MenuItem ( " Close " ) ) * p_open = false ;
2015-07-22 01:00:28 +02: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-24 13:50:18 +02:00
2015-07-22 01:00:28 +02:00
// right
ImGui : : BeginGroup ( ) ;
ImGui : : BeginChild ( " item view " , ImVec2 ( 0 , - ImGui : : GetItemsLineHeightWithSpacing ( ) ) ) ; // Leave room for 1 line below us
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 ( ) ;
2016-07-31 13:40:14 +02:00
ImGui : : BeginChild ( " buttons " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : Button ( " Revert " ) ) { }
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Save " ) ) { }
ImGui : : EndChild ( ) ;
ImGui : : EndGroup ( ) ;
}
ImGui : : End ( ) ;
}
2016-05-02 12:32:16 +02:00
static void ShowExampleAppPropertyEditor ( bool * p_open )
2015-11-28 18:16:59 +01:00
{
ImGui : : SetNextWindowSize ( ImVec2 ( 430 , 450 ) , ImGuiSetCond_FirstUseEver ) ;
2016-05-02 12:32:16 +02:00
if ( ! ImGui : : Begin ( " Example: Property editor " , p_open ) )
2015-11-28 18:16:59 +01:00
{
ImGui : : End ( ) ;
return ;
}
2015-11-28 18:23:32 +01:00
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. " ) ;
2015-11-28 18:16:59 +01:00
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 2 , 2 ) ) ;
ImGui : : Columns ( 2 ) ;
ImGui : : Separator ( ) ;
struct funcs
{
2016-05-04 23:17:53 +02:00
static void ShowDummyObject ( const char * prefix , int uid )
2015-11-28 18:16:59 +01:00
{
2015-11-29 21:35:58 +01:00
ImGui : : PushID ( uid ) ; // Use object uid as identifier. Most commonly you could also use the object pointer as a base ID.
ImGui : : AlignFirstTextHeightToWidgets ( ) ; // Text and Tree nodes are less high than regular widgets, here we add vertical spacing to make the tree lines equal high.
2016-05-02 12:32:16 +02:00
bool node_open = ImGui : : TreeNode ( " Object " , " %s_%u " , prefix , uid ) ;
2015-11-28 18:16:59 +01:00
ImGui : : NextColumn ( ) ;
2015-11-29 21:35:58 +01:00
ImGui : : AlignFirstTextHeightToWidgets ( ) ;
2015-11-28 18:16:59 +01:00
ImGui : : Text ( " my sailor is rich " ) ;
ImGui : : NextColumn ( ) ;
2016-05-02 12:32:16 +02:00
if ( node_open )
2015-11-28 18:16:59 +01: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-04 23:17:53 +02:00
ShowDummyObject ( " Child " , 424242 ) ;
2015-11-28 18:16:59 +01:00
}
else
{
ImGui : : AlignFirstTextHeightToWidgets ( ) ;
// Here we use a Selectable (instead of Text) to highlight on hover
//ImGui::Text("Field_%d", i);
char label [ 32 ] ;
sprintf ( label , " Field_%d " , i ) ;
2015-12-14 00:41:02 +01:00
ImGui : : Bullet ( ) ;
2015-11-28 18:16:59 +01:00
ImGui : : Selectable ( label ) ;
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 15:38:52 +01:00
}
2015-11-28 18:16:59 +01: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 ( ) ;
}
2016-05-02 12:32:16 +02:00
static void ShowExampleAppLongText ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
ImGui : : SetNextWindowSize ( ImVec2 ( 520 , 600 ) , ImGuiSetCond_FirstUseEver ) ;
2016-05-02 12:32:16 +02:00
if ( ! ImGui : : Begin ( " Example: Long text display " , p_open ) )
2015-07-22 01:00:28 +02:00
{
ImGui : : End ( ) ;
return ;
}
static int test_type = 0 ;
static ImGuiTextBuffer log ;
static int lines = 0 ;
ImGui : : Text ( " Printing unusually long amount of text. " ) ;
2015-08-24 13:50:18 +02: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 \0 " ) ;
2015-07-22 01:00:28 +02: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 + + )
log . append ( " %i The quick brown fox jumps over the lazy dog \n " , lines + i ) ;
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-08-30 01:03:08 +02:00
{
// Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGuiListClipper helper.
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 0 , 0 ) ) ;
2016-05-16 19:22:51 +02: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-08-30 01:03:08 +02:00
ImGui : : PopStyleVar ( ) ;
break ;
}
2015-07-22 01:00:28 +02: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-16 19:22:51 +02:00
ImGui : : Text ( " %i The quick brown fox jumps over the lazy dog " , i ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PopStyleVar ( ) ;
break ;
}
ImGui : : EndChild ( ) ;
ImGui : : End ( ) ;
}
// End of Demo code
# else
void ImGui : : ShowTestWindow ( bool * ) { }
2016-05-09 00:21:05 +02:00
void ImGui : : ShowUserGuide ( ) { }
void ImGui : : ShowStyleEditor ( ImGuiStyle * ) { }
2015-07-22 01:00:28 +02:00
# endif