From 91e4e6401089d6dc5b92589fa1fb1501b7217cf0 Mon Sep 17 00:00:00 2001 From: BlazingTwist <39350649+BlazingTwist@users.noreply.github.com> Date: Wed, 8 Feb 2023 18:25:51 +0100 Subject: Fix WBox Horizontal Offset (#184) --- .../io/github/cottonmc/cotton/gui/widget/WBox.java | 22 ++++++++++++---------- 1 file 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); -- cgit