aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/src/main/java/dev/isxander/yacl/gui/tab/ScrollableNavigationBar.java21
-rw-r--r--test-common/src/main/java/dev/isxander/yacl/test/GuiTest.java2
2 files changed, 15 insertions, 8 deletions
diff --git a/common/src/main/java/dev/isxander/yacl/gui/tab/ScrollableNavigationBar.java b/common/src/main/java/dev/isxander/yacl/gui/tab/ScrollableNavigationBar.java
index 8132ccc..b452495 100644
--- a/common/src/main/java/dev/isxander/yacl/gui/tab/ScrollableNavigationBar.java
+++ b/common/src/main/java/dev/isxander/yacl/gui/tab/ScrollableNavigationBar.java
@@ -35,20 +35,27 @@ public class ScrollableNavigationBar extends TabNavigationBar {
@Override
public void arrangeElements() {
int noScrollWidth = this.width - NAVBAR_MARGIN*2;
- int minimumSize = tabButtons.stream()
- .map(AbstractWidget::getMessage)
- .mapToInt(label -> font.width(label) + 3)
- .min().orElse(0);
- int singleTabWidth = Math.max(noScrollWidth / Math.min(this.tabButtons.size(), 3), minimumSize);
+
+ // first pass: set the width of each tab button
for (TabButton tabButton : this.tabButtons) {
- tabButton.setWidth(singleTabWidth);
+ tabButton.setWidth(font.width(tabButton.getMessage()) + 10);
+ }
+
+ // second pass: redistribute remaining width evenly
+ for (TabButton tabButton : tabButtons) {
+ int totalWidth = tabButtons.stream().mapToInt(AbstractWidget::getWidth).sum();
+ int remainingWidth = noScrollWidth - totalWidth;
+ if (remainingWidth > 0) {
+ int extra = remainingWidth / tabButtons.size();
+ tabButton.setWidth(tabButton.getWidth() + extra);
+ }
}
this.layout.arrangeElements();
this.layout.setY(0);
this.scrollOffset = 0;
- int allTabsWidth = singleTabWidth * this.tabButtons.size();
+ int allTabsWidth = this.tabButtons.stream().mapToInt(AbstractWidget::getWidth).sum();
this.layout.setX(Math.max((this.width - allTabsWidth) / 2, NAVBAR_MARGIN));
this.maxScrollOffset = Math.max(0, allTabsWidth - noScrollWidth);
}
diff --git a/test-common/src/main/java/dev/isxander/yacl/test/GuiTest.java b/test-common/src/main/java/dev/isxander/yacl/test/GuiTest.java
index 8647d16..9ab34a4 100644
--- a/test-common/src/main/java/dev/isxander/yacl/test/GuiTest.java
+++ b/test-common/src/main/java/dev/isxander/yacl/test/GuiTest.java
@@ -339,7 +339,7 @@ public class GuiTest {
.option(LabelOption.create(Component.literal("This is a test category!")))
.build())
.category(ConfigCategory.createBuilder()
- .name(Component.literal("Category Test"))
+ .name(Component.literal("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
.option(LabelOption.create(Component.literal("This is a test category!")))
.build())
.category(ConfigCategory.createBuilder()