Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This has been issued in #278.
The auto-resizing functionality of DearImgui uses a callback, and the user is responsible for managing the underlying buffer (malloc, realloc, free). Since in
pyimgui
the string buffer is internally managed, it wasn't possible to implement the functionality via python.Now the resizing of the buffer, if asked via the
imgui.INPUT_TEXT_CALLBACK_RESIZE
, is done internally and is fully transparent to python users. If the user provides a custom callback, it is still called properly after the internal buffer resizing.Moreover, it is not very python friendly to ask for a buffer with a given size that is growable; one would have to create a variable
buffer_size
, globally access it in a provided callback function, and update it when the resize callback is called. This all comes from the c/c++ management of character strings and does not make a lot of sense for a python user. Thus I decided to simplify a bit the prototype ofinput_text
,input_text_multiline
, andinput_text_with_hint
. Now the argumentbuffer_length
is optional and has a value of-1
by default. In this case, the buffer size sent to DearImgui is the length of the argumentvalue
and the flagimgui.INPUT_TEXT_CALLBACK_RESIZE
is automatically set.This allows writing input text field as
Of course, the old syntax with the
buffer_length
argument is still usable and would lead to a field with a maximum byte lengthI consider this PR a work in progress since working on this has highlighted some weird and suboptimal functioning of
pyimgui
that I wish to fix. DearImgui asks for achar*
that we must create from the passedvalue
argument. Currently for each call ofinput_text()
, memory is dynamically allocated withmalloc
, the content is copied fromvalue
to the internal buffer, and this buffer is passed to DearImgui. The internal buffer is freed at the end of the function. This is problematic since all of this is done for each text field and for each frame (which is a lot). I am considering implementing a memory pool internally topyimgui
that would be allocated at the start and using it instead of dynamically allocating memory for eachinput_text()
call.Moreover, there is some cleaning to do in the methods of the class
_ImGuiInputTextCallbackData
.Any feedback is welcome :)