@ -921,48 +921,89 @@ static void ShowDemoWindowWidgets()
ImGui : : TreePop ( ) ;
ImGui : : TreePop ( ) ;
}
}
if ( ImGui : : TreeNode ( " Filtered Text Input" ) )
if ( ImGui : : TreeNode ( " Text Input " ) )
{
{
static char buf1 [ 64 ] = " " ; ImGui : : InputText ( " default " , buf1 , 64 ) ;
if ( ImGui : : TreeNode ( " Multi-line Text Input " ) )
static char buf2 [ 64 ] = " " ; ImGui : : InputText ( " decimal " , buf2 , 64 , ImGuiInputTextFlags_CharsDecimal ) ;
{
static char buf3 [ 64 ] = " " ; ImGui : : InputText ( " hexadecimal " , buf3 , 64 , ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase ) ;
// Note: we are using a fixed-sized buffer for simplicity here. See ImGuiInputTextFlags_CallbackResize
static char buf4 [ 64 ] = " " ; ImGui : : InputText ( " uppercase " , buf4 , 64 , ImGuiInputTextFlags_CharsUppercase ) ;
// and the code in misc/cpp/imgui_stdlib.h for how to setup InputText() for dynamically resizing strings.
static char buf5 [ 64 ] = " " ; ImGui : : InputText ( " no blank " , buf5 , 64 , ImGuiInputTextFlags_CharsNoBlank ) ;
static char text [ 1024 * 16 ] =
struct TextFilters { static int FilterImGuiLetters ( ImGuiInputTextCallbackData * data ) { if ( data - > EventChar < 256 & & strchr ( " imgui " , ( char ) data - > EventChar ) ) return 0 ; return 1 ; } } ;
" /* \n "
static char buf6 [ 64 ] = " " ; ImGui : : InputText ( " \" imgui \" letters " , buf6 , 64 , ImGuiInputTextFlags_CallbackCharFilter , TextFilters : : FilterImGuiLetters ) ;
" The Pentium F00F bug, shorthand for F0 0F C7 C8, \n "
" the hexadecimal encoding of one offending instruction, \n "
ImGui : : Text ( " Password input " ) ;
" more formally, the invalid operand with locked CMPXCHG8B \n "
static char bufpass [ 64 ] = " password123 " ;
" instruction bug, is a design flaw in the majority of \n "
ImGui : : InputText ( " password " , bufpass , 64 , ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank ) ;
" Intel Pentium, Pentium MMX, and Pentium OverDrive \n "
ImGui : : SameLine ( ) ; HelpMarker ( " Display all characters as '*'. \n Disable clipboard cut and copy. \n Disable logging. \n " ) ;
" processors (all in the P5 microarchitecture). \n "
ImGui : : InputTextWithHint ( " password (w/ hint) " , " <password> " , bufpass , 64 , ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank ) ;
" */ \n \n "
ImGui : : InputText ( " password (clear) " , bufpass , 64 , ImGuiInputTextFlags_CharsNoBlank ) ;
" label: \n "
" \t lock cmpxchg8b eax \n " ;
static ImGuiInputTextFlags flags = ImGuiInputTextFlags_AllowTabInput ;
HelpMarker ( " You can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputTextMultiline() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example. (This is not demonstrated in imgui_demo.cpp) " ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_ReadOnly " , ( unsigned int * ) & flags , ImGuiInputTextFlags_ReadOnly ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_AllowTabInput " , ( unsigned int * ) & flags , ImGuiInputTextFlags_AllowTabInput ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_CtrlEnterForNewLine " , ( unsigned int * ) & flags , ImGuiInputTextFlags_CtrlEnterForNewLine ) ;
ImGui : : InputTextMultiline ( " ##source " , text , IM_ARRAYSIZE ( text ) , ImVec2 ( - 1.0f , ImGui : : GetTextLineHeight ( ) * 16 ) , flags ) ;
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 ( ImGuiInputTextCallbackData * 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 ) ;
ImGui : : Text ( " Password input " ) ;
static char bufpass [ 64 ] = " password123 " ;
ImGui : : InputText ( " password " , bufpass , 64 , ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Display all characters as '*'. \n Disable clipboard cut and copy. \n Disable logging. \n " ) ;
ImGui : : InputTextWithHint ( " password (w/ hint) " , " <password> " , bufpass , 64 , ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank ) ;
ImGui : : InputText ( " password (clear) " , bufpass , 64 , ImGuiInputTextFlags_CharsNoBlank ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Resize Callback " ) )
{
// If you have a custom string type you would typically create a ImGui::InputText() wrapper than takes your type as input.
// See misc/cpp/imgui_stdlib.h and .cpp for an implementation of this using std::string.
HelpMarker ( " Demonstrate using ImGuiInputTextFlags_CallbackResize to wire your resizable string type to InputText(). \n \n See misc/cpp/imgui_stdlib.h for an implementation of this for std::string. " ) ;
struct Funcs
{
static int MyResizeCallback ( ImGuiInputTextCallbackData * data )
{
if ( data - > EventFlag = = ImGuiInputTextFlags_CallbackResize )
{
ImVector < char > * my_str = ( ImVector < char > * ) data - > UserData ;
IM_ASSERT ( my_str - > begin ( ) = = data - > Buf ) ;
my_str - > resize ( data - > BufSize ) ; // NB: On resizing calls, generally data->BufSize == data->BufTextLen + 1
data - > Buf = my_str - > begin ( ) ;
}
return 0 ;
}
// Tip: Because ImGui:: is a namespace you can add your own function into the namespace from your own source files.
static bool MyInputTextMultiline ( const char * label , ImVector < char > * my_str , const ImVec2 & size = ImVec2 ( 0 , 0 ) , ImGuiInputTextFlags flags = 0 )
{
IM_ASSERT ( ( flags & ImGuiInputTextFlags_CallbackResize ) = = 0 ) ;
return ImGui : : InputTextMultiline ( label , my_str - > begin ( ) , my_str - > size ( ) , size , flags | ImGuiInputTextFlags_CallbackResize , Funcs : : MyResizeCallback , ( void * ) my_str ) ;
}
} ;
// For this demo we are using ImVector as a string container.
// Note that because we need to store a terminating zero character, our size/capacity are 1 more than usually reported by a typical string class.
static ImVector < char > my_str ;
if ( my_str . empty ( ) )
my_str . push_back ( 0 ) ;
Funcs : : MyInputTextMultiline ( " ##MyStr " , & my_str , ImVec2 ( - 1.0f , ImGui : : GetTextLineHeight ( ) * 16 ) ) ;
ImGui : : Text ( " Data: %p \n Size: %d \n Capacity: %d " , my_str . begin ( ) , my_str . size ( ) , my_str . capacity ( ) ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Multi-line Text Input " ) )
{
// Note: we are using a fixed-sized buffer for simplicity here. See ImGuiInputTextFlags_CallbackResize
// and the code in misc/cpp/imgui_stdlib.h for how to setup InputText() for dynamically resizing strings.
static char text [ 1024 * 16 ] =
" /* \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 " ;
static ImGuiInputTextFlags flags = ImGuiInputTextFlags_AllowTabInput ;
HelpMarker ( " You can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputTextMultiline() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example. (This is not demonstrated in imgui_demo.cpp) " ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_ReadOnly " , ( unsigned int * ) & flags , ImGuiInputTextFlags_ReadOnly ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_AllowTabInput " , ( unsigned int * ) & flags , ImGuiInputTextFlags_AllowTabInput ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_CtrlEnterForNewLine " , ( unsigned int * ) & flags , ImGuiInputTextFlags_CtrlEnterForNewLine ) ;
ImGui : : InputTextMultiline ( " ##source " , text , IM_ARRAYSIZE ( text ) , ImVec2 ( - 1.0f , ImGui : : GetTextLineHeight ( ) * 16 ) , flags ) ;
ImGui : : TreePop ( ) ;
ImGui : : TreePop ( ) ;
}
}