aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-06-01 23:10:09 +0200
committernea <nea@nea.moe>2023-06-01 23:10:09 +0200
commit7c60db4fbf6b67dc5144436d2387331219128d3c (patch)
tree53eb08b732d802ab76b39a4f650aaf9fc5564a53 /src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt
parent6e3c41fbafd837b891bc01e3baa0424effcdb734 (diff)
downloadfirmament-7c60db4fbf6b67dc5144436d2387331219128d3c.tar.gz
firmament-7c60db4fbf6b67dc5144436d2387331219128d3c.tar.bz2
firmament-7c60db4fbf6b67dc5144436d2387331219128d3c.zip
Profile Viewer Skill Page v1
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt')
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt b/src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt
new file mode 100644
index 0000000..c6d1f56
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt
@@ -0,0 +1,34 @@
+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),
+ )
+ }
+
+
+}