aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-08-04 03:56:53 +0200
committernea <romangraef@gmail.com>2022-08-04 03:56:53 +0200
commitc83890afc8304fc0a1b1d0ea8da791c6d9b90439 (patch)
treef95b2816503b865d78e326448faca350dbec2445 /src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt
parent2625eeb7dedb05b524b08721e1267acdcd93e5c1 (diff)
downloadFirmament-c83890afc8304fc0a1b1d0ea8da791c6d9b90439.tar.gz
Firmament-c83890afc8304fc0a1b1d0ea8da791c6d9b90439.tar.bz2
Firmament-c83890afc8304fc0a1b1d0ea8da791c6d9b90439.zip
screen padding
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt b/src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt
new file mode 100644
index 0000000..287483e
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt
@@ -0,0 +1,33 @@
+package moe.nea.notenoughupdates.gui
+
+import io.github.cottonmc.cotton.gui.widget.WPanelWithInsets
+import io.github.cottonmc.cotton.gui.widget.WWidget
+import io.github.cottonmc.cotton.gui.widget.data.Insets
+
+class WGridPanelWithPadding(
+ val grid: Int = 18,
+ val verticalPadding: Int = 0,
+ val horizontalPadding: Int = 0,
+) : WPanelWithInsets() {
+
+ private inline val vertOffset get() = grid + verticalPadding
+ private inline val horiOffset get() = grid + horizontalPadding
+
+ fun add(w: WWidget, x: Int, y: Int, width: Int = 1, height: Int = 1) {
+ children.add(w)
+ w.parent = this
+ w.setLocation(x * horiOffset + insets.left, y * vertOffset + insets.top)
+ if (w.canResize())
+ w.setSize(
+ grid + (horiOffset * (width - 1)),
+ grid + (vertOffset * (height - 1)),
+ )
+ expandToFit(w, insets)
+ }
+
+ override fun setInsets(insets: Insets): WGridPanelWithPadding {
+ super.setInsets(insets)
+ return this
+ }
+
+} \ No newline at end of file