aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/dev
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-06-05 16:43:44 +0100
committerisXander <xandersmith2008@gmail.com>2023-06-05 16:43:44 +0100
commita05ce5306ac326c5e492ecf962a4b83cd7149f9a (patch)
treeee69bcac9bd400f00a861258af9246db11c72b3a /common/src/main/java/dev
parente5bb02b4415975464d91a3d13f83a58cb8b7ad80 (diff)
downloadYetAnotherConfigLib-a05ce5306ac326c5e492ecf962a4b83cd7149f9a.tar.gz
YetAnotherConfigLib-a05ce5306ac326c5e492ecf962a4b83cd7149f9a.tar.bz2
YetAnotherConfigLib-a05ce5306ac326c5e492ecf962a4b83cd7149f9a.zip
Fix improve tab layout
Diffstat (limited to 'common/src/main/java/dev')
-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);
}