blob: 69a59f5fa36cbf42ab6a6d70d1693ff91b678bd4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package moe.nea.firmament.gui
import io.github.cottonmc.cotton.gui.widget.WPanel
import io.github.cottonmc.cotton.gui.widget.WWidget
import io.github.cottonmc.cotton.gui.widget.data.Axis
data class WCenteringPanel(
val child: WWidget,
val axis: Axis,
) : WPanel() {
init {
child.parent = this
}
override fun setSize(x: Int, y: Int) {
super.setSize(x, y)
if (!child.canResize()) return
if (axis == Axis.HORIZONTAL) {
child.setSize(child.width, y)
} else {
child.setSize(x, child.height)
}
}
override fun layout() {
super.layout()
child.setLocation(
axis.choose((child.width + width) / 2, child.x),
axis.choose(child.y, (child.height + height) / 2),
)
}
}
|