Add and improve domain (WIP)
This commit is contained in:
44
composeApp/src/commonMain/kotlin/domain/items.kt
Normal file
44
composeApp/src/commonMain/kotlin/domain/items.kt
Normal file
@@ -0,0 +1,44 @@
|
||||
@file:OptIn(ExperimentalResourceApi::class)
|
||||
|
||||
package domain
|
||||
|
||||
import org.jetbrains.compose.resources.DrawableResource
|
||||
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
||||
|
||||
fun category(block: CategoryContext.() -> Unit): ItemCategory {
|
||||
class CategoryImpl(val items: MutableList<ItemImpl>) :
|
||||
ItemCategory, List<Item> by items {
|
||||
inner class ItemImpl(
|
||||
override val image: DrawableResource
|
||||
) : Item {
|
||||
override val category: CategoryImpl = this@CategoryImpl
|
||||
|
||||
init {
|
||||
items.add(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val ctx = object : CategoryContext {
|
||||
val category = CategoryImpl(mutableListOf())
|
||||
|
||||
override fun item(image: DrawableResource) {
|
||||
category.ItemImpl(image)
|
||||
}
|
||||
}
|
||||
ctx.block()
|
||||
return ctx.category
|
||||
}
|
||||
|
||||
interface CategoryContext {
|
||||
fun item(image: DrawableResource)
|
||||
}
|
||||
|
||||
interface Item {
|
||||
val category: ItemCategory
|
||||
|
||||
@OptIn(ExperimentalResourceApi::class)
|
||||
val image: DrawableResource
|
||||
}
|
||||
|
||||
interface ItemCategory : List<Item>
|
||||
Reference in New Issue
Block a user