From cc01e089d361f56382eb43560aee952674211dd2 Mon Sep 17 00:00:00 2001 From: LopyMine <127966446+LopyMine@users.noreply.github.com> Date: Sat, 9 Sep 2023 18:52:08 +0500 Subject: Paint WScrollBar using textures (#212) --- .../cottonmc/test/client/LibGuiTestClient.java | 1 + .../cottonmc/test/client/ScrollBarTestGui.java | 44 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/testMod/java/io/github/cottonmc/test/client/ScrollBarTestGui.java (limited to 'src/testMod/java') diff --git a/src/testMod/java/io/github/cottonmc/test/client/LibGuiTestClient.java b/src/testMod/java/io/github/cottonmc/test/client/LibGuiTestClient.java index e15eb83..57c2790 100644 --- a/src/testMod/java/io/github/cottonmc/test/client/LibGuiTestClient.java +++ b/src/testMod/java/io/github/cottonmc/test/client/LibGuiTestClient.java @@ -53,6 +53,7 @@ public class LibGuiTestClient implements ClientModInitializer { .then(literal("config").executes(openScreen(client -> new ConfigGui(client.currentScreen)))) .then(literal("tab").executes(openScreen(client -> new TabTestGui()))) .then(literal("scrolling").executes(openScreen(client -> new ScrollingTestGui()))) + .then(literal("scrollbar").executes(openScreen(client -> new ScrollBarTestGui()))) .then(literal("insets").executes(openScreen(client -> new InsetsTestGui()))) .then(literal("textfield").executes(openScreen(client -> new TextFieldTestGui()))) .then(literal("paddings") diff --git a/src/testMod/java/io/github/cottonmc/test/client/ScrollBarTestGui.java b/src/testMod/java/io/github/cottonmc/test/client/ScrollBarTestGui.java new file mode 100644 index 0000000..efac9d5 --- /dev/null +++ b/src/testMod/java/io/github/cottonmc/test/client/ScrollBarTestGui.java @@ -0,0 +1,44 @@ +package io.github.cottonmc.test.client; + +import net.fabricmc.fabric.api.util.TriState; + +import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; +import io.github.cottonmc.cotton.gui.widget.WPlainPanel; +import io.github.cottonmc.cotton.gui.widget.WScrollBar; +import io.github.cottonmc.cotton.gui.widget.WToggleButton; +import io.github.cottonmc.cotton.gui.widget.data.Axis; +import io.github.cottonmc.cotton.gui.widget.data.Insets; + +public class ScrollBarTestGui extends LightweightGuiDescription { + private boolean darkMode = false; + + public ScrollBarTestGui() { + WPlainPanel root = new WPlainPanel(); + setRootPanel(root); + root.setSize(256, 240); + root.setInsets(Insets.ROOT_PANEL); + + WScrollBar scrollBar1 = new WScrollBar(Axis.HORIZONTAL); + root.add(scrollBar1, 0, 0, 256, 16); + + WScrollBar scrollBar2 = new WScrollBar(Axis.HORIZONTAL); + root.add(scrollBar2, 0, 240 - scrollBar2.getHeight(), 256, 8); + + WScrollBar scrollBar3 = new WScrollBar(Axis.VERTICAL); + root.add(scrollBar3, 0, 18, 16, 202); + + WScrollBar scrollBar4 = new WScrollBar(Axis.VERTICAL); + root.add(scrollBar4, 248, 18, 8, 202); + + WToggleButton toggleButton = new WToggleButton(); + toggleButton.setOnToggle(on -> darkMode = on); + root.add(toggleButton, 128 - (toggleButton.getWidth() / 2), 120 - (toggleButton.getHeight() / 2)); + + root.validate(this); + } + + @Override + public TriState isDarkMode() { + return TriState.of(darkMode); + } +} -- cgit