Anindya Chatterjee
Anindya Chatterjee

Reputation: 5964

Is there any way to bind a property to appConfig in tornadofx?

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

Answers (1)

Edvin Syse
Edvin Syse

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

Related Questions