:sparkling_heart: Pure Java binding for dear-imgui
Linux Build | Windows Build |
---|---|
To jcenter users: as the deprecation of jcenter, this library is now published to maven central since v0.20
.
Please update your repository setting to reflect the change.
Cross-platform efficient pure Java binding for dear-imgui, Kotlin is used as code generation tool.
This binding is rather bare-metal, that reflects imgui’s API directly. I think it’s good enough, but you may expect some other styles of bindings.
There is a declarative wrapper of jimgui, namely flui available.
Can be considered as both advantages and disadvantages.
It is Java-only with an optional Kotlin DSL wrapper.
It hides everything about rendering behind-the-scene,
so you don’t need to worry about GLFW, OpenGL or DirectX stuffs
(speaking of lwjgl or jogl integration — see #18, it’s hard).
Also, it doesn’t separate jars for different platforms. One jar works on all supported platforms.
It is well-known that dear imgui doesn’t have image loading out-of-the-box,
but this library has, and it even has a wrapper for aiekick/ImGuiFileDialog
and Flix01/imguidatechooser and some other minor widgets.
This is twofolded.
java.lang.String
into byte arrays that C++ is happy with.org.ice1000.jimgui.util.JImGuiUtil.setStringToBytes
JImGuiUtil.cacheStringToBytes()
, or use the more efficient alternative to java.lang.String
—org.ice1000.jimgui.JImStr
, which is supposed to be created as global constants.It exploits JetBrains annotations, particularly with MagicConstant
,NotNull
, Nullable
and Contract
.
MagicConstant
annotation enables IntelliJ IDEA to provide completion for int flags
arguments
with only the flags needed:
This project was created for a code editor and a game engine, both dead.
For macOS users, make sure you add -XstartOnFirstThread
JVM argument when running applications built with jimgui.
ImGui
namespace getter/setter/function/javadoc generationImGuiFontAtlas
/ImGuiStyle
/ImGuiFont
/ImGuiIO
/ImGuiDrawList
properties getter/setter/function/javadoc generation
ImGui*Flags
constant/javadoc generationImStyleVar
keys using generic parameter as type constraint (type safe!)MagicConstant
annotation to specify where the constant parameters are from (IntelliJ IDEA understands this!)MagicConstant
annotationemptyButton
, dragVec4
, sliderVec4
, lineTo
, circle
,
`bufferingBar`, `dialogBox`, `spinner` (Android style!), `toggleButton` (iOS style!),
mostly from the issues and the communities.
JImFileDialog
imgui.dateChooser
bool *
, int *
, float *
) wrappers, providing accessValue
and modifyValue
ImVec4
wrapper with optional mutabilityImTextureID
wrapper with platform-dependent implementationsLPDIRECT3DTEXTURE9
on WindowsXP+ID3D11ShaderResourceView*
on Windows7+GLuint
on MacOS/Linux
import org.ice1000.jimgui.JImGui;
import org.ice1000.jimgui.util.JniLoader;
public class Main {
public static void main(String... args){
JniLoader.load();
try (JImGui imGui = new JImGui()) {
// load fonts, global initializations, etc.
while (!imGui.windowShouldClose()) {
// some drawing-unrelated initializations
// mostly do nothing here
imGui.initNewFrame();
// draw your widgets here, like this
imGui.text("Hello, World!");
imGui.render();
// mostly do nothing here
}
}
}
}
Kotlin DSL:
runPer(10) {
"Window with Tabs" {
tabBar("tab bar id") {
tabItem("Tab One") { text("I am in Tab one!") }
tabItem("Tab Two") { button("I am in Tab two!") }
tabItem("Tab Three") { bulletText("I am in Tab three!") }
}
treeNode("PsiClassBody") {
treeNode("PsiConstructor") {
text("PsiIdentifier")
}
treeNode("PsiMethod") {
text("PsiAnnotation")
text("PsiLeafElement")
}
}
}
}
You can use ImGuiFontAtlas
to extend glyph ranges for your font, which is needed if you want to display Unicode characters.
You can find more info about glyph ranges at the dear-imgui repository.
Notice that to display Unicode characters you need to have your Java sources encoded and compiled as UTF-8. To compile the sources as UTF-8, add the following line to your build.gradle
:
compileJava.options.encoding = 'UTF-8'
import org.apache.tools.ant.taskdefs.condition.Os
// ...
dependencies {
String jimguiVersion = 'v0.20.3'
implementation "org.ice1000.jimgui:core:$jimguiVersion" // basic functionality
implementation "org.ice1000.jimgui:kotlin-dsl:$jimguiVersion" // kotlin dsl wrapper
}
// ...
tasks.withType(JavaExec).configureEach {
if (Os.isFamily(Os.FAMILY_MAC)) jvmArgs "-XstartOnFirstThread"
}
import org.apache.tools.ant.taskdefs.condition.Os
dependencies {
val jimguiVersion = "v0.20.3"
implementation("org.ice1000.jimgui:core:$jimguiVersion") // basic functionality
implementation("org.ice1000.jimgui:kotlin-dsl:$jimguiVersion") // kotlin dsl wrapper
}
tasks.withType<JavaExec>().configureEach {
if (Os.isFamily(Os.FAMILY_MAC)) jvmArgs("-XstartOnFirstThread")
}
<dependency>
<groupId>org.ice1000.jimgui</groupId>
<!-- basic functionality -->
<artifactId>core</artifactId>
<version>v0.20.3</version>
<type>pom</type>
</dependency>
First you need to make sure you have cmake
newer than 3.14 and the following software installed:
make
pkg-config
libglfw3-dev
msbuild
(needs to be on PATH)Cocoa
, GLUT
, OpenGL
-XstartOnFirstThread
export _JAVA_OPTIONS='-XstartOnFirstThread'
)To compile a jar library, run
(you need to use the developer command prompt for this on Windows):
$ ./gradlew jar
To run tests, run:
$ ./gradlew test