Buffer to store entered text.
Slice of buffer that stores text entered so far.
Force the text input field to be inputable regardless of whether it has been selected by the user? Useful to e.g. make a text field inputable immediately after it appears in a newly opened dialog.
Optionally override the current default color scheme for this element.
true if the user has entered and confirmed the text (by pressing Enter), false otherwise.
Example (using GLFW):
1 static dchar staticUnicode; 2 // Buffer to store text input 3 char[128] textInputBuffer; 4 // Slice of textInputBuffer 5 char[] textEntered; 6 7 extern(C) static void getUnicode(GLFWwindow* w, uint unicode) 8 { 9 staticUnicode = unicode; 10 } 11 12 extern(C) static void getKey(GLFWwindow* w, int key, int scancode, int action, int mods) 13 { 14 if(action != GLFW_PRESS) { return; } 15 if(key == GLFW_KEY_ENTER) { staticUnicode = 0x0D; } 16 else if(key == GLFW_KEY_BACKSPACE) { staticUnicode = 0x08; } 17 } 18 19 void init() 20 { 21 GLFWwindow* window; 22 23 // ... init the window here ... 24 25 // Not really needed, but makes it obvious what we're doing 26 textEntered = textInputBuffer[0 .. 0]; 27 glfwSetCharCallback(window, &getUnicode); 28 glfwSetKeyCallback(window, &getKey); 29 } 30 31 void frame() 32 { 33 // These should be defined somewhere 34 int mouseX, mouseY, mouseScroll; 35 ubyte mousebutton; 36 37 // .. code here .. 38 39 // Pass text input to imgui 40 imguiBeginFrame(cast(int)mouseX, cast(int)mouseY, mousebutton, mouseScroll, staticUnicode); 41 // reset staticUnicode for the next frame 42 43 staticUnicode = 0; 44 45 if(imguiTextInput("Text input:", textInputBuffer, textEntered)) 46 { 47 import std.stdio; 48 writeln("Entered text is: ", textEntered); 49 // Reset entered text for next input (use e.g. textEntered.dup if you need a copy). 50 textEntered = textInputBuffer[0 .. 0]; 51 } 52 53 // .. more code here .. 54 }
Define a text input field.