Created
February 20, 2018 13:33
-
-
Save pandulapeter/e9091ee28b8193ab02552e19eb9ec1a3 to your computer and use it in GitHub Desktop.
IntervalDelegate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IntervalDelegate( | |
var value: Int, | |
val minValue: Int, | |
val maxValue: Int | |
) : ReadWriteProperty<Any?, Int> { | |
override fun getValue(thisRef: Any?, property: KProperty<*>) = value | |
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Int) { | |
this.value = value.coerceIn(minValue, maxValue) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment