Skip to content

Instantly share code, notes, and snippets.

@bng86
Created September 29, 2021 13:35
Show Gist options
  • Save bng86/04f79a6e36429488729f2bbe215c202b to your computer and use it in GitHub Desktop.
Save bng86/04f79a6e36429488729f2bbe215c202b to your computer and use it in GitHub Desktop.
sealed class WidgetType {
data class SlideBar(val min: Int, val max: Int, val step: Int) : WidgetType()
data class Radio(val items: List<RadioItem>) : WidgetType()
}
data class RadioItem(
val name: String,
val value: Int
)
enum class Widget(val widgetType: WidgetType) {
FOO(WidgetType.SlideBar(0, 9, 3)),
Bar(WidgetType.SlideBar(0, 100, 3)),
XXX(WidgetType.Radio(
listOf(RadioItem("aaa", 0), RadioItem("bbb", 1)))
)
}
fun main() {
val widgets = TODO()
val widgetType = Widget.FOO.widgetType
when (widgetType) {
is WidgetType.Radio -> {
widgetType.items
}
is WidgetType.SlideBar -> {
widgetType.min
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment