From b5c5182e32f77db84dee227aadb74aece31ef2f6 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Sat, 18 Nov 2023 21:52:30 +0200 Subject: WScrollPanel: Add insets support --- .../cottonmc/test/client/ScrollingTestGui.java | 44 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'src/testMod') 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); } } -- cgit