Skip to content

Instantly share code, notes, and snippets.

@programaths
Created August 13, 2015 14:35
Show Gist options
  • Save programaths/90a694a8d830e17becd0 to your computer and use it in GitHub Desktop.
Save programaths/90a694a8d830e17becd0 to your computer and use it in GitHub Desktop.
Mimmic FXML in Kotlin using only one extention method
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()
}
}
@abreslav
Copy link

You builder function seem to be the same as the library function with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment