Skip to content

ImVec usage from kotlin is not great. #302

Closed
@wagyourtail

Description

@wagyourtail

This is more of a request for comments and ideas about what could be done, seeing as this would probably require a breaking change to fix... unless there's some jetbrains annotation I don't know about.

but the gist of it is that the functions in ImVec2 (and 4, and probably some other classes) end up becoming operator overloads in kotlin.
so for example

val v1 = ImVec2(10, 10)
val v2 = ImVec2(20, 20)
val v3 = v1 + v2

println(v1) // (30, 30)
println(v2) // (20, 20)
println(v3) // (30, 30)
println(v1 == v3) // true

Obviously this makes programmer error a lot more likely in kotlin as v1 gets mutated when it wouldn't be expected to.
but I'm not sure what the most desirable way to change this behavior is, since its not a part of the java api.
what I'm currently doing is using my own vector library, with a function to convert it back to imvec when I need to pass it into imgui.

what would be the way to fix this behavoir? should it even be fixed? do we care about usability from kotlin with these bindings?

I'd propose a global flag to set the behavoirs
ie. ImVec2.allowMutation = false
which would change the function behavior, but... it would also possibly lower performance a little bit in some usecases, probably not by much, if it's even measurable.
then, just default this value to true, to not change behavior in existing applications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion issue type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions