Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Binding : What do I miss? #999

Open
balage1551 opened this issue May 23, 2019 · 0 comments
Open

Binding : What do I miss? #999

balage1551 opened this issue May 23, 2019 · 0 comments

Comments

@balage1551
Copy link

I use (sometimes complex) bindings with no problem, but stucked with this one.
I have this code (simplified):


    val deltaXProperty = SimpleDoubleProperty(100.0)
    val deltaYProperty = SimpleDoubleProperty(100.0)
    
    
    class TranslateInfo(x: Double = 0.0, y: Double = 0.0) {
        val xProperty = SimpleDoubleProperty(x)
        var x by xProperty
        val yProperty = SimpleDoubleProperty(y)
        var y by yProperty
    
        val translateXProperty = ReadOnlyDoubleWrapper(0.0).apply {
            bind(xProperty.add(deltaXProperty))
        }
        val translateYProperty = ReadOnlyDoubleWrapper(0.0).apply {
            bind(yProperty.doubleBinding(deltaYProperty) { y + deltaYProperty.value } )
        }
    
        override fun toString(): String {
            return "FloorTranslateInfo[x= $x, y=$y, tx=${translateXProperty.value}, ty=${translateYProperty.value}}]"
        }
    }
    
    
    fun main() {
        val t = TranslateInfo(10.0,20.0)
        println("Initial: $t")
        t.x = 30.0
        println("Change x: $t")
        t.y = 40.0
        println("Change y: $t")
    }

The first type of binding I use in translateX works fine and the value is updated. However, using the doubleBinding function doesn't binds the values and the bound value isn't updated.
The output:

Initial: FloorTranslateInfo[x= 10.0, y=20.0, tx=110.0, ty=120.0}]
Change x: FloorTranslateInfo[x= 30.0, y=20.0, tx=130.0, ty=120.0}]
Change y: FloorTranslateInfo[x= 30.0, y=40.0, tx=130.0, ty=120.0}]

It should be some simple mistake I doesn't see, but can't make it work. (I could use the first syntax, but z (which I left out) has a more complex expression with four or five dependencies.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant