Skip to content

0x1bd/imgui2kt

Repository files navigation

imgui2kt

Kotlin/Native bindings and window helpers for Dear ImGui on desktop.

imgui2kt provides:

  • a generated Kotlin facade for the cimgui Dear ImGui API
  • a simple GLFW desktop window host
  • click-through and interactive overlay hosts
  • Linux linuxX64 and Windows mingwX64 targets

Quick Start

Add the plugin from Maven Central:

// settings.gradle.kts
pluginManagement {
    repositories {
        gradlePluginPortal()
        mavenCentral()
    }
}

dependencyResolutionManagement {
    repositories { mavenCentral() }
}
// build.gradle.kts
plugins {
    kotlin("multiplatform") version "2.3.20"
    id("org.kvxd.imgui2kt.runtime") version "0.7.0"
}

kotlin {
    linuxX64 {
        binaries.executable {
            entryPoint = "example.main"
        }
    }
}

Then create src/nativeMain/kotlin/example/Main.kt:

package example

import org.kvxd.imgui2kt.ImGui
import org.kvxd.imgui2kt.desktopWindow

fun main() {
    desktopWindow(title = "imgui2kt", width = 900, height = 560) { window ->
        window.run {
            ImGui.window("Hello") {
                ImGui.textUnformatted("Dear ImGui from Kotlin/Native")
            }
        }
    }
}

Build it:

./gradlew linkDebugExecutableLinuxX64

Examples

Run an example from this repository:

./gradlew :examples:simple-window:linkDebugExecutableLinuxX64

To build the Windows executable from Linux:

./gradlew :examples:simple-window:linkDebugExecutableMingwX64
  • examples/simple-window: normal desktop window
  • examples/simple-overlay: click-through HUD overlay
  • examples/interactive-overlay: overlay that can switch between HUD and interactive input

Requirements

Linux builds require:

  • CMake
  • C and C++ compilers
  • OpenGL development files
  • Wayland development files
  • EGL
  • xkbcommon
  • pkg-config
  • wayland-scanner

Windows target builds use Kotlin/Native mingwX64. Cross-building from Linux also requires:

  • x86_64-w64-mingw32-gcc
  • x86_64-w64-mingw32-g++
  • x86_64-w64-mingw32-windres

Publishing

Publish the library and Gradle plugin to Maven Local:

./gradlew publishAllToMavenLocal

Publish the library and Gradle plugin to Maven Central:

./gradlew publishAllToMavenCentral

Maven Central publishing requires the Vanniktech Maven Publish credentials and signing properties to be available to Gradle. The release version is set in gradle.properties as imgui2kt.version.

About

autogenerated bindings for kotlin native

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors