@ -1005,7 +1005,7 @@ static void ShowDemoWindowWidgets()
if ( ImGui : : TreeNode ( " Color/Picker Widgets " ) )
{
static ImVec4 color = Im Color( 114 , 144 , 154 , 200 ) ;
static ImVec4 color = Im Vec4( 114.0f / 255.0f , 144.0f / 255.0f , 154.0f / 255.0f , 200.0f / 255.0f ) ;
static bool alpha_preview = true ;
static bool alpha_half_preview = false ;
@ -3095,10 +3095,12 @@ struct ExampleAppConsole
{
char InputBuf [ 256 ] ;
ImVector < char * > Items ;
bool ScrollToBottom ;
ImVector < const char * > Commands ;
ImVector < char * > History ;
int HistoryPos ; // -1: new line, 0..History.Size-1 browsing history.
ImVector < const char * > Commands ;
ImGuiTextFilter Filter ;
bool AutoScroll ;
bool ScrollToBottom ;
ExampleAppConsole ( )
{
@ -3109,6 +3111,8 @@ struct ExampleAppConsole
Commands . push_back ( " HISTORY " ) ;
Commands . push_back ( " CLEAR " ) ;
Commands . push_back ( " CLASSIFY " ) ; // "classify" is only here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
AutoScroll = true ;
ScrollToBottom = true ;
AddLog ( " Welcome to Dear ImGui! " ) ;
}
~ ExampleAppConsole ( )
@ -3142,6 +3146,7 @@ struct ExampleAppConsole
buf [ IM_ARRAYSIZE ( buf ) - 1 ] = 0 ;
va_end ( args ) ;
Items . push_back ( Strdup ( buf ) ) ;
if ( AutoScroll )
ScrollToBottom = true ;
}
@ -3177,10 +3182,20 @@ struct ExampleAppConsole
ImGui : : Separator ( ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 0 , 0 ) ) ;
static ImGuiTextFilter filter ;
filter . Draw ( " Filter ( \" incl,-excl \" ) ( \" error \" ) " , 180 ) ;
ImGui : : PopStyleVar ( ) ;
// Options menu
if ( ImGui : : BeginPopup ( " Options " ) )
{
if ( ImGui : : Checkbox ( " Auto-scroll " , & AutoScroll ) )
if ( AutoScroll )
ScrollToBottom = true ;
ImGui : : EndPopup ( ) ;
}
// Options, Filter
if ( ImGui : : Button ( " Options " ) )
ImGui : : OpenPopup ( " Options " ) ;
ImGui : : SameLine ( ) ;
Filter . Draw ( " Filter ( \" incl,-excl \" ) ( \" error \" ) " , 180 ) ;
ImGui : : Separator ( ) ;
const float footer_height_to_reserve = ImGui : : GetStyle ( ) . ItemSpacing . y + ImGui : : GetFrameHeightWithSpacing ( ) ; // 1 separator, 1 input text
@ -3205,17 +3220,18 @@ struct ExampleAppConsole
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 4 , 1 ) ) ; // Tighten spacing
if ( copy_to_clipboard )
ImGui : : LogToClipboard ( ) ;
ImVec4 col_default_text = ImGui : : GetStyleColorVec4 ( ImGuiCol_Text ) ;
for ( int i = 0 ; i < Items . Size ; i + + )
{
const char * item = Items [ i ] ;
if ( ! f ilter. PassFilter ( item ) )
if ( ! F ilter. PassFilter ( item ) )
continue ;
ImVec4 col = col_default_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 ) ;
ImGui : : PushStyleColor ( ImGuiCol_Text , col ) ;
// Normally you would store more information in your item (e.g. make Items[] an array of structure, store color/type etc.)
bool pop_color = false ;
if ( strstr ( item , " [error] " ) ) { ImGui : : PushStyleColor ( ImGuiCol_Text , ImVec4 ( 1.0f , 0.4f , 0.4f , 1.0f ) ) ; pop_color = true ; }
else if ( strncmp ( item , " # " , 2 ) = = 0 ) { ImGui : : PushStyleColor ( ImGuiCol_Text , ImVec4 ( 1.0f , 0.8f , 0.6f , 1.0f ) ) ; pop_color = true ; }
ImGui : : TextUnformatted ( item ) ;
if ( pop_color )
ImGui : : PopStyleColor ( ) ;
}
if ( copy_to_clipboard )
@ -3283,6 +3299,9 @@ struct ExampleAppConsole
{
AddLog ( " Unknown command: '%s' \n " , command_line ) ;
}
// On commad input, we scroll to bottom even if AutoScroll==false
ScrollToBottom = true ;
}
static int TextEditCallbackStub ( ImGuiInputTextCallbackData * data ) // In C++11 you are better off using lambdas for this sort of forwarding callbacks
@ -3411,10 +3430,12 @@ struct ExampleAppLog
ImGuiTextBuffer Buf ;
ImGuiTextFilter Filter ;
ImVector < int > LineOffsets ; // Index to lines offset. We maintain this with AddLog() calls, allowing us to have a random access on lines
bool AutoScroll ;
bool ScrollToBottom ;
ExampleAppLog ( )
{
AutoScroll = true ;
ScrollToBottom = false ;
Clear ( ) ;
}
@ -3436,6 +3457,7 @@ struct ExampleAppLog
for ( int new_size = Buf . size ( ) ; old_size < new_size ; old_size + + )
if ( Buf [ old_size ] = = ' \n ' )
LineOffsets . push_back ( old_size + 1 ) ;
if ( AutoScroll )
ScrollToBottom = true ;
}
@ -3446,13 +3468,31 @@ struct ExampleAppLog
ImGui : : End ( ) ;
return ;
}
if ( ImGui : : Button ( " Clear " ) ) Clear ( ) ;
// Options menu
if ( ImGui : : BeginPopup ( " Options " ) )
{
if ( ImGui : : Checkbox ( " Auto-scroll " , & AutoScroll ) )
if ( AutoScroll )
ScrollToBottom = true ;
ImGui : : EndPopup ( ) ;
}
// Main window
if ( ImGui : : Button ( " Options " ) )
ImGui : : OpenPopup ( " Options " ) ;
ImGui : : SameLine ( ) ;
bool clear = ImGui : : Button ( " Clear " ) ;
ImGui : : SameLine ( ) ;
bool copy = ImGui : : Button ( " Copy " ) ;
ImGui : : SameLine ( ) ;
Filter . Draw ( " Filter " , - 100.0f ) ;
ImGui : : Separator ( ) ;
ImGui : : BeginChild ( " scrolling " , ImVec2 ( 0 , 0 ) , false , ImGuiWindowFlags_HorizontalScrollbar ) ;
if ( clear )
Clear ( ) ;
if ( copy )
ImGui : : LogToClipboard ( ) ;
@ -3461,6 +3501,10 @@ struct ExampleAppLog
const char * buf_end = Buf . end ( ) ;
if ( Filter . IsActive ( ) )
{
// In this example we don't use the clipper when Filter is enabled.
// This is because we don't have a random access on the result on our filter.
// A real application processing logs with ten of thousands of entries may want to store the result of search/filter.
// especially if the filtering function is not trivial (e.g. reg-exp).
for ( int line_no = 0 ; line_no < LineOffsets . Size ; line_no + + )
{
const char * line_start = buf + LineOffsets [ line_no ] ;
@ -3508,11 +3552,12 @@ static void ShowExampleAppLog(bool* p_open)
{
static ExampleAppLog log ;
// For the demo: add a debug button before the normal log window contents
// For the demo: add a debug button _BEFORE_ the normal log window contents
// We take advantage of the fact that multiple calls to Begin()/End() are appending to the same window.
// Most of the contents of the window will be added by the log.Draw() call.
ImGui : : SetNextWindowSize ( ImVec2 ( 500 , 400 ) , ImGuiCond_FirstUseEver ) ;
ImGui : : Begin ( " Example: Log " , p_open ) ;
if ( ImGui : : SmallButton ( " Add 5 entries" ) )
if ( ImGui : : SmallButton ( " [Debug] Add 5 entries" ) )
{
static int counter = 0 ;
for ( int n = 0 ; n < 5 ; n + + )