diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-11-18 21:57:32 +0200 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-11-18 21:57:32 +0200 |
commit | e79301a6a927cd8f14060b671f41936f519ea6ac (patch) | |
tree | ab86743c39c0ac9a75c91935496a8bdab976ad99 | |
parent | b5c5182e32f77db84dee227aadb74aece31ef2f6 (diff) | |
download | LibGui-e79301a6a927cd8f14060b671f41936f519ea6ac.tar.gz LibGui-e79301a6a927cd8f14060b671f41936f519ea6ac.tar.bz2 LibGui-e79301a6a927cd8f14060b671f41936f519ea6ac.zip |
Add Insets.width and Insets.height
5 files changed, 30 insertions, 8 deletions
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 dd7e771..3d3ce9d 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 @@ -110,7 +110,7 @@ public class WBox extends WPanelWithInsets { if (axis == Axis.HORIZONTAL) { int y = switch (verticalAlignment) { case TOP -> insets.top(); - case CENTER -> insets.top() + (getHeight() - insets.top() - insets.bottom() - child.getHeight()) / 2; + case CENTER -> insets.top() + (getHeight() - insets.height() - child.getHeight()) / 2; case BOTTOM -> getHeight() - insets.bottom() - child.getHeight(); }; @@ -118,7 +118,7 @@ public class WBox extends WPanelWithInsets { } else { int x = switch (horizontalAlignment) { case LEFT -> insets.left(); - case CENTER -> insets.left() + (getWidth() - insets.left() - insets.right() - child.getWidth()) / 2; + case CENTER -> insets.left() + (getWidth() - insets.width() - child.getWidth()) / 2; case RIGHT -> getWidth() - insets.right() - child.getWidth(); }; 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 675298e..6af0f1e 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 @@ -173,7 +173,7 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel { Insets insets = getInsets(); int gap = getGap(); - int layoutHeight = this.getHeight() - insets.top() - insets.bottom(); + int layoutHeight = this.getHeight() - insets.height(); int cellsHigh = Math.max((layoutHeight + gap) / (cellHeight + gap), 1); // At least one cell is always visible //System.out.println("Adding children..."); @@ -210,7 +210,7 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel { //At this point, w is nonnull and configured by d if (w.canResize()) { - w.setSize(this.width - insets.left() - insets.right() - scrollBar.getWidth(), cellHeight); + w.setSize(this.width - insets.width() - scrollBar.getWidth(), cellHeight); } w.x = insets.left(); w.y = insets.top() + ((cellHeight + gap) * i); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanelWithInsets.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanelWithInsets.java index 48792d4..5650aff 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanelWithInsets.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanelWithInsets.java @@ -40,7 +40,7 @@ public abstract class WPanelWithInsets extends WPanel { Insets old = this.insets; this.insets = Objects.requireNonNull(insets, "insets"); - setSize(getWidth() - old.left() - old.right(), getHeight() - old.top() - old.bottom()); + setSize(getWidth() - old.width(), getHeight() - old.height()); for (WWidget child : children) { child.setLocation(child.getX() - old.left() + insets.left(), child.getY() - old.top() + insets.top()); 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 index 66cefaa..4e3669b 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java @@ -158,7 +158,7 @@ public class WScrollPanel extends WPanel { Insets insets = getInsets(); for (WWidget child : children) { if (child == widget) { - Scissors.push(x + insets.left(), y + insets.top(), width - insets.left() - insets.right(), height - insets.top() - insets.bottom()); + Scissors.push(x + insets.left(), y + insets.top(), width - insets.width(), height - insets.height()); } child.paint(context, x + child.getX(), y + child.getY(), mouseX - child.getX(), mouseY - child.getY()); @@ -189,9 +189,9 @@ public class WScrollPanel extends WPanel { int y = insets.top() + (vertical ? -verticalScrollBar.getValue() : 0); widget.setLocation(x, y); - verticalScrollBar.setWindow(this.height - insets.top() - insets.bottom() - (horizontal ? SCROLL_BAR_SIZE : 0)); + verticalScrollBar.setWindow(this.height - insets.height() - (horizontal ? SCROLL_BAR_SIZE : 0)); verticalScrollBar.setMaxValue(widget.getHeight()); - horizontalScrollBar.setWindow(this.width - insets.left() - insets.right() - (vertical ? SCROLL_BAR_SIZE : 0)); + horizontalScrollBar.setWindow(this.width - insets.width() - (vertical ? SCROLL_BAR_SIZE : 0)); horizontalScrollBar.setMaxValue(widget.getWidth()); if (vertical) children.add(verticalScrollBar); 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 782cf74..b9e789e 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 @@ -54,4 +54,26 @@ public record Insets(int top, int left, int bottom, int right) { public Insets(int size) { this(size, size, size, size); } + + /** + * {@return the total width of these insets} + * + * <p>Equivalent to <code>{@link #left()} + {@link #right()}</code>. + * + * @since 9.1.0 + */ + public int width() { + return left + right; + } + + /** + * {@return the total height of these insets} + * + * <p>Equivalent to <code>{@link #top()} + {@link #bottom()}</code>. + * + * @since 9.1.0 + */ + public int height() { + return top + bottom; + } } |