-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Question: does anyone know/use the math operators of InputInt/InputFloat ? #1691
Comments
I got a got amount of answers for this on twitter, Basically
I think will keep the feature active until we get a chance to replace it with an expression evaluator, which shouldn't be too much work. |
If you would like to i have fully working implementation of calc where you can even register any single char operators. I just tested it on custom InputScalarCalc and it works nicely + using it few years for my config system |
Would be interested in seeing the code yes. I think we ought to support an “expression evaluator” callback and provide a default one that users could adapt to handle eg : variables. |
Ok, will prepare example to some separate repo or I can attach it as file here. Up to you, in any case it's close to midnight here so tomorrow ;-) |
Here is self compilable cpp source file with implemented calculator (tested on Osx - clang). Just a note: it could use some optimizations like not using std::string, std::stringstream for reading equation, use hardcoded operators and more, which i did not need even now when loading hundereds of small equations in my config system so its fast enough for me now. This was attempt to make it simpler to read and change with different sets of operators (with simple adjustment it could even support word type operators (not only char) so you could create even own tiny simple scripting language). Feel free to use it as you see fit with no guarantees ;-) Here is then my snippet for creating input fields with calculator support: |
Thank you! |
Fully agree, style is way different and quite not compatible but it may help ;-) :-) |
First off, thanks for your library! It's fantastic. I had an expression evaluator in my editor in the past, but after switching to imgui I was missing it, so I just tried integrating it back in and it seems to work nicely. The evaluator I'm using can be found here, it's small and written in a simple, nice C style, though I had to mod it slightly for const: https://www.strchr.com/expression_evaluator As an example of how to use it, essentially the following can be added just before the
Maybe instead of a direct integration of an expression evaluator, we could get a callback that gives the application the |
Hello, I would love to be able to do math in inputInt (and the ctrl+clicked part of if I write int i; if (InputInt("xxx",&i...)) { /* no sign of string to evaluate here ? */} So I got better luck with my question is, is that the efficient way to go ? Also I added attributes SliderScalarN(const char* label, ... , ImGuiInputTextFlags temp_flags = 0, ImGuiInputTextCallback temp_callback = NULL, void* temp_user_data = NULL); so I can do ( I also changed int x = ImGui::SliderScalarN("name", &data, type, ...,ImGuiInputTextFlags_CallbackAlways | ImGuiInputTextFlags_EnterReturnsTrue, [](auto data){ memcpy(data->UserData, data->Buf, data->BufSize); return 1;}, &buf); if (x) *data = evaluate_expression(buf[x], type); This partly works, But if the value is already set to thx for suggestions |
I think few people know about that, but with InputInt, InputFloat, SliderInt, SliderFloat, DragInt, DragFloat, etc. you can input simple operators to affect the current value:
current value
1000
enter+100
new value1100
current value
1000
enter/2
new value500
current value
1000
enter*2
new value2000
etc.
Except that
-
doesn't work as expected since it would be ambiguous, but you can use+-100
to subtract 100.I suspect no one is really relying on this feature and I would like to remove it.
If you relied on this feature please raise a voice :)
I think it's more interesting to have a full expression evaluator, and honestly at this point perhaps it should be just up to the application and not imgui.
The text was updated successfully, but these errors were encountered: