Skip to content

Instantly share code, notes, and snippets.

@nimatrueway
Forked from jschneider/MigPaneExtensions.kt
Last active September 12, 2020 21:15
Show Gist options
  • Save nimatrueway/1a9cdeb0023f261cbea35730fc8bab03 to your computer and use it in GitHub Desktop.
Save nimatrueway/1a9cdeb0023f261cbea35730fc8bab03 to your computer and use it in GitHub Desktop.
MigPane extension methods for TornadoFX
import javafx.event.EventTarget
import javafx.scene.Node
import org.tbee.javafx.scene.layout.fxml.MigPane
import tornadofx.attachTo
fun EventTarget.migPane(op: MigPane.() -> Unit = {}): MigPane {
return MigPane().attachTo(this, op)
}
var Node.cc: String
get() = throw IllegalAccessError("No getter")
set(value) {
val migLayout = this.parent
if (migLayout is MigPane)
migLayout.setComponentConstraints(this, value)
else
throw IllegalStateException("$this is not the immediate child of a MigPane!")
}
@nimatrueway
Copy link
Author

Examples:

import tornadofx.*

class ConsoleRunner : View() {
	override val root = migPane {
		layout = "debug, fill, ins 10"
		cols = "[grow 1][grow 1]"
		rows = "[fill, grow 1][bottom, grow 0]"
		prefHeight = 200.0
		prefWidth = 500.0
		textarea {
			id = "dragPane"
			cc = "span 2, grow, wrap"
		}
		button("Ok") {
			id = "runButton"
			cc = "ax left, sgx bottom_buttons"
		}
		button("Exit") {
			id = "exitButton"
			cc = "ax right, sgx bottom_buttons"
		}
	}
}

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