Closed dcnieho closed 9 months ago
Hello again,
I cannot work on this, during this christmas period. This modification is a bit more involved, since callbacks are C function pointers (unbindable with pybind).
If you want to give it a try, a possible path would be:
// Callback and functions types
#ifdef IMGUI_BUNDLE_PYTHON_API
using ImGuiInputTextCallback = std::function<int(ImGuiInputTextCallbackData*)>; // Callback function for ImGui::InputText()
using ImGuiSizeCallback = std::function<void(ImGuiSizeCallbackData*)>; // Callback function for ImGui::SetNextWindowSizeConstraints()
#else
#ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData* data); // Callback function for ImGui::InputText()
typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data); // Callback function for ImGui::SetNextWindowSizeConstraints()
#endif
#endif
i.e. replace C function pointers (unbindable) by std::function, when compiling the python bindings.
Modify external/imgui/bindings/litgen_options_imgui.py and change: options.fn_params_exclude_types__regex = r"Callback$|size_t[ ]\"
run external/imgui/bindings/generate_imgui.py (it requires to install litgen
Merry christmas!
Hi Pascal,
No worries, this is another nice to have (sorry, should have specified that). Like for the other case, i won't be able to try this out myself.
There is maybe a dirty trick (I don't quite oversee it after a quick read, but seems like not cheap) to make this work without changing the signatures of all the callback functions: https://stackoverflow.com/a/18422878/3103767
But thats a lot of work on the generator side i suppose!
Merry christmas!
Super cool. Can't wait to try it out :)
I just realize i have two usecases for this callback: I want to add a button to my GUI that allows inserting a path at the cursor position in the textbox. Right now the only way to get the cursor position in the callback is through this callback. So, double super nice you've enabled it!
@pthom: This is working very well, thanks a lot!
Currently the callback argument is dropped when
imgui.input_text
is wrapped (ImGuiInputTextCallback callback = nullptr
is the signature). I wonder if it would be possible to wrap this (and thereby callbacks more generally i guess), since i'd like to use the input text withImGuiInputTextFlags_CallbackHistory
.