@@ -35,20 +35,32 @@ public ScrollableNavigationBar(int width, TabManager tabManager, Iterable<? exte
3535 @ Override
3636 public void arrangeElements () {
3737 int noScrollWidth = this .width - NAVBAR_MARGIN *2 ;
38- int minimumSize = tabButtons .stream ()
39- .map (AbstractWidget ::getMessage )
40- .mapToInt (label -> font .width (label ) + 3 )
41- .min ().orElse (0 );
42- int singleTabWidth = Math .max (noScrollWidth / Math .min (this .tabButtons .size (), 3 ), minimumSize );
38+
39+ int allTabsWidth = 0 ;
40+ // first pass: set the width of each tab button
4341 for (TabButton tabButton : this .tabButtons ) {
44- tabButton .setWidth (singleTabWidth );
42+ int buttonWidth = font .width (tabButton .getMessage ()) + 20 ;
43+ allTabsWidth += buttonWidth ;
44+ tabButton .setWidth (buttonWidth );
45+ }
46+
47+ if (allTabsWidth < noScrollWidth ) {
48+ int equalWidth = noScrollWidth / this .tabButtons .size ();
49+ var smallTabs = this .tabButtons .stream ().filter (btn -> btn .getWidth () < equalWidth ).toList ();
50+ var bigTabs = this .tabButtons .stream ().filter (btn -> btn .getWidth () >= equalWidth ).toList ();
51+ int leftoverWidth = noScrollWidth - bigTabs .stream ().mapToInt (AbstractWidget ::getWidth ).sum ();
52+ int equalWidthForSmallTabs = leftoverWidth / smallTabs .size ();
53+ for (TabButton tabButton : smallTabs ) {
54+ tabButton .setWidth (equalWidthForSmallTabs );
55+ }
56+
57+ allTabsWidth = noScrollWidth ;
4558 }
4659
4760 this .layout .arrangeElements ();
4861 this .layout .setY (0 );
4962 this .scrollOffset = 0 ;
5063
51- int allTabsWidth = singleTabWidth * this .tabButtons .size ();
5264 this .layout .setX (Math .max ((this .width - allTabsWidth ) / 2 , NAVBAR_MARGIN ));
5365 this .maxScrollOffset = Math .max (0 , allTabsWidth - noScrollWidth );
5466 }
0 commit comments