Closed ezorzin closed 2 years ago
There's indeed an old feature (which I think no one is using, I made a poll once) where typing an operator e.g. +100
into a text field would apply this over the initial value.
I think I am going to remove this feature, but we can also detect this specific case and fix it ahead.
By digging into the code, I found this (imgui_widgets.cpp, line 1995): // User can input math operators (e.g. +100) to edit a numerical values. // NB: This is not a full expression evaluator. We should probably add one and replace this dumb mess.. bool ImGui::DataTypeApplyOpFromText(const char buf, const char initial_value_buf, ImGuiDataType data_type, void p_data, const char format)
...which is invoked by the InputScalar method, which is invoked by the InputFloat method (and possibly by similar others).
As far as I understand, the DataTypeApplyOpFromText implements a basic algebraic interpreter: does its logic maybe collide with the "+" in the printf-style format producing an unwanted summation?
I wanted to use the "%+.6E" format because in my application I have a panel containing many numbers: it was nice to have them all aligned as they change, not having the negative ones shifting to the right (because their numbers have a "-" sign in front).
If it is not possible to change/eliminate that algebraic interpreter, is there any workaround in order to achieve the same goal?
Thanks,
Erik
As far as I understand, the DataTypeApplyOpFromText implements a basic algebraic interpreter: does its logic maybe collide with the "+" in the printf-style format producing an unwanted summation?
Yes that's the problem.
If it is not possible to change/eliminate that algebraic interpreter, is there any workaround in order to achieve the same goal?
This is what I'm doing now.
I just went and removed that legacy feature which was intended for removal anyway!
One extra data point suggesting no one used it, is that when we introduced new data types in 1.69 we intentionally did NOT enable those arithmetic operators on the new types, and no-one ever complained about it.
I have just pulled the last version after your modification: now my code works as expected. Thanks you so much!
And congratulations for this library: it's really very useful :)
Version: 1.86 Commit: 673f5e588de32e5fc2bfd1d94a0d8a687ffdbc9b Branch: master Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp Compiler: VS2022 Operating System: Windows 10
Hi,
I am doing this: ImGui::InputFloat ("value_name", &value, 0.0f, 0.0f, "%+.6E");
and expect to have the value formatted according the the "printf" style "%+.6E". According to the "printf" documentation, the "+" should always show the sign (plus or minus) of the number. It works, but there is a problem: when changing the number in the input field, let's say e.g. from +1.000000E+00 to +2.000000E+00, the updated number in the text field does not correspond to the latter one but to the summation of the new one and the old one (in this case it would be "+3.000000E+00"). In case enter the new number as "2.000000E+00" (notice I removed the leading "+"), then the summation is not done and the number is updated correctly. No issues with negative numbers.
It looks to me there is a misinterpretation of the "+" symbol in some low level function of imgui.
Best regards,
Erik