imgui-java icon indicating copy to clipboard operation
imgui-java copied to clipboard

Kotlin DSL

Open Lyzev opened this issue 3 months ago • 2 comments

I would like to add Kotlin DSL support to make the lib more usable for Kotlin users, similar to what https://github.com/kotlin-graphics/imgui (this lib is not maintained thats why it would be nice to add this feature to this lib) does.

This would allow Kotlin code like this:

with(ImGui) {
    text("Hello, world %d", 123)
    button("Save") {
        // do stuff
    }
    inputText("string", buf)
    sliderFloat("float", ::f, 0f, 1f)
}

I am not quite sure if a PR like this would be accepted since it requires adding the Kotlin Gradle plugin, which adds bloat (Kotlin lib). I considered implementing it in Java to avoid this, but Kotlin's inline functions don't translate well to Java and the code would be unreadable/unmaintainable.

I'm happy to submit a PR for this if you're open to it. Otherwise, feel free to close this issue.

Lyzev avatar Nov 05 '25 20:11 Lyzev

I find myself sometimes naturally adding trailing lambdas to various components.

Maybe a wrapper could be made instead that incorporates the Kotlin functions ?

JCox06 avatar Nov 09 '25 12:11 JCox06

It would be a wrapper of the begin and end functions anyway, but it would be nice if it were shipped with the bindings. It could live in this project as a separate Gradle module if you mean that.

I could make seperate project of course but as said in my opinion it would be nicer in here.

Lyzev avatar Nov 09 '25 17:11 Lyzev