Merge branch '1.21' into new-container-api
This commit is contained in:
commit
65bf4dc9d0
@ -82,6 +82,10 @@ data class DockProperty(val left: Float = 0f, val top: Float = 0f, val right: Fl
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val EMPTY = DockProperty()
|
val EMPTY = DockProperty()
|
||||||
|
|
||||||
|
fun all(value: Float): DockProperty {
|
||||||
|
return DockProperty(value, value, value, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
|
||||||
import ru.dbotthepony.mc.otm.core.collect.filter
|
import ru.dbotthepony.mc.otm.core.collect.filter
|
||||||
import ru.dbotthepony.mc.otm.core.collect.maybe
|
import ru.dbotthepony.mc.otm.core.collect.maybe
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
open class GridPanel<out S : Screen>(
|
open class GridPanel<out S : Screen>(
|
||||||
screen: S,
|
screen: S,
|
||||||
@ -20,21 +21,110 @@ open class GridPanel<out S : Screen>(
|
|||||||
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
||||||
var columns: Int = columns
|
var columns: Int = columns
|
||||||
set(value) {
|
set(value) {
|
||||||
|
if (field != value) {
|
||||||
field = value
|
field = value
|
||||||
invalidateLayout()
|
invalidateLayout()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var rows: Int = rows
|
var rows: Int = rows
|
||||||
set(value) {
|
set(value) {
|
||||||
|
if (field != value) {
|
||||||
field = value
|
field = value
|
||||||
invalidateLayout()
|
invalidateLayout()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var gravity: RenderGravity = RenderGravity.CENTER_CENTER
|
var gravity: RenderGravity = RenderGravity.CENTER_CENTER
|
||||||
set(value) {
|
set(value) {
|
||||||
|
if (field != value) {
|
||||||
field = value
|
field = value
|
||||||
invalidateLayout()
|
invalidateLayout()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var layout: Layout = Layout.TOP_LEFT
|
||||||
|
set(value) {
|
||||||
|
if (field != value) {
|
||||||
|
field = value
|
||||||
|
invalidateLayout()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Layout {
|
||||||
|
TOP_LEFT {
|
||||||
|
override fun rows(last: Int): IntIterator {
|
||||||
|
return (0 until last).iterator()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun columns(last: Int): IntIterator {
|
||||||
|
return (0 until last).iterator()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
TOP_RIGHT {
|
||||||
|
override fun rows(last: Int): IntIterator {
|
||||||
|
return (0 until last).iterator()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun columns(last: Int): IntIterator {
|
||||||
|
return (last - 1 downTo 1).iterator()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
BOTTOM_LEFT {
|
||||||
|
override fun rows(last: Int): IntIterator {
|
||||||
|
return (last - 1 downTo 1).iterator()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun columns(last: Int): IntIterator {
|
||||||
|
return (0 until last).iterator()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
BOTTOM_RIGHT {
|
||||||
|
override fun rows(last: Int): IntIterator {
|
||||||
|
return (last - 1 downTo 1).iterator()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun columns(last: Int): IntIterator {
|
||||||
|
return (last - 1 downTo 1).iterator()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
abstract fun rows(last: Int): IntIterator
|
||||||
|
abstract fun columns(last: Int): IntIterator
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun sizeToContents() {
|
||||||
|
if (visibleChildren.isEmpty()) {
|
||||||
|
// nothing to size against
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
visibleChildren.forEach { it.sizeToContents() }
|
||||||
|
|
||||||
|
var width = 0f
|
||||||
|
var height = 0f
|
||||||
|
|
||||||
|
val children = visibleChildren.iterator().filter { it.dock == Dock.NONE }
|
||||||
|
|
||||||
|
for (row in layout.rows(rows)) {
|
||||||
|
var maxHeight = 0f
|
||||||
|
var rowWidth = 0f
|
||||||
|
|
||||||
|
for (column in layout.columns(columns)) {
|
||||||
|
val nextChild = children.maybe() ?: break
|
||||||
|
rowWidth += nextChild.width + nextChild.dockMargin.horizontal
|
||||||
|
maxHeight = max(maxHeight, nextChild.height + nextChild.dockMargin.vertical)
|
||||||
|
}
|
||||||
|
|
||||||
|
height += maxHeight
|
||||||
|
width = max(width, rowWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.width = width
|
||||||
|
this.height = height
|
||||||
|
}
|
||||||
|
|
||||||
override fun performLayout() {
|
override fun performLayout() {
|
||||||
super.performLayout()
|
super.performLayout()
|
||||||
@ -43,11 +133,11 @@ open class GridPanel<out S : Screen>(
|
|||||||
var totalWidth = 0f
|
var totalWidth = 0f
|
||||||
var totalHeight = 0f
|
var totalHeight = 0f
|
||||||
|
|
||||||
for (row in 0 until rows) {
|
for (row in layout.rows(rows)) {
|
||||||
var maxHeight = 0f
|
var maxHeight = 0f
|
||||||
var width = 0f
|
var width = 0f
|
||||||
|
|
||||||
for (column in 0 until columns) {
|
for (column in layout.columns(columns)) {
|
||||||
val child = children.maybe() ?: break
|
val child = children.maybe() ?: break
|
||||||
width += child.dockedWidth
|
width += child.dockedWidth
|
||||||
maxHeight = maxHeight.coerceAtLeast(child.dockedHeight)
|
maxHeight = maxHeight.coerceAtLeast(child.dockedHeight)
|
||||||
@ -64,11 +154,11 @@ open class GridPanel<out S : Screen>(
|
|||||||
totalWidth = 0f
|
totalWidth = 0f
|
||||||
totalHeight = 0f
|
totalHeight = 0f
|
||||||
|
|
||||||
for (row in 0 until rows) {
|
for (row in layout.rows(rows)) {
|
||||||
var maxHeight = 0f
|
var maxHeight = 0f
|
||||||
var width = 0f
|
var width = 0f
|
||||||
|
|
||||||
for (column in 0 until columns) {
|
for (column in layout.columns(columns)) {
|
||||||
val child = children.maybe() ?: break
|
val child = children.maybe() ?: break
|
||||||
child.x = alignX + width
|
child.x = alignX + width
|
||||||
child.y = alignY + totalHeight
|
child.y = alignY + totalHeight
|
||||||
|
Loading…
Reference in New Issue
Block a user