-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rough draft for scrollable type
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/com/mineinabyss/guiy/components/lists/Scrollable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
) | ||
} | ||
} |