Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dear ImGui 1.87 #252

Merged
merged 15 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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