Is there a good way to get the KProperty for a delegate when it's initialized? I'm trying to simplify creating variables for a software that binds UI inputs to variables. I have the get/set working binding property.name, but I need to call a method to tell the UI to create the binding. This should ideally be in the constructor.
Landry Norris
03/07/2024, 6:35 PM
Right now, my delegate looks like
Copy code
class UIValue(val default: Double) {
operator fun setValue(ref: Any?, property: KProperty<*>, value: Double) {
Library.putValue(property.name, value)
}
operator fun getValue(ref: Any?, property: KProperty<*>): Double {
Library.getValue(property.name, default)
}
}
fun uiValue(default: Double) = UIValue(default)
Landry Norris
03/07/2024, 6:36 PM
I need a place to call Library.setDefault(name, value)
Landry Norris
03/07/2024, 6:40 PM
For now, I'm calling this in the getter if it hasn't been called yet, and requiring that all values have a dummy getter call at the start, but I don't love that at all.