screen padding

This commit is contained in:
nea
2022-08-04 03:56:53 +02:00
parent 2625eeb7de
commit c83890afc8
4 changed files with 92 additions and 29 deletions

View File

@@ -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)
}
}
}

View File

@@ -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
}
}