diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-11-18 21:52:30 +0200 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-11-18 21:52:30 +0200 |
commit | b5c5182e32f77db84dee227aadb74aece31ef2f6 (patch) | |
tree | 3a61cc886334a8732c1af52b5244f08a6459f685 /src/testMod | |
parent | 3993b1a96704f9241b1bfceb03f9575c3c503b49 (diff) | |
download | LibGui-b5c5182e32f77db84dee227aadb74aece31ef2f6.tar.gz LibGui-b5c5182e32f77db84dee227aadb74aece31ef2f6.tar.bz2 LibGui-b5c5182e32f77db84dee227aadb74aece31ef2f6.zip |
WScrollPanel: Add insets support
Diffstat (limited to 'src/testMod')
-rw-r--r-- | src/testMod/java/io/github/cottonmc/test/client/ScrollingTestGui.java | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/testMod/java/io/github/cottonmc/test/client/ScrollingTestGui.java b/src/testMod/java/io/github/cottonmc/test/client/ScrollingTestGui.java index bfc25c4..af0d1e3 100644 --- a/src/testMod/java/io/github/cottonmc/test/client/ScrollingTestGui.java +++ b/src/testMod/java/io/github/cottonmc/test/client/ScrollingTestGui.java @@ -11,6 +11,7 @@ import io.github.cottonmc.cotton.gui.widget.WLabel; import io.github.cottonmc.cotton.gui.widget.WLabeledSlider; import io.github.cottonmc.cotton.gui.widget.WScrollPanel; import io.github.cottonmc.cotton.gui.widget.data.Axis; +import io.github.cottonmc.cotton.gui.widget.data.Insets; import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment; import io.github.cottonmc.cotton.gui.widget.icon.ItemIcon; @@ -18,6 +19,7 @@ public class ScrollingTestGui extends LightweightGuiDescription { public ScrollingTestGui() { WGridPanel root = (WGridPanel) rootPanel; WBox box = new WBox(Axis.VERTICAL); + WScrollPanel scrollPanel = new WScrollPanel(box); for (int i = 0; i < 20; i++) { box.add(new WLabeledSlider(0, 10, Text.literal("Slider #" + i))); @@ -25,8 +27,46 @@ public class ScrollingTestGui extends LightweightGuiDescription { box.add(new WButton(new ItemIcon(Items.APPLE))); - root.add(new WLabel(Text.literal("Scrolling test")).setVerticalAlignment(VerticalAlignment.CENTER), 0, 0, 5, 2); - root.add(new WScrollPanel(box), 0, 2, 5, 3); + WLabeledSlider topSlider = new WLabeledSlider(0, 16, Axis.HORIZONTAL, Text.literal("Top insets")); + WLabeledSlider bottomSlider = new WLabeledSlider(0, 16, Axis.HORIZONTAL, Text.literal("Bottom insets")); + WLabeledSlider leftSlider = new WLabeledSlider(0, 16, Axis.HORIZONTAL, Text.literal("Left insets")); + WLabeledSlider rightSlider = new WLabeledSlider(0, 16, Axis.HORIZONTAL, Text.literal("Right insets")); + + topSlider.setValueChangeListener(top -> { + Insets insets = scrollPanel.getInsets(); + Insets newInsets = new Insets(top, insets.left(), insets.bottom(), insets.right()); + scrollPanel.setInsets(newInsets); + scrollPanel.layout(); + }); + + bottomSlider.setValueChangeListener(bottom -> { + Insets insets = scrollPanel.getInsets(); + Insets newInsets = new Insets(insets.top(), insets.left(), bottom, insets.right()); + scrollPanel.setInsets(newInsets); + scrollPanel.layout(); + }); + + leftSlider.setValueChangeListener(left -> { + Insets insets = scrollPanel.getInsets(); + Insets newInsets = new Insets(insets.top(), left, insets.bottom(), insets.right()); + scrollPanel.setInsets(newInsets); + scrollPanel.layout(); + }); + + rightSlider.setValueChangeListener(right -> { + Insets insets = scrollPanel.getInsets(); + Insets newInsets = new Insets(insets.top(), insets.left(), insets.bottom(), right); + scrollPanel.setInsets(newInsets); + scrollPanel.layout(); + }); + + root.setGaps(2, 2); + root.add(new WLabel(Text.literal("Scrolling test")).setVerticalAlignment(VerticalAlignment.CENTER), 0, 0, 6, 2); + root.add(topSlider, 0, 2, 3, 1); + root.add(bottomSlider, 3, 2, 3, 1); + root.add(leftSlider, 0, 3, 3, 1); + root.add(rightSlider, 3, 3, 3, 1); + root.add(scrollPanel, 0, 4, 6, 3); root.validate(this); } } |