Reputation: 5964
Suppose I want to save a view's height and width value using appConfig in tornadofx. Is there anyway I can bind these properties to appConfig, so that when I save the config, the latest value of height and width will always be saved?
Upvotes: 0
Views: 170
Reputation: 7297
If what you want to do is to save the current width/height of the Window and restore that when the View is docked again, you can override onDock to do both operations there:
override fun onDock() {
if (config["w"] != null && config["h"] != null) {
currentWindow?.apply {
width = config.double("w")!!
height = config.double("h")!!
}
}
currentWindow?.apply {
Bindings.add(widthProperty(), heightProperty()).onChange {
with (config) {
put("w", width.toString())
put("h", height.toString())
save()
}
}
}
}
Upvotes: 3