-
-
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
Input textbox of arbitrary length #1008
Comments
Hello, Sorry it is isn't supported at the moment. There's definitively a need to support that sort of patterns (to work more naturally with say, user storage in a std::string along with clipboard pasting of any size). At some point earlier on InputText() was about to update its size but that was actually tied to a bug that really needed fixing. That code has become muddled in a series of features and needs to be rewritten. This is among the thing that will be keep in mind when doing so. The regular workaround for now is just to provide a buffer large enough, sorry! As you pointed out, manipulating internals or the code itself might lead to acceptable workarounds, you can always include ( If you need a serious text editor you may attempt to integrate Scintilla: |
Hi, thanks for reply. For now, even though such textbox would be useful, it's not of utmost importance so I've moved on. But it seems interesting so I will surely return to the problem. I will post if I find any suitable, more general solution. |
I have been hitting the same issue here described. My temporary fix is to add Text.resize() inside ImGui::InputTextEx if (io.InputCharacters[0])
{
if(buf_size + 1 != edit_state.Text.Size)
{
edit_state.Text.resize(buf_size+1);
}
//...
} Could such a change make any sense to be merged in the master? |
@Pagghiu: Does this work when text is copied/pasted too? Moreover, in ImGuiTextEditState 3 buffers are present: ImVector<ImWchar> Text; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer.
ImVector<char> InitialText; // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
ImVector<char> TempTextBuffer; I didn't look at the code, but Is it safe to just resize one of them ? P.S. Maybe it's possible to add an ImGui::InputText(...) overload that takes an ImGuiTextBuffer, so that it's resizable. Maybe we can add an optional last argument to ImGui::InputTextEx(...) that takes that buffer, so that we can keep most of its implementation as it is. |
@Flix01 you're right, there are issues with copy&paste. |
I was looking after a way to resize the Input textbox myself(expand when needed), and here is my solution: Note: myText is a std::string.
Seems to work fine, but I just made it work, so might be something I haven't thought about. |
@SSBMTonberry: Good job! (and non-intrusive) 😃 I've not tested it yet, but maybe there could be some problem when using two different instances: Q) How can we be sure that "clipText" belongs to "Them characters mate" and not to the another input text ? Q) Does ImGui::GetCurrentContext()->InputTextState always point to the input text in the previous line (or only if it's focused) ? Q) [Optimization] Would it be possible to just append some '\0' chars to the string, instead of deep copying it every frame? However basically I think this kind of solution can actually work, since the only question I can think that can break it is the second. 😃 |
@Flix01: To be honest, I started tinkering with ImGui for the first time yesterday, so there is naturally a lot of things I don't know for sure yet. What I have figured, though, is that the code I posted is causing issues for other code parts when used. For instance, I get a crash when simply selecting the bottom textbox (the one displaying the hex value of the color) of ColorPicker4 which is in another popup. My idea of the code though, was to make the InputTextMultiline field expand to a size that made sure you always could paste in values as well as typing, but as I have figured my code has issues. Works fine when "isolated", but can cause crashes when using controls added later. EDIT:
|
I can't test it yet, but maybe something like: From imgui.h: IMGUI_API bool IsItemActive();
// is the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false) Can you please try and see if it still works ? |
Made a small gist here, mostly for testing purposes. But if the ImGui::InputText(...) internals are going to change in the future, maybe it's a wise choice to wait... 😕 |
I want to implement input textbox for arbitrary length buffer that would grow when needed. I am already resizing my buffer when it approaches its capacity, but as ImGui is internally keeping a copy of original data (together with its size) as long as it is active, usable buffer size remains the same until I click somewhere else and back on the textbox to reactivate it.
Is there any way to force ImGui to synchronize/update its internal buffer with the one provided by my without the need to click, nor loosing cursor position? I wanted to try SetActiveId, but it isn't part of the public interface.
PS. I am aware that whatever the solution, pasting becomes a problem when we allow for any buffer to change size.
The text was updated successfully, but these errors were encountered: