Fix cleanup
This commit is contained in:
@@ -71,9 +71,10 @@ fun PuzzleGrid(
|
||||
val allOptions = row.options
|
||||
for (item in row) {
|
||||
var selection by remember { mutableStateOf(item.selection) }
|
||||
val options = remember { allOptions.map { Toggleable(it, item.options.contains(it)) } }
|
||||
val options =
|
||||
remember { allOptions.map { Toggleable(it, item.options.contains(it)) } }
|
||||
LaunchedEffect(item) {
|
||||
item.removedListeners.add { removed ->
|
||||
item.optionsRemovedListeners.add { removed ->
|
||||
options
|
||||
.filter { removed.contains(it.item) }
|
||||
.forEach { it.enabled = false }
|
||||
@@ -88,10 +89,14 @@ fun PuzzleGrid(
|
||||
.padding(8.dp)
|
||||
.weight(1f),
|
||||
options = options,
|
||||
onOptionRemoved = {
|
||||
item.options.remove(it)
|
||||
row.cleanupOptions()
|
||||
},
|
||||
selectedItem = selection,
|
||||
onSelectItem = {
|
||||
item.selection = it
|
||||
grid.cleanupOptions()
|
||||
row.cleanupOptions()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import kotlin.math.min
|
||||
fun <C : ItemClass<C>> Selector(
|
||||
modifier: Modifier = Modifier,
|
||||
options: List<Toggleable<Item<C>>>,
|
||||
onOptionRemoved: (Item<C>?) -> Unit,
|
||||
selectedItem: Item<C>?,
|
||||
onSelectItem: (Item<C>?) -> Unit,
|
||||
) {
|
||||
@@ -54,6 +55,7 @@ fun <C : ItemClass<C>> Selector(
|
||||
matcher = PointerMatcher.mouse(PointerButton.Secondary),
|
||||
onClick = {
|
||||
option.enabled = false
|
||||
onOptionRemoved(option.item)
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user