Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Guild Member List & Guild Search Lists are now fully clickable + Grid fixes #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/main/kotlin/com/mineinabyss/guiy/components/Grid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.mineinabyss.guiy.layout.Layout
import com.mineinabyss.guiy.layout.MeasurePolicy
import com.mineinabyss.guiy.layout.MeasureResult
import com.mineinabyss.guiy.modifiers.Modifier
import kotlin.math.ceil

/**
* A grid layout component that finds the largest child size, and then places children in a grid based on this size.
Expand Down Expand Up @@ -47,22 +48,19 @@ fun gridMeasurePolicy(vertical: Boolean) = MeasurePolicy { measurables, constrai
constraints.minWidth,
constraints.minHeight
) {}

// Get width and height divisible by cellWidth, cellHeight
val itemsPerLine =
if (vertical) constraints.maxWidth / cellWidth
else constraints.maxHeight / cellHeight

val (width, height) = if (vertical) {
val w = itemsPerLine * cellWidth
val h = ((placeables.size / itemsPerLine) + 1) * cellHeight
val h = (ceil(placeables.size / itemsPerLine.toFloat()).toInt()) * cellHeight
w to h
} else {
val w = ((placeables.size / itemsPerLine) + 1) * cellWidth
val w = (ceil(placeables.size / itemsPerLine.toFloat()).toInt()) * cellWidth
val h = itemsPerLine * cellHeight
w to h
}

MeasureResult(width, height) {
var placeAtX = 0
var placeAtY = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mineinabyss.guiy.components.lists
import androidx.compose.runtime.*
import com.mineinabyss.guiy.components.Item
import com.mineinabyss.guiy.components.Spacer
import com.mineinabyss.guiy.components.VerticalGrid
import com.mineinabyss.guiy.jetpack.Alignment
import com.mineinabyss.guiy.jetpack.Arrangement
import com.mineinabyss.guiy.layout.Box
Expand Down Expand Up @@ -35,14 +36,33 @@ fun <T> Paginated(
content: @Composable (page: List<T>) -> Unit,
) {
var size by remember { mutableStateOf(Size(0, 0)) }
var clearSize by remember { mutableStateOf(Size(0, 0)) }
val itemsPerPage = size.width * size.height

Box(Modifier.fillMaxSize()) {
val start = page * itemsPerPage
val end = (page + 1) * itemsPerPage
val pageItems = remember(items, start, end) {
if (start < 0) emptyList()
else items.subList(start, end.coerceAtMost(items.size))
}

// Extract original size of contents
Box(Modifier.onSizeChanged{
size = it
}) {
content(pageItems)
}

// Clear out the previous Box
Box(Modifier.onSizeChanged{
clearSize = it
}.fillMaxSize()) {
VerticalGrid(){
MutableList(clearSize.width * clearSize.height) {Item(null)}
}
}

NavbarLayout(
position = navbarPosition,
navbar = {
Expand All @@ -54,9 +74,8 @@ fun <T> Paginated(
}
},
content = {
Box(Modifier.onSizeChanged {
size = it
}) {
// Actually render the correct amount of items into a box that can fit them including offsets
Box(Modifier.fillMaxSize()) {
content(pageItems)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.mineinabyss.guiy.components.lists

import androidx.compose.runtime.*
import com.mineinabyss.guiy.components.Item
import com.mineinabyss.guiy.components.Spacer
import com.mineinabyss.guiy.components.VerticalGrid
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.guiy.modifiers.*
import com.mineinabyss.idofront.items.editItemMeta
import org.bukkit.Material
import org.bukkit.inventory.ItemStack
Expand Down Expand Up @@ -36,15 +36,35 @@ fun <T> Scrollable(
content: @Composable (page: List<T>) -> Unit,
) {
var size by remember { mutableStateOf(Size(0, 0)) }
var clearSize by remember { mutableStateOf(Size(0, 0)) }

val itemsPerLine = if (scrollDirection == ScrollDirection.VERTICAL) size.width else size.height
val totalLines = if (scrollDirection == ScrollDirection.VERTICAL) size.height else size.width
Box(Modifier.fillMaxSize()) {

Box(Modifier.fillMaxSize().onSizeChanged {println("Exterior box size: $it")}) {
val start = line * itemsPerLine
val end = start + (itemsPerLine * totalLines)
val pageItems = remember(items, start, end) {
if (start < 0) emptyList()
else items.subList(start, end.coerceAtMost(items.size))
}

// Extract original size of contents
Box(Modifier.onSizeChanged{
size = it
}) {
content(pageItems)
}

// Clear out the previous Box
Box(Modifier.onSizeChanged{
clearSize = it
}.fillMaxSize()) {
VerticalGrid(){
MutableList(clearSize.width * clearSize.height) {Item(null)}
}
}

NavbarLayout(
position = navbarPosition,
navbar = {
Expand All @@ -56,12 +76,12 @@ fun <T> Scrollable(
}
},
content = {
Box(Modifier.onSizeChanged {
size = it
}) {
// Actually render the correct amount of items into a box that can fit them including offsets
Box(Modifier.fillMaxSize()) {
content(pageItems)
}
}

)
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mineinabyss/guiy/layout/Layout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ inline fun Layout(
set(measurePolicy) { this.measurePolicy = it }
set(renderer) { this.renderer = it }
//TODO dunno if this works
set(canvas) { this.canvas = it}
set(canvas) { this.canvas = it }
set(modifier) { this.modifier = it }
},
content = content,
Expand Down