Skip to content

Commit

Permalink
fix: Paginated and Scrolling menus did not correctly listen to items …
Browse files Browse the repository at this point in the history
…recomposition

test: Update paginated menu example to allow clicking on items to remove them
  • Loading branch information
0ffz committed Nov 10, 2024
1 parent bb34982 commit 1c4ed32
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kotlin.code.style=official
group=com.mineinabyss
version=0.12
idofrontVersion=0.25.1
idofrontVersion=0.25.17
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,32 @@ class GuiyExamplePlugin : JavaPlugin() {
"guiyexample" {
"arrangement" {
playerExecutes {
guiy {
ArrangementMenu(player)
}
guiy { ArrangementMenu(player) }
}
}
"animated" {
playerExecutes {
guiy {
AnimatedTitle(player)
}
guiy { AnimatedTitle(player) }
}
}
"creative" {
playerExecutes {
guiy {
CreativeMenu(player)
}
guiy { CreativeMenu(player) }
}
}
"cursor" {
playerExecutes {
guiy {
Cursor(player)
}
guiy { Cursor(player) }
}
}
"pagination" {
playerExecutes {
guiy {
PaginatedMenu(player)
}
guiy { PaginatedMenu(player) }
}
}
"scrolling" {
playerExecutes {
guiy {
ScrollingMenu(player)
}
guiy { ScrollingMenu(player) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ fun PaginatedMenu(player: Player) {
onClose = { owner.exit() },
modifier = Modifier.fillMaxSize()
) {
val items = remember {
var items by remember {
val materials = Material.entries
(1..100).map { ItemStack(materials[it]) }
mutableStateOf((1..100).map { ItemStack(materials[it]) })
}
var page by remember { mutableStateOf(0) }
Paginated(
Expand All @@ -38,7 +38,7 @@ fun PaginatedMenu(player: Player) {
) { pageItems ->
HorizontalGrid(Modifier.size(4, 5)) {
pageItems.forEach { item ->
Item(item)
Item(item, modifier = Modifier.clickable { items = items - item })
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun <T> Paginated(
Box(Modifier.fillMaxSize()) {
val start = page * itemsPerPage
val end = (page + 1) * itemsPerPage
val pageItems = remember(start, end) {
val pageItems = remember(items, start, end) {
if (start < 0) emptyList()
else items.subList(start, end.coerceAtMost(items.size))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun <T> Scrollable(
Box(Modifier.fillMaxSize()) {
val start = line * itemsPerLine
val end = start + (itemsPerLine * totalLines)
val pageItems = remember(start, end) {
val pageItems = remember(items, start, end) {
if (start < 0) emptyList()
else items.subList(start, end.coerceAtMost(items.size))
}
Expand Down

0 comments on commit 1c4ed32

Please sign in to comment.