I adapted the demo console example into a chatbox system for my application, and I wondered something.
My buffer has a length of 2001 (2000 characters + the \0 character), and I provide a buffer size of 2000 to InputText. But when I tested, I was able to enter more than 2000 characters, which led to a segmentation fault as I tried to enter a 2002nd one.
Is there a way (maybe using a callback) of preventing the user from inputting of a 2001st character if there are already 2000 ?
I can tell because there’s no function called TextInput() in ImGui, the function is called InputText(). When “translating” your code to a post here you are likely omitting the elements that are actually important to your issue.
1/ You are not testing the event flag correctly in your callback.
2/ You are specifying the Resize flag which has the explicit purpose of requesting new buffer size to the callback. In other words, you are explicitely enabling a feature that allows resizing while misusing it (not honoring resize requests). (And omitted mentioning it until now)
Currently I’m not sure resize callback can be used if you cannot resize your underlying buffer. I’ll double check tomorrow and it’ll be nice to also support the use case you were intending to use, but it wasn’t the initial intent.
So, I get either a charcounter that works without callbacks or the ability to send messages using Enter (as the EnterReturnsTrue flag prevents the editing of text from returning true).
Unless I’m doing something wrong.
I tried this:
// Code I took from the console example in the demo
char* s = InputBuf;
CharCounter = strlen(InputBuf);
reclaim_focus = true;
I also tried with IsKeyDown and IsKeyReleased, but nothing worked.
I guess there are other ways of doing what I want, but I can’t think of any at the moment.