edvin / tornadofx

Lightweight JavaFX Framework for Kotlin
Apache License 2.0
3.67k stars 269 forks source link

How to bind a spinner to a LongProperty? #1320

Closed SKeeneCode closed 3 years ago

SKeeneCode commented 3 years ago

Short and simple: The following code does not compile:

            val longProperty = (0L).toProperty()
            spinner<Long> {
               bind(longProperty)
            }

How can I bind my spinner value to a longProperty? Been scratching at this for a few hours now.

I noticed if I cast the property like so: val longProperty = (0L).toProperty() as ObservableValue<Long> it accepts the binding, but then I lose all the useful utility of my longProperty.

SchweinchenFuntik commented 3 years ago

close ?

SKeeneCode commented 3 years ago

I realized the obvious: I can cast to ObservableValue<Long> where I bind the spinner:

bind(longProperty as ObservableValue<Long>)

Which means I can use longProperty just fine elsewhere. A silly thing I didn't spot because I was tired :)

Although, if you think there's a better way I'm open ears.

I'm surprised javafx does not have a SpinnerLongValueFactory already, leaving it to the user to write. Might be a PR candidate for tornadofx.

SchweinchenFuntik commented 3 years ago

There is a nuance in type inference. Will need to be corrected