-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for dynamic re-allocation of internal buffer while user is still typing in InputText? #2006
Comments
Alternatively an
|
1- The solution wouldn't work with clipboard pasting afaik? 2- You have a intermediary This is recurring issue, see #1008, #1443. There's probably a nice solution awaiting in the form of a change to the callback design.. I personally haven't taken the time to sit and figure it out yet. I'll give it a bit of time now. |
std::string isn't guaranteed to have contiguous memory until C++11, and the pointer is invalidated after the resize. My method to overcome this issue is messy to say the least, but I desperately needed it working Another option I had considered (but would require a fair bit more work) would be allowing the passed string and the internal buffer to be resized from the callback, rather than having to wait until the next time InputText is called. The buffer is already passed to the callback, so allowing it to be reallocated shouldn't be too hard? If I find the time I'll see if I can hack something together to test the idea |
I’m working on this, i’ll probably have a patch tomorrow.
|
I'm going to push and describe my solution right below this post, but first I wanted to react on:
Pointer invalidation is handled by the solution described below. About contiguous memory guarantee: are you aware of any pre C++11 implementation that actually used non-contiguous strings? To honor It is just that the early standard wasn't overtly explicit about that requirement but this is where everyone went anyway and they decided to standardize it later. Some ref: Either way, in core imgui we are solely providing a resize callback (no actual std::string support) and it would be fine if in theory the imgui_stl.h wrapper requires C++11. |
I have made various changes to InputText now and among there pushed what I propose to be a solution for this much requested issue. I have added a The callback function will be called with This is how a regular callback function would look like:
The actual function in the imgui_stl wrapper is a little more complicated (a few more lines) because we handle chaining callbacks, so it is possible for the end-user to use the other callbacks (completion/history, etc.) which you may or not need.
FEEDBACK HIGHLY WELCOME! |
It's possible that Though that will be spread over O(n) frames (each frame doing a small number of resizes, which means O(n) complexity per frame. |
Yeah this is why the standard was changed IIRC, but I'd still prefer to not rely on it.
This is perfect! Thank you! |
With the current system at maximum we'll have 1 resize call a frame on user interaction, so it should be inconsequential. Note that it is up to the user to implement that resize callback, so people may do a combination or reserve+resize if they deem necessary. Arguably we can improve imgui_stl to do so, thought on my test bed MS STL the string grow by a factor of 2-ish so I didn't push it further. With this feature done I'd be happy to tag and release 1.63 but I'll probably need feedback from a few people who have used and tested the feature (and also making sure there are no InputText regression related to the changes). |
Only slightly on topic, but can we get a flag to make InputText return true when the user clicks out of the text box? It seems to write to the buffer like pressing enter does, but it doesn't trigger
This wasn't a big deal when working with c-strings, but it is an issue now that we're dealing with std::strings |
I'm not sure I understand your issue and why/how it relate to using std::string. Will probably expose |
Now added |
Does
I don't want to be calling |
It return true every time the string is changed.
You may use |
That works, but it seems like a very round about way of doing what |
?? Isn’t the whole point that it is NOT doing the same as EnterReturnTrue and handle cases such as clicking out of the item?
|
I mean in terms of return-true-when-done (which |
|
I understand that having another function makes it a little more universal, but I'd still prefer
rather than
I find the current default return behaviour of InputText pretty useless anyway, if I want to get an update every single time it updates I'd probably be using a callback. But that might just be me |
In many engines I've seen, it was useful and preferable to have live edit for strings be the default default, and the use of Return in an exception for situation like command processing. What/how are you using it for? |
I'm using it for a file browser where the directories shouldn't be selected till you're sure you've got it right. I've also used it for things similar to HTML forms. |
I see. Rather than a flag to detect clicked/tabbed out, I think we should aim at a more generic feature of being able to disable the immediate writing-back of values (see #701). The difference with So I think the focus should be on something like #701 here. |
Would it be possible to toggle this with something like PushStyleVar? Say if you did |
@LAK132 Could you open a separate issue for this specifically? |
Currently I do not have C++11 and an older version of ImGui. Until I can upgrade I manage to solve it like this. But this is terrible, doing resize on every frame, but it works for my debug purposes for now. bool InputText(const char* label, std::string* str, ImGuiInputTextFlags flags) |
@vincentkarlsson94 Which compiler do you use that doesn't support C++11? |
My compiler support C++11 but our project does not fully support it yet. We are working on converting our huge project! Thanks that is a neat solution to use for now! |
I'm currently running into an issue with using a
ImGuiTextEditCallback
for dynamic allocation of memory for an InputText. It seems to me that in order for the internal buffer to resize the user has to stop editing. This is extremely frustrating!Would it be reasonable to include something like
Inside of
I have tested that this works, and it is a lot smoother than having to hit enter all the time. I'm not 100% sure of the performance impact though
My current use case (not the best performance but it's a WIP):
This
InputText
takes astring*
instead of achar*
and resizes when needed. The rest of my code usesstring
s a lot, so converting over tochar*
just for ImGui is a painEdit: I can do a pull request if this is wanted
The text was updated successfully, but these errors were encountered: