diff options
Diffstat (limited to 'src/main')
27 files changed, 260 insertions, 76 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java index 6badb54..0ca52a4 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java @@ -1,8 +1,9 @@ package io.github.cottonmc.cotton.gui.client; +import net.minecraft.util.Identifier; + import io.github.cottonmc.cotton.gui.widget.WItemSlot; import io.github.cottonmc.cotton.gui.widget.WWidget; -import net.minecraft.util.Identifier; /** * Background painters are used to paint the background of a widget. diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java index d4ac04c..b5ac34e 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java @@ -1,14 +1,15 @@ package io.github.cottonmc.cotton.gui.client; -import io.github.cottonmc.cotton.gui.GuiDescription; -import io.github.cottonmc.cotton.gui.widget.WPanel; -import io.github.cottonmc.cotton.gui.widget.WWidget; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; +import io.github.cottonmc.cotton.gui.GuiDescription; +import io.github.cottonmc.cotton.gui.widget.WPanel; +import io.github.cottonmc.cotton.gui.widget.WWidget; + public class CottonClientScreen extends Screen implements TextHoverRendererScreen { protected GuiDescription description; protected int left = 0; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java index ae0f232..9549b99 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java @@ -1,6 +1,5 @@ package io.github.cottonmc.cotton.gui.client; -import io.github.cottonmc.cotton.gui.widget.WWidget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; @@ -8,7 +7,12 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.Window; import net.minecraft.client.util.math.MatrixStack; -import java.util.*; +import io.github.cottonmc.cotton.gui.widget.WWidget; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; /** * Manages widgets that are painted on the in-game HUD. diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java index 1508110..ea24abf 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java @@ -1,17 +1,17 @@ package io.github.cottonmc.cotton.gui.client; -import io.github.cottonmc.cotton.gui.CottonInventoryController; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.render.DiffuseLighting; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; import org.lwjgl.glfw.GLFW; +import io.github.cottonmc.cotton.gui.CottonInventoryController; import io.github.cottonmc.cotton.gui.widget.WPanel; import io.github.cottonmc.cotton.gui.widget.WWidget; -import net.minecraft.client.MinecraftClient; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; public class CottonInventoryScreen<T extends CottonInventoryController> extends HandledScreen<T> implements TextHoverRendererScreen { protected CottonInventoryController description; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java index 013382f..386f5ad 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java @@ -7,7 +7,6 @@ import io.github.cottonmc.jankson.JanksonFactory; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.fabricmc.loader.api.FabricLoader; - import net.minecraft.resource.ResourceType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java index 7c9c73c..3eb6578 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java @@ -1,6 +1,6 @@ package io.github.cottonmc.cotton.gui.client; -import javax.annotation.Nullable; +import net.minecraft.screen.PropertyDelegate; import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.ValidatedSlot; @@ -8,7 +8,8 @@ import io.github.cottonmc.cotton.gui.widget.WGridPanel; import io.github.cottonmc.cotton.gui.widget.WLabel; import io.github.cottonmc.cotton.gui.widget.WPanel; import io.github.cottonmc.cotton.gui.widget.WWidget; -import net.minecraft.screen.PropertyDelegate; + +import javax.annotation.Nullable; /** * A GuiDescription without any associated Minecraft classes diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java b/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java index 34a50b1..9828715 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java @@ -1,6 +1,5 @@ package io.github.cottonmc.cotton.gui.client; -import io.github.cottonmc.cotton.gui.widget.WWidget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; @@ -11,9 +10,15 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import net.minecraft.util.profiler.Profiler; +import io.github.cottonmc.cotton.gui.widget.WWidget; + import javax.annotation.Nullable; import java.io.InputStream; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; /** * The nine-patch background painter paints rectangles using a nine-patch texture. diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java index 770b1d6..4868f92 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java @@ -1,18 +1,17 @@ package io.github.cottonmc.cotton.gui.client; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; -import org.lwjgl.opengl.GL11; - import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; - -import io.github.cottonmc.cotton.gui.widget.data.Alignment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import org.lwjgl.opengl.GL11; + +import io.github.cottonmc.cotton.gui.widget.data.Alignment; /** * {@code ScreenDrawing} contains utility methods for drawing contents on a screen. diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java index b8abd22..ccc9679 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java @@ -1,5 +1,9 @@ package io.github.cottonmc.cotton.gui.client.modmenu; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.TranslatableText; + import io.github.cottonmc.cotton.gui.client.BackgroundPainter; import io.github.cottonmc.cotton.gui.client.LibGuiClient; import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; @@ -7,9 +11,6 @@ import io.github.cottonmc.cotton.gui.widget.WButton; import io.github.cottonmc.cotton.gui.widget.WGridPanel; import io.github.cottonmc.cotton.gui.widget.WTextField; import io.github.cottonmc.cotton.gui.widget.WToggleButton; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.TranslatableText; public class ConfigGui extends LightweightGuiDescription { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java index 2ab2a47..5cec105 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java @@ -1,12 +1,13 @@ package io.github.cottonmc.cotton.gui.client.modmenu; -import io.github.cottonmc.cotton.gui.client.CottonClientScreen; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; import io.github.prospector.modmenu.api.ConfigScreenFactory; import io.github.prospector.modmenu.api.ModMenuApi; import net.minecraft.text.TranslatableText; +import io.github.cottonmc.cotton.gui.client.CottonClientScreen; +import io.github.cottonmc.cotton.gui.client.LibGuiClient; + public class ModMenuSupport implements ModMenuApi { @Override diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java index bc55760..74d5357 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java @@ -1,15 +1,16 @@ package io.github.cottonmc.cotton.gui.client.modmenu; -import java.util.ArrayList; - -import io.github.cottonmc.cotton.gui.client.LibGuiClient; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; -import io.github.cottonmc.cotton.gui.widget.WWidget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; +import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import io.github.cottonmc.cotton.gui.widget.WWidget; + +import java.util.ArrayList; + public class WKirbSprite extends WWidget { private static final Identifier KIRB = new Identifier("libgui:textures/widget/kirb.png"); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java index 1884243..999effc 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java @@ -1,9 +1,5 @@ package io.github.cottonmc.cotton.gui.widget; -import java.util.List; - -import io.github.cottonmc.cotton.gui.GuiDescription; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; @@ -13,7 +9,11 @@ import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; import net.minecraft.util.Identifier; +import io.github.cottonmc.cotton.gui.GuiDescription; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; + import javax.annotation.Nullable; +import java.util.List; /** * A bar that displays int values from a {@link PropertyDelegate}. diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java index fc6eb72..1f9525d 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java @@ -1,7 +1,5 @@ package io.github.cottonmc.cotton.gui.widget; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; -import io.github.cottonmc.cotton.gui.widget.data.Alignment; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; @@ -11,6 +9,9 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import io.github.cottonmc.cotton.gui.widget.data.Alignment; + public class WButton extends WWidget { private Text label; protected int color = WLabel.DEFAULT_TEXT_COLOR; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java index ad93259..d4cd9f5 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java @@ -1,10 +1,9 @@ package io.github.cottonmc.cotton.gui.widget; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.math.MatrixStack; import org.lwjgl.opengl.GL11; -import net.minecraft.client.MinecraftClient; - /** * A panel that is clipped to only render widgets inside its bounds. */ diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java index 69332d6..9e87174 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java @@ -1,9 +1,10 @@ package io.github.cottonmc.cotton.gui.widget; +import net.minecraft.client.util.math.MatrixStack; + import io.github.cottonmc.cotton.gui.client.LibGuiClient; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Alignment; -import net.minecraft.client.util.math.MatrixStack; import java.util.function.Supplier; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java index 2572e83..ffba2c3 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java @@ -13,7 +13,9 @@ import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.tag.Tag; -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Objects; /** * A widget that displays an item or a list of items. diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java index 67bd55a..663c58a 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java @@ -1,9 +1,5 @@ package io.github.cottonmc.cotton.gui.widget; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; -import io.github.cottonmc.cotton.gui.client.TextHoverRendererScreen; -import io.github.cottonmc.cotton.gui.widget.data.Alignment; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; @@ -12,6 +8,11 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; +import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import io.github.cottonmc.cotton.gui.client.TextHoverRendererScreen; +import io.github.cottonmc.cotton.gui.widget.data.Alignment; + import javax.annotation.Nullable; /** diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java index 77e51ce..d853bd7 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java @@ -1,8 +1,5 @@ package io.github.cottonmc.cotton.gui.widget; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; -import io.github.cottonmc.cotton.gui.widget.data.Alignment; -import io.github.cottonmc.cotton.gui.widget.data.Axis; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.widget.AbstractButtonWidget; @@ -11,6 +8,10 @@ import net.minecraft.client.util.math.Vector3f; import net.minecraft.text.Text; import net.minecraft.util.math.Quaternion; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import io.github.cottonmc.cotton.gui.widget.data.Alignment; +import io.github.cottonmc.cotton.gui.widget.data.Axis; + import javax.annotation.Nullable; /** diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java index 876d43a..9ba8562 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java @@ -1,14 +1,15 @@ package io.github.cottonmc.cotton.gui.widget; +import net.minecraft.client.util.math.MatrixStack; + +import io.github.cottonmc.cotton.gui.widget.data.Axis; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.function.BiConsumer; import java.util.function.Supplier; -import io.github.cottonmc.cotton.gui.widget.data.Axis; -import net.minecraft.client.util.math.MatrixStack; - /** * Similar to the RecyclerView in Android, this widget represents a scrollable list of items. * diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java index c538cda..2acfb80 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java @@ -1,9 +1,10 @@ package io.github.cottonmc.cotton.gui.widget; +import net.minecraft.client.util.math.MatrixStack; + import io.github.cottonmc.cotton.gui.client.LibGuiClient; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Axis; -import net.minecraft.client.util.math.MatrixStack; public class WScrollBar extends WAbstractSlider { protected int window = 16; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java new file mode 100644 index 0000000..9ff61a6 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java @@ -0,0 +1,105 @@ +package io.github.cottonmc.cotton.gui.widget; + +import net.minecraft.client.util.math.MatrixStack; + +import io.github.cottonmc.cotton.gui.widget.data.Axis; + +/** + * Similar to the JScrollPane in Swing, this widget represents a scrollable widget. + * + * @since 2.0.0 + */ +public class WScrollPanel extends WClippedPanel { + private final WWidget widget; + + private boolean scrollingHorizontally = false; + private boolean scrollingVertically = true; + + /** + * The horizontal scroll bar of this panel. + */ + protected WScrollBar horizontalScrollBar = new WScrollBar(Axis.HORIZONTAL); + + /** + * The vertical scroll bar of this panel. + */ + protected WScrollBar verticalScrollBar = new WScrollBar(Axis.VERTICAL); + + private int lastHorizontalScroll = -1; + private int lastVerticalScroll = -1; + + /** + * Creates a vertically scrolling panel. + * + * @param widget the viewed widget + */ + public WScrollPanel(WWidget widget) { + this.widget = widget; + + widget.setParent(this); + horizontalScrollBar.setParent(this); + verticalScrollBar.setParent(this); + + children.add(widget); + children.add(verticalScrollBar); // Only vertical scroll bar + } + + public boolean isScrollingHorizontally() { + return scrollingHorizontally; + } + + public WScrollPanel setScrollingHorizontally(boolean scrollingHorizontally) { + if (scrollingHorizontally != this.scrollingHorizontally) { + this.scrollingHorizontally = scrollingHorizontally; + layout(); + } + + return this; + } + + public boolean isScrollingVertically() { + return scrollingVertically; + } + + public WScrollPanel setScrollingVertically(boolean scrollingVertically) { + if (scrollingVertically != this.scrollingVertically) { + this.scrollingVertically = scrollingVertically; + layout(); + } + + return this; + } + + @Override + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { + if (verticalScrollBar.getValue() != lastVerticalScroll || horizontalScrollBar.getValue() != lastHorizontalScroll) { + layout(); + lastHorizontalScroll = horizontalScrollBar.getValue(); + lastVerticalScroll = verticalScrollBar.getValue(); + } + + super.paint(matrices, x, y, mouseX, mouseY); + } + + @Override + public void layout() { + children.clear(); + verticalScrollBar.setLocation(this.width - verticalScrollBar.getWidth(), 0); + verticalScrollBar.setSize(8, this.height); + horizontalScrollBar.setLocation(0, this.height - horizontalScrollBar.getHeight()); + horizontalScrollBar.setSize(scrollingVertically ? (this.width - verticalScrollBar.getWidth()) : this.width, 8); + + children.add(widget); + int x = scrollingHorizontally ? -horizontalScrollBar.getValue() : 0; + int y = scrollingVertically ? -verticalScrollBar.getValue() : 0; + widget.setLocation(x, y); + + verticalScrollBar.setWindow(this.height); + verticalScrollBar.setMaxValue(widget.getHeight() + 1); + horizontalScrollBar.setWindow(this.width); + horizontalScrollBar.setMaxValue(widget.getWidth() + 1); + + if (scrollingVertically) children.add(verticalScrollBar); + if (scrollingHorizontally) children.add(horizontalScrollBar); + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java index f68c5bb..88e532c 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java @@ -1,14 +1,15 @@ package io.github.cottonmc.cotton.gui.widget; -import io.github.cottonmc.cotton.gui.client.BackgroundPainter; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; -import io.github.cottonmc.cotton.gui.widget.data.Axis; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; +import io.github.cottonmc.cotton.gui.client.BackgroundPainter; +import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import io.github.cottonmc.cotton.gui.widget.data.Axis; + import javax.annotation.Nullable; /** diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java index 1c78793..a5555fc 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java @@ -1,11 +1,12 @@ package io.github.cottonmc.cotton.gui.widget; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; + public class WSprite extends WWidget { protected int currentFrame= 0; protected long currentFrameTime = 0; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java index ebd8e03..ea7f721 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java @@ -1,9 +1,5 @@ package io.github.cottonmc.cotton.gui.widget; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; -import io.github.cottonmc.cotton.gui.client.TextHoverRendererScreen; -import io.github.cottonmc.cotton.gui.widget.data.Alignment; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; @@ -12,6 +8,11 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; +import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import io.github.cottonmc.cotton.gui.client.TextHoverRendererScreen; +import io.github.cottonmc.cotton.gui.widget.data.Alignment; + import javax.annotation.Nullable; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java index 74129f5..429fa4f 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java @@ -1,19 +1,7 @@ package io.github.cottonmc.cotton.gui.widget; -import java.util.function.Consumer; -import java.util.function.Predicate; - -import javax.annotation.Nullable; - -import net.minecraft.client.util.math.MatrixStack; -import org.lwjgl.glfw.GLFW; -import org.lwjgl.opengl.GL11; - import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; - -import io.github.cottonmc.cotton.gui.client.BackgroundPainter; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; @@ -22,8 +10,18 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; +import org.lwjgl.glfw.GLFW; +import org.lwjgl.opengl.GL11; + +import io.github.cottonmc.cotton.gui.client.BackgroundPainter; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; + +import javax.annotation.Nullable; +import java.util.function.Consumer; +import java.util.function.Predicate; public class WTextField extends WWidget { public static final int OFFSET_X_TEXT = 4; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java index 87a9265..69fef45 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java @@ -1,7 +1,5 @@ package io.github.cottonmc.cotton.gui.widget; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; @@ -11,6 +9,9 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; + import javax.annotation.Nullable; import java.util.function.Consumer; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WVerticalBox.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WVerticalBox.java new file mode 100644 index 0000000..7987424 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WVerticalBox.java @@ -0,0 +1,57 @@ +package io.github.cottonmc.cotton.gui.widget; + +/** + * Similar to the BoxLayout in Swing, this widget represents a vertical list of widgets. + * + * @since 2.0.0 + */ +public class WVerticalBox extends WPanel { + /** + * The spacing between widgets. + */ + protected int spacing = 4; + + public WVerticalBox() { + } + + public void add(WWidget widget, int width, int height) { + widget.setParent(this); + children.add(widget); + if (canResize()) { + widget.setSize(width, height); + } + } + + public void add(WWidget widget) { + add(widget, 18, 18); + } + + @Override + public void layout() { + int height = 0; + + for (int i = 0; i < children.size(); i++) { + WWidget child = children.get(i); + child.setLocation(0, height); + + if (child instanceof WPanel) ((WPanel) child).layout(); + expandToFit(child); + + if (i != children.size() - 1) { + height += spacing; + } + + height += child.getHeight(); + } + } + + public int getSpacing() { + return spacing; + } + + public WVerticalBox setSpacing(int spacing) { + this.spacing = spacing; + + return this; + } +} |