diff options
author | BlazingTwist <39350649+BlazingTwist@users.noreply.github.com> | 2023-02-08 18:25:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-08 19:25:51 +0200 |
commit | 91e4e6401089d6dc5b92589fa1fb1501b7217cf0 (patch) | |
tree | 1911155ca1d4d215cf89fc41553d646392a772a7 | |
parent | 509850c97a828d721db9e5f968d888882dce2bfb (diff) | |
download | LibGui-91e4e6401089d6dc5b92589fa1fb1501b7217cf0.tar.gz LibGui-91e4e6401089d6dc5b92589fa1fb1501b7217cf0.tar.bz2 LibGui-91e4e6401089d6dc5b92589fa1fb1501b7217cf0.zip |
Fix WBox Horizontal Offset (#184)
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WBox.java | 22 |
1 files changed, 12 insertions, 10 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 5452b93..dd7e771 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 @@ -78,16 +78,18 @@ public class WBox extends WPanelWithInsets { int dimension = axis.choose(insets.left(), insets.top()); // Set position offset from alignment along the box axis - if (axis == Axis.HORIZONTAL && horizontalAlignment != HorizontalAlignment.LEFT) { - int widgetWidth = spacing * (children.size() - 1); - for (WWidget child : children) { - widgetWidth += child.getWidth(); - } - - if (horizontalAlignment == HorizontalAlignment.CENTER) { - dimension = (getWidth() - widgetWidth) / 2; - } else { // right - dimension = getWidth() - widgetWidth; + if (axis == Axis.HORIZONTAL) { + if (horizontalAlignment != HorizontalAlignment.LEFT) { + int widgetWidth = spacing * (children.size() - 1); + for (WWidget child : children) { + widgetWidth += child.getWidth(); + } + + if (horizontalAlignment == HorizontalAlignment.CENTER) { + dimension = (getWidth() - widgetWidth) / 2; + } else { // right + dimension = getWidth() - widgetWidth; + } } } else if (verticalAlignment != VerticalAlignment.TOP) { int widgetHeight = spacing * (children.size() - 1); |