Sam Marz
09/20/2021, 3:21 PMSam Marz
09/20/2021, 3:23 PMval red_blood = 0xFFb92b27
val red_orange = 0xFFb12b11
val colors = listOf(Color(red_blood),Color(red_orange) ...)
print: red_blood, red_orange, ...Joffrey
09/20/2021, 3:28 PMJoffrey
09/20/2021, 3:30 PMobject
and use property delegates to automatically add the color names into a list that you can later printSam Marz
09/20/2021, 3:34 PMJoffrey
09/20/2021, 3:43 PMJoffrey
09/20/2021, 3:45 PMclass DumbColorGetter(val value: Long) : ReadOnlyProperty<MyColors, Long> {
override operator fun getValue(thisRef: MyColors, property: KProperty<*>): Long = value
}
object MyColors {
private val _allNames = mutableListOf<String>()
val all get() = _allNames
class NamedColor(val value: Long) {
operator fun provideDelegate(thisRef: MyColors, prop: KProperty<*>): ReadOnlyProperty<MyColors, Long> {
_allNames.add(prop.name)
return DumbColorGetter(value)
}
}
val red_blood by NamedColor(0xFFb92b27)
val red_orange by NamedColor(0xFFb12b11)
}
This way you can have the list of all your color names using MyCOlors.all
Joffrey
09/20/2021, 3:46 PMLong
because those were the types of your color constants, but you could use UInt
insteadJoffrey
09/20/2021, 3:48 PMSam Marz
09/20/2021, 3:56 PM