@@ -5,14 +5,13 @@ import com.lambda.core.Loadable
55import com.lambda.newgui.component.core.UIBuilder
66import com.lambda.newgui.component.layout.Layout
77import com.lambda.newgui.impl.clickgui.settings.BooleanButton.Companion.booleanSetting
8- import java.lang.reflect.Type
98import kotlin.reflect.KClass
109
1110object GuiManager : Loadable {
12- val typeMap = mutableMapOf<Type , (owner: Layout , converted: Any ) - > Layout > ()
11+ val typeMap = mutableMapOf<KClass < * > , (owner: Layout , converted: Any ) -> Layout > ()
1312
1413 private inline fun <reified T : Any > typeAdapter (noinline block : (Layout , T ) -> Layout ) {
15- typeMap[T ::class .java ] = { owner, converted -> block(owner, converted as T ) }
14+ typeMap[T ::class ] = { owner, converted -> block(owner, converted as T ) }
1615 }
1716
1817 override fun load (): String {
@@ -27,8 +26,9 @@ object GuiManager : Loadable {
2726 * Attempts to convert the given [reference] to the [Layout]
2827 */
2928 @UIBuilder
30- inline fun <reified T : Any > Layout.layoutOf (reference : T , block : Layout .() -> Unit = {}): Layout ? {
31- val adapter = typeMap[T ::class .java] ? : return null
32- return adapter(this , reference).apply (children::add).apply (block)
33- }
34- }
29+ inline fun Layout.layoutOf (
30+ reference : Any ,
31+ block : Layout .() -> Unit = {}
32+ ): Layout ? =
33+ typeMap[reference::class ]?.invoke(this , reference)?.apply (block)
34+ }
0 commit comments