diff options
author | nea <nea@nea.moe> | 2023-07-31 21:27:07 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-07-31 21:27:07 +0200 |
commit | c3e1bab941f47dfd5ef5c55805015ee5d47da802 (patch) | |
tree | b4db354834ad01260b2c544ae6bfe7e73de00a07 /src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt | |
parent | d8ee0c458a31352eefdb2100a53c3af268b2bb53 (diff) | |
download | firmament-c3e1bab941f47dfd5ef5c55805015ee5d47da802.tar.gz firmament-c3e1bab941f47dfd5ef5c55805015ee5d47da802.tar.bz2 firmament-c3e1bab941f47dfd5ef5c55805015ee5d47da802.zip |
Improve config gui handling
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt b/src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt index af83aee..7b7186a 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt @@ -18,33 +18,27 @@ package moe.nea.firmament.gui.config +import io.github.cottonmc.cotton.gui.widget.WBox import io.github.cottonmc.cotton.gui.widget.WGridPanel import io.github.cottonmc.cotton.gui.widget.WLabel import io.github.cottonmc.cotton.gui.widget.WWidget +import io.github.cottonmc.cotton.gui.widget.data.Axis import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment import net.minecraft.client.gui.screen.Screen import net.minecraft.text.Text +import moe.nea.firmament.gui.WFixedPanel +import moe.nea.firmament.gui.WSplitPanel class GuiAppender(val width: Int, val screenAccessor: () -> Screen) { - private var row = 0 - - - - internal val panel = WGridPanel().also { it.setGaps(4, 4) } - internal val reloadables = mutableListOf<(() -> Unit)>() - fun set(x: Int, y: Int, w: Int, h: Int, widget: WWidget) { - panel.add(widget, x, y + row, w, h) + internal val panel = WBox(Axis.VERTICAL).also { + it.setSize(width, 200) } - + internal val reloadables = mutableListOf<(() -> Unit)>() fun onReload(reloadable: () -> Unit) { reloadables.add(reloadable) } - fun skipRows(r: Int) { - row += r - } - fun appendLabeledRow(label: Text, right: WWidget) { appendSplitRow( WLabel(label).setVerticalAlignment(VerticalAlignment.CENTER), @@ -53,14 +47,10 @@ class GuiAppender(val width: Int, val screenAccessor: () -> Screen) { } fun appendSplitRow(left: WWidget, right: WWidget) { - val lw = width / 2 - set(0, 0, lw, 1, left) - set(lw, 0, width - lw, 1, right) - skipRows(1) + appendFullRow(WSplitPanel(left.also { it.setSize(width / 2, 18) }, right.also { it.setSize(width / 2, 18) })) } fun appendFullRow(widget: WWidget) { - set(0, 0, width, 1, widget) - skipRows(1) + panel.add(widget, width, 18) } } |