Skip to content

Commit

Permalink
Replace ImGui with generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaiR committed Jan 15, 2024
1 parent 8264c7c commit 38f22b8
Show file tree
Hide file tree
Showing 5 changed files with 2,901 additions and 10,746 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tool.generator.api.definition._package.imgui

import tool.generator.api.definition.Definition
import tool.generator.api.definition.DisableDefinition
import tool.generator.api.definition._package.imgui.binding.ImGuiApi
import tool.generator.api.definition.dsl.define
import tool.generator.api.definition.dsl.defines
Expand All @@ -10,12 +9,15 @@ import tool.generator.api.definition.node.type.method.MethodDefinitionNode
import tool.generator.api.definition.node.type.method.ext.*
import tool.generator.api.definition.node.type.method.ext.ret.ReturnTypeGeneral

@DisableDefinition
class ImGui : Definition {
companion object {
private const val API_FIELD_NAME = "api"
}

private val excludedMethods = setOf(
"preInputText",
)

override fun getNodes(): Collection<DefinitionNode> {
return defines(
define {
Expand All @@ -26,8 +28,7 @@ class ImGui : Definition {
* Can be replaced with custom API implementation if required.
*/
public static ${getApiClass()} $API_FIELD_NAME = new ${getApiClass()}();
""".trimIndent()
)
""".trimIndent())
},
collectImGuiApiMethods()
)
Expand All @@ -41,6 +42,7 @@ class ImGui : Definition {
return ImGuiApi().getNodes()
.filterIsInstance<MethodDefinitionNode>()
.filterNot { it.signature.isNative }
.filterNot { excludedMethods.contains(it.signature.name) }
.map { method ->
method.signature.isStatic = true
method.body.lines = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import tool.generator.api.definition.dsl.method.ArgsDsl
import tool.generator.api.definition.dsl.method.MethodsDsl
import tool.generator.api.definition.node.transform.method.METHOD_JNI_PREFIX
import tool.generator.api.definition.node.transform.method.THIS_PTR_CALL_JVM
import tool.generator.api.definition.node.transform.method.TYPE_IM_BOOL

fun DefineDsl.manualMethods() {
methods {
checkboxMethod()
comboMethods()
listBoxMethods()
isMousePosValidMethod()
Expand All @@ -18,6 +20,25 @@ fun DefineDsl.manualMethods() {
inputText()
}

private fun MethodsDsl.checkboxMethod() {
method {
signature {
public()
name("checkbox")
args {
argString("label")
argBoolean("v")
}
}
body {
line("return ${THIS_PTR_CALL_JVM}checkbox(label, new $TYPE_IM_BOOL(v));")
}
returnType {
asBoolean()
}
}
}

private fun MethodsDsl.comboMethods() {
val methodName = "combo"
val nMethodName = "${METHOD_JNI_PREFIX}Combo"
Expand Down Expand Up @@ -705,6 +726,12 @@ private fun DefineDsl.inputText() {
""".trimIndent()
)

line("""
{
${THIS_PTR_CALL_JVM}${METHOD_JNI_PREFIX}InitInputTextData();
}
""".trimIndent())

methods {
method {
signature {
Expand Down
Loading

0 comments on commit 38f22b8

Please sign in to comment.