Skip to content

Commit

Permalink
feat: rough draft for scrollable type
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jun 8, 2024
1 parent 4fc09f1 commit 2047735
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fun <T> Paginated(
}

@Composable
private inline fun NavbarButtons(
inline fun NavbarButtons(
navbarPosition: NavbarPosition,
background: ItemStack?,
crossinline content: @Composable () -> Unit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.mineinabyss.guiy.components.lists

import androidx.compose.runtime.*
import com.mineinabyss.guiy.components.Spacer
import com.mineinabyss.guiy.layout.Box
import com.mineinabyss.guiy.layout.Size
import com.mineinabyss.guiy.modifiers.Modifier
import com.mineinabyss.guiy.modifiers.fillMaxSize
import com.mineinabyss.guiy.modifiers.onSizeChanged
import com.mineinabyss.idofront.items.editItemMeta
import org.bukkit.Material
import org.bukkit.inventory.ItemStack

@Composable
fun <T> Scrollable(
items: List<T>,
startLine: Int,
itemsPerLine: Int,
totalLines: Int,
nextButton: @Composable () -> Unit,
previousButton: @Composable () -> Unit,
navbarPosition: NavbarPosition = NavbarPosition.BOTTOM,
navbarBackground: ItemStack? = remember {
ItemStack(Material.GRAY_STAINED_GLASS_PANE).editItemMeta {
isHideTooltip = true
}
},
content: @Composable (page: List<T>) -> Unit,
) {
var size by remember { mutableStateOf(Size(0, 0)) }
Box(Modifier.fillMaxSize()) {
val start = startLine * itemsPerLine
val end = (startLine + 1) * itemsPerLine * totalLines
val pageItems = remember(start, end) {
if (start < 0) emptyList()
else items.subList(start, end.coerceAtMost(items.size))
}
NavbarLayout(
position = navbarPosition,
navbar = {
NavbarButtons(navbarPosition, navbarBackground) {
if (startLine > 0) previousButton()
//else Spacer(1, 1)
if (end < items.size) nextButton()
//else Spacer(1, 1)
}
},
content = {
Box(Modifier.fillMaxSize().onSizeChanged {
size = it
}) {
content(pageItems)
}
}
)
}
}

0 comments on commit 2047735

Please sign in to comment.