aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/dev/isxander/yacl3/gui
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl3/gui')
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java23
1 files changed, 14 insertions, 9 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java b/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
index 199845d..da1965f 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java
@@ -36,26 +36,31 @@ public class ScrollableNavigationBar extends TabNavigationBar {
public void arrangeElements() {
int noScrollWidth = this.width - NAVBAR_MARGIN*2;
+ int allTabsWidth = 0;
// first pass: set the width of each tab button
for (TabButton tabButton : this.tabButtons) {
- tabButton.setWidth(font.width(tabButton.getMessage()) + 10);
+ int buttonWidth = font.width(tabButton.getMessage()) + 20;
+ allTabsWidth += buttonWidth;
+ tabButton.setWidth(buttonWidth);
}
- // 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);
+ if (allTabsWidth < noScrollWidth) {
+ int equalWidth = noScrollWidth / this.tabButtons.size();
+ var smallTabs = this.tabButtons.stream().filter(btn -> btn.getWidth() < equalWidth).toList();
+ var bigTabs = this.tabButtons.stream().filter(btn -> btn.getWidth() >= equalWidth).toList();
+ int leftoverWidth = noScrollWidth - bigTabs.stream().mapToInt(AbstractWidget::getWidth).sum();
+ int equalWidthForSmallTabs = leftoverWidth / smallTabs.size();
+ for (TabButton tabButton : smallTabs) {
+ tabButton.setWidth(equalWidthForSmallTabs);
}
+
+ allTabsWidth = noScrollWidth;
}
this.layout.arrangeElements();
this.layout.setY(0);
this.scrollOffset = 0;
- 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);
}