I need to be able to use ImGui
textboxes, however they don't take const char*
or std::string
so I need to convert a string to a char
array. The problem with this is, however, that I need my char
array to be the same size as the string (+1). I get an error saying it needs to be constant value in declaration but I need to be able to access the string's size and make a variable that holds that value as constant. Is this possible? Here is the code:
static std::string text = "";
static bool read_only = false;
char txt[text.size() + 1] = text;
ImGui::Begin("Window");
ImGui::InputTextMultiline("Textbox", txt, IM_ARRAYSIZE(txt), ImVec2(-1.0f, ImGui::GetTextLineHeight() * 16), ImGuiInputTextFlags_AllowTabInput | (read_only ? ImGuiInputTextFlags_ReadOnly : 0));
ImGui::End();
The format for the ImGui::InputTextMultiline is this:
bool InputTextMultiline(const char* label, char* buf, size_t buf_size, const ImVec2& size = ImVec2(0,0), ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL)
Edit: The textbox needs to be arbitrary size and not limited by a static const value at compile time, rather a dynamic size such that strings are aswell.