Created
August 13, 2015 14:35
-
-
Save programaths/90a694a8d830e17becd0 to your computer and use it in GitHub Desktop.
Mimmic FXML in Kotlin using only one extention method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args:Array<String>){ | |
Application.launch(javaClass<Foo>()) | |
} | |
fun <T:Any> T.builder(f:T.()->Unit):T{ | |
this.f() | |
return this | |
} | |
class Foo : Application(){ | |
override fun start(primaryStage: Stage) { | |
val s=Scene(AnchorPane().builder { | |
this.getChildren().addAll( | |
TextField("e").builder { | |
AnchorPane.setLeftAnchor(this,0.toDouble()) | |
AnchorPane.setRightAnchor(this,200.toDouble()) | |
setPrefWidth(300.toDouble()) | |
}, | |
Button().builder { | |
AnchorPane.setRightAnchor(this,0.toDouble()) | |
setPrefWidth(200.toDouble()) | |
} | |
) | |
}) | |
primaryStage.setScene(s) | |
primaryStage.show() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You
builder
function seem to be the same as the library functionwith