Skip to content

Commit

Permalink
feat(api): Dear ImGui v1.87 + ImPlot v0.13 (#252)
Browse files Browse the repository at this point in the history
* build(deps): bump Dear ImGui from 1.86 to 1.87

* build(deps): bump implot from 0.12 to 0.13

* feat(api,binding): adapt API to Dear ImGui v1.87

* feat(api,binding): adapt API to implot v0.13

* build: generate API for latest changes

* chore(binding): add missing super call for ImGuiStructDestroyable constructor

* chore: minor code style

* feat: adapt ImGuiImplGlfw to 1.87

* feat: adapt ImGuiImplGl3 to 1.87

* feat: adapt imgui-app module to 1.87

* fix: javadoc for updated imgui-binding

* fix: loosing data when setting struct field of char* type

Since we manually release chars, to store them in field we need to do a local copy.

* fix: invalid methods to check program linking in OpenGL

* chore: remove dedicated method to check GLFW version

* fix: add missing include
  • Loading branch information
SpaiR authored Aug 16, 2024
1 parent 341b0af commit 47d9710
Show file tree
Hide file tree
Showing 80 changed files with 17,372 additions and 12,534 deletions.
31 changes: 20 additions & 11 deletions buildSrc/src/main/kotlin/tool/generator/api/jni_content.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private fun convertParams2jni(f: Factory, params: List<CtParameter<*>>, defaults
setType<Nothing>(f.createTypeParam("double"))
setSimpleName<Nothing>("${p.simpleName}Max")
}
} else if (p.isType("ImPlotLimits")) {
} else if (p.isType("ImPlotRect")) {
result += f.createParameter<Nothing>().apply {
setType<Nothing>(f.createTypeParam("double"))
setSimpleName<Nothing>("${p.simpleName}MinX")
Expand Down Expand Up @@ -155,8 +155,8 @@ private fun joinInBodyParams(params: List<CtParameter<*>>, defaults: IntArray):
"ImPlotRange(${p.simpleName}Min, ${p.simpleName}Max)"
}

"ImPlotLimits" -> {
"ImPlotLimits(${p.simpleName}MinX, ${p.simpleName}MinY, ${p.simpleName}MaxX, ${p.simpleName}MaxY)"
"ImPlotRect" -> {
"ImPlotRect(${p.simpleName}MinX, ${p.simpleName}MinY, ${p.simpleName}MaxX, ${p.simpleName}MaxY)"
}

"TextEditorCoordinates" -> {
Expand Down Expand Up @@ -281,8 +281,10 @@ private fun createMethod(mOrig: CtMethod<*>, params: List<CtParameter<*>>, defau
append(joinInBodyParams(params, defaults))
append(')')

mOrig.getAnnotation(A_NAME_RETURN_VALUE)?.let { a ->
append(a.getValueAsString(A_VALUE_CALL_SUFFIX))
if (!mOrig.isType("void")) {
mOrig.getAnnotation(A_NAME_RETURN_VALUE)?.let { a ->
append(a.getValueAsString(A_VALUE_CALL_SUFFIX))
}
}

if (jniCpyReturn) {
Expand Down Expand Up @@ -553,7 +555,7 @@ private fun createFieldGetContent(field: CtField<*>): List<String> {
)
}

"ImVec2", "ImVec4" -> {
else -> {
getArray.setBody<Nothing>(
f.createCodeSnippet(
"""
Expand Down Expand Up @@ -602,6 +604,7 @@ private fun createFieldSetContent(field: CtField<*>): List<String> {
setAccessor.setParent<Nothing>(field.parent)
setAccessor.setSimpleName<Nothing>("set${field.simpleName}")
setAccessor.addModifier<Nothing>(ModifierKind.PRIVATE)
setAccessor.setAnnotations<Nothing>(field.annotations)

val valueParam = f.createParameter<Nothing>().apply {
setType<Nothing>(field.type)
Expand Down Expand Up @@ -633,7 +636,7 @@ private fun createFieldSetContent(field: CtField<*>): List<String> {
)
}

"ImVec2", "ImVec4" -> {
else -> {
setArray.setBody<Nothing>(
f.createCodeSnippet("""
Jni::${arrayType}ArrayCpy(env, value, $PTR_JNI_THIS->${field.getCallName()}, $arraySize)
Expand Down Expand Up @@ -665,10 +668,16 @@ private fun createFieldSetContent(field: CtField<*>): List<String> {
}
} else {
result += transformMethodToContent(setAccessor, listOf(valueParam)).map {
it.replace(
"$PTR_JNI_THIS->${setAccessor.simpleName}\\((.+)\\)".toRegex(),
"$PTR_JNI_THIS->${field.getCallName()} = $1"
)
val fieldName = "$PTR_JNI_THIS->${field.getCallName()}"
val replaceTarget = "$PTR_JNI_THIS->${setAccessor.simpleName}\\((.+)\\)"
var replaceContent = "$fieldName = $1"

// When we set a string to a field we need to manually copy the string itself.
if (field.isType("String") && !field.hasAnnotation(A_NAME_TYPE_STD_STRING)) {
replaceContent = "SET_STRING_FIELD($fieldName, $1)"
}

it.replace(replaceTarget.toRegex(), replaceContent)
}
}

Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/tool/generator/api/jvm_content.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private fun joinInBodyParams(params: List<CtParameter<*>>, defaults: IntArray):

"ImPlotPoint" -> "${p.simpleName}.x, ${p.simpleName}.y"
"ImPlotRange" -> "${p.simpleName}.min, ${p.simpleName}.max"
"ImPlotLimits" -> "${p.simpleName}.x.min, ${p.simpleName}.y.min, ${p.simpleName}.x.max, ${p.simpleName}.y.max"
"ImPlotRect" -> "${p.simpleName}.x.min, ${p.simpleName}.y.min, ${p.simpleName}.x.max, ${p.simpleName}.y.max"

"TextEditorCoordinates" -> "${p.simpleName}.mLine, ${p.simpleName}.mColumn"

Expand Down Expand Up @@ -366,7 +366,7 @@ private fun methodPlotLimitsUnwrappedContent(method: CtMethod<*>): String {
val paramNames = mutableSetOf<String>()

for (p in newMethod.parameters) {
if (p.isType("ImPlotLimits")) {
if (p.isType("ImPlotRect")) {
paramNames += p.simpleName

val paramMinX = p.factory.createParameter<Nothing>()
Expand Down Expand Up @@ -527,7 +527,7 @@ private fun transformMethodToContent(
methodPlotRangeUnwrappedContent(mNew).takeIf(String::isNotEmpty)?.run(methods::add)
}

if (params.find { it.isType("ImPlotLimits") } != null) {
if (params.find { it.isType("ImPlotRect") } != null) {
methodPlotLimitsUnwrappedContent(mNew).takeIf(String::isNotEmpty)?.run(methods::add)
}

Expand Down
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/tool/generator/api/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const val A_NAME_EXCLUDED_SOURCE = "ExcludedSource"
const val A_NAME_RETURN_VALUE = "ReturnValue"
const val A_NAME_ARG_VALUE = "ArgValue"
const val A_NAME_TYPE_ARRAY = "TypeArray"
const val A_NAME_TYPE_STD_STRING = "TypeStdString"

const val A_VALUE_CALL_PTR = "callPtr"
const val A_VALUE_CALL_OPERATOR = "callOperator"
Expand Down Expand Up @@ -55,6 +56,7 @@ val CLEANUP_ANNOTATIONS_LIST = listOf(
A_NAME_OPT_ARG,
A_NAME_ARG_VALUE,
A_NAME_TYPE_ARRAY,
A_NAME_TYPE_STD_STRING,
A_NAME_BINDING_AST_ENUM,
)

Expand All @@ -74,7 +76,7 @@ val DST_RETURN_TYPE_SET = setOf(
"ImRect",
"ImPlotPoint",
"ImPlotRange",
"ImPlotLimits",
"ImPlotRect",
"TextEditorCoordinates",
)

Expand Down
Loading

0 comments on commit 47d9710

Please sign in to comment.