Skip to content
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

Added various missing operators to ImVec4 #8510

Closed
wants to merge 1 commit into from
Closed

Conversation

gan74
Copy link
Contributor

@gan74 gan74 commented Mar 21, 2025

Added operator*(ImVec4, float), operator/(ImVec4, float), operator*(ImVec4, ImVec4) and operator-(ImVec4)

This makes ImVec4 (with IMGUI_DEFINE_MATH_OPERATORS) usable for basic math which is useful when manipulating colors.

I omitted self-assignment operators because they are easier to manage without.

@ocornut
Copy link
Owner

ocornut commented Mar 21, 2025

Hello,

Thanks for your PR.

The idea is to avoid turning the thing into a full-fledged math library. As far as I know, I don't consider those particular operator to be necessary or frequently used for color manipulation, e.g. why would you multiply all 4 fields of a color? or subtract two of them? Can you clarify why do you need them? (Genuinely curious and happy to be convinced)

There is a ImLerp() function in imgui_internal.h if that's what you are trying to implement, but otherwise note that you can perfectly add those operators in your own code.

@gan74
Copy link
Contributor Author

gan74 commented Mar 21, 2025

The usecase is mostly lerp indeed!

The argument for having these as part of ImVec4 rather than relying on eg: ImLerp is that it allows ImVec4 to go through templated functions like any other vector type. I think there is a least surprise argument as well, I would expect a numeric vector type to either provide the 5 operators (+, -, *, / and unary -) or none at all.

All this can be done by adding the operators into imgui_user.h, but the change seemed simple enough that might be worth providing it by default.

ocornut pushed a commit that referenced this pull request Mar 23, 2025
@ocornut
Copy link
Owner

ocornut commented Mar 23, 2025

Thanks. Alright, I decided there's little harm in adding them, pushed as 7674cbc. Thanks!

@ocornut ocornut closed this Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants