diff options
Diffstat (limited to 'src/main/java/io')
6 files changed, 17 insertions, 55 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java index 71fc6a5..05770ae 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java @@ -142,6 +142,7 @@ public interface GuiDescription { /** * Gets the position of the screen title. * + * @return the title position * @since 4.0.0 */ Vec2i getTitlePos(); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBox.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBox.java index e65d27a..a4212c9 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBox.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBox.java @@ -77,7 +77,7 @@ public class WBox extends WPanel { @Override public void layout() { - int dimension = axis.choose(insets.left, insets.top); + int dimension = axis.choose(insets.left(), insets.top()); // Set position offset from alignment along the box axis if (axis == Axis.HORIZONTAL && horizontalAlignment != HorizontalAlignment.LEFT) { @@ -113,13 +113,13 @@ public class WBox extends WPanel { switch (verticalAlignment) { case TOP: default: - y = insets.top; + y = insets.top(); break; case CENTER: - y = insets.top + (getHeight() - insets.top - insets.bottom - child.getHeight()) / 2; + y = insets.top() + (getHeight() - insets.top() - insets.bottom() - child.getHeight()) / 2; break; case BOTTOM: - y = getHeight() - insets.bottom - child.getHeight(); + y = getHeight() - insets.bottom() - child.getHeight(); break; } @@ -130,13 +130,13 @@ public class WBox extends WPanel { switch (horizontalAlignment) { case LEFT: default: - x = insets.left; + x = insets.left(); break; case CENTER: - x = insets.left + (getWidth() - insets.left - insets.right - child.getWidth()) / 2; + x = insets.left() + (getWidth() - insets.left() - insets.right() - child.getWidth()) / 2; break; case RIGHT: - x = getWidth() - insets.right - child.getWidth(); + x = getWidth() - insets.right() - child.getWidth(); break; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WGridPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WGridPanel.java index 0fd8bd4..c2bea8b 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WGridPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WGridPanel.java @@ -41,7 +41,7 @@ public class WGridPanel extends WPanel { public void add(WWidget w, int x, int y) { children.add(w); w.parent = this; - w.setLocation(x * grid + insets.left, y * grid + insets.top); + w.setLocation(x * grid + insets.left(), y * grid + insets.top()); if (w.canResize()) { w.setSize(grid, grid); } @@ -61,7 +61,7 @@ public class WGridPanel extends WPanel { public void add(WWidget w, int x, int y, int width, int height) { children.add(w); w.parent = this; - w.setLocation(x * grid + insets.left, y * grid + insets.top); + w.setLocation(x * grid + insets.left(), y * grid + insets.top()); if (w.canResize()) { w.setSize(width * grid, height * grid); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java index 64b2369..f5ff75a 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java @@ -99,8 +99,8 @@ public abstract class WPanel extends WWidget { * @since 4.0.0 */ protected void expandToFit(WWidget w, Insets insets) { - int pushRight = w.getX()+w.getWidth()+insets.right; - int pushDown = w.getY()+w.getHeight()+insets.bottom; + int pushRight = w.getX() + w.getWidth() + insets.right(); + int pushDown = w.getY() + w.getHeight() + insets.bottom(); this.setSize(Math.max(this.getWidth(), pushRight), Math.max(this.getHeight(), pushDown)); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlainPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlainPanel.java index 0afd16f..3c7bee7 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlainPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlainPanel.java @@ -23,7 +23,7 @@ public class WPlainPanel extends WPanel { public void add(WWidget w, int x, int y) { children.add(w); w.parent = this; - w.setLocation(insets.left + x, insets.top + y); + w.setLocation(insets.left() + x, insets.top() + y); if (w.canResize()) { w.setSize(18, 18); } @@ -44,7 +44,7 @@ public class WPlainPanel extends WPanel { public void add(WWidget w, int x, int y, int width, int height) { children.add(w); w.parent = this; - w.setLocation(insets.left + x, insets.top + y); + w.setLocation(insets.left() + x, insets.top() + y); if (w.canResize()) { w.setSize(width, height); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Insets.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Insets.java index 85c32ed..4ceb13f 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Insets.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Insets.java @@ -1,14 +1,12 @@ package io.github.cottonmc.cotton.gui.widget.data; -import java.util.Objects; - /** * The layout insets of a panel. The insets describe how many pixels should be around the panel's contents. - * For example, root panels have 7 pixels around their contents, and that is set via {@link #ROOT_PANEL}. + * For example, root panels have 7 pixels around their contents, which is set via {@link #ROOT_PANEL}. * * @since 4.0.0 */ -public final class Insets { +public record Insets(int top, int left, int bottom, int right) { /** * Empty layout insets that do not provide any borders around content. */ @@ -19,15 +17,6 @@ public final class Insets { */ public static final Insets ROOT_PANEL = new Insets(7); - /** The top (-Y) inset size. */ - public final int top; - /** The left (-X) inset size. */ - public final int left; - /** The bottom (+Y) inset size. */ - public final int bottom; - /** The right (+X) inset size. */ - public final int right; - /** * Constructs layout insets. * @@ -36,16 +25,11 @@ public final class Insets { * @param bottom the bottom (+Y) inset size * @param right the right (+X) inset size */ - public Insets(int top, int left, int bottom, int right) { + public Insets { if (top < 0) throw new IllegalArgumentException("top cannot be negative, found " + top); if (left < 0) throw new IllegalArgumentException("left cannot be negative, found " + left); if (bottom < 0) throw new IllegalArgumentException("bottom cannot be negative, found " + bottom); if (right < 0) throw new IllegalArgumentException("right cannot be negative, found " + right); - - this.top = top; - this.left = left; - this.bottom = bottom; - this.right = right; } /** @@ -66,27 +50,4 @@ public final class Insets { public Insets(int size) { this(size, size, size, size); } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Insets insets = (Insets) o; - return top == insets.top && left == insets.left && bottom == insets.bottom && right == insets.right; - } - - @Override - public int hashCode() { - return Objects.hash(top, left, bottom, right); - } - - @Override - public String toString() { - return "Insets{" + - "top=" + top + - ", left=" + left + - ", bottom=" + bottom + - ", right=" + right + - '}'; - } } |