Add and improve domain (WIP)

This commit is contained in:
2024-06-11 11:04:02 +02:00
parent 1b9c8633c9
commit f891dea885
11 changed files with 232 additions and 29 deletions

View 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>