From c83890afc8304fc0a1b1d0ea8da791c6d9b90439 Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 4 Aug 2022 03:56:53 +0200 Subject: screen padding --- .../nea/notenoughupdates/gui/RepoManagementGui.kt | 64 ++++++++++++++++------ .../notenoughupdates/gui/WGridPanelWithPadding.kt | 33 +++++++++++ 2 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 src/main/kotlin/moe/nea/notenoughupdates/gui/WGridPanelWithPadding.kt (limited to 'src/main/kotlin/moe/nea/notenoughupdates/gui') diff --git a/src/main/kotlin/moe/nea/notenoughupdates/gui/RepoManagementGui.kt b/src/main/kotlin/moe/nea/notenoughupdates/gui/RepoManagementGui.kt index 115b9f8..ecdb05b 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/gui/RepoManagementGui.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/gui/RepoManagementGui.kt @@ -1,25 +1,35 @@ package moe.nea.notenoughupdates.gui import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription -import io.github.cottonmc.cotton.gui.widget.WGridPanel +import io.github.cottonmc.cotton.gui.widget.WButton import io.github.cottonmc.cotton.gui.widget.WLabel import io.github.cottonmc.cotton.gui.widget.WTextField import io.github.cottonmc.cotton.gui.widget.WToggleButton +import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment import io.github.cottonmc.cotton.gui.widget.data.Insets +import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment import moe.nea.notenoughupdates.repo.RepoManager import net.minecraft.network.chat.Component import java.util.function.Consumer class RepoManagementGui : LightweightGuiDescription() { init { - val root = WGridPanel() + val root = WGridPanelWithPadding(verticalPadding = 5) setRootPanel(root) - - root.setSize(256, 240) + root.setSize(0, 0) root.insets = Insets.ROOT_PANEL + var col = 0 + + WLabel(Component.literal("NotEnoughUpdates Repo Settings")).apply { + root.add(this, 0, col, 11, 1) + this.verticalAlignment = VerticalAlignment.TOP + this.horizontalAlignment = HorizontalAlignment.CENTER + } + col += 1 WLabel(Component.literal("Auto Update")).apply { - root.add(this, 0, 1, 5, 1) + root.add(this, 0, col, 5, 1) + this.verticalAlignment = VerticalAlignment.CENTER } WToggleButton(Component.literal("Auto Update")).apply { @@ -28,50 +38,72 @@ class RepoManagementGui : LightweightGuiDescription() { RepoManager.config.autoUpdate = it RepoManager.markDirty() } - root.add(this, 5, 1, 1, 1) + root.add(this, 5, col, 1, 1) } - + col += 1 WLabel(Component.literal("Repo Username")).apply { - root.add(this, 0, 2, 5, 1) + root.add(this, 0, col, 5, 1) + this.verticalAlignment = VerticalAlignment.CENTER + } - WTextField(Component.literal("username")).apply { + val userName = WTextField(Component.literal("username")).apply { this.isEditable = true this.text = RepoManager.config.user this.setChangedListener { RepoManager.config.user = it RepoManager.markDirty() } - root.add(this, 5, 2, 6, 1) + root.add(this, 5, col, 6, 1) } + col += 1 WLabel(Component.literal("Repo Name")).apply { - root.add(this, 0, 3, 5, 1) + root.add(this, 0, col, 5, 1) + this.verticalAlignment = VerticalAlignment.CENTER } - WTextField(Component.literal("repo name")).apply { + val repoName = WTextField(Component.literal("repo name")).apply { this.isEditable = true this.text = RepoManager.config.repo this.setChangedListener { RepoManager.config.repo = it RepoManager.markDirty() } - root.add(this, 5, 3, 6, 1) + root.add(this, 5, col, 6, 1) } + col += 1 WLabel(Component.literal("Repo Branch")).apply { - root.add(this, 0, 4, 5, 1) + root.add(this, 0, col, 5, 1) + this.verticalAlignment = VerticalAlignment.CENTER } - WTextField(Component.literal("repo name")).apply { + val branchName = WTextField(Component.literal("repo branch")).apply { this.isEditable = true this.text = RepoManager.config.branch this.setChangedListener { RepoManager.config.branch = it RepoManager.markDirty() } - root.add(this, 5, 4, 6, 1) + root.add(this, 5, col, 6, 1) + } + col += 1 + + WLabel(Component.literal("Reset to Defaults")).apply { + root.add(this, 0, col, 5, 1) + this.verticalAlignment = VerticalAlignment.CENTER + } + + WButton(Component.literal("Reset")).apply { + this.setOnClick { + branchName.text = "master" + userName.text = "NotEnoughUpdates" + repoName.text = "NotEnoughUpdates-REPO" + RepoManager.markDirty() + } + root.add(this, 5, col, 6, 1) } } } \ No newline at end of file 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 -- cgit