Skip to content

Instantly share code, notes, and snippets.

@pandulapeter
Created February 20, 2018 13:33
Show Gist options
  • Save pandulapeter/e9091ee28b8193ab02552e19eb9ec1a3 to your computer and use it in GitHub Desktop.
Save pandulapeter/e9091ee28b8193ab02552e19eb9ec1a3 to your computer and use it in GitHub Desktop.
IntervalDelegate
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