99import net .minecraft .client .gui .components .AbstractWidget ;
1010import net .minecraft .client .gui .components .TabButton ;
1111import net .minecraft .client .gui .components .events .GuiEventListener ;
12+ //? if >=26.2
13+ import net .minecraft .client .gui .components .tabs .MenuTabBar ;
1214import net .minecraft .client .gui .components .tabs .Tab ;
1315import net .minecraft .client .gui .components .tabs .TabManager ;
14- import net .minecraft .client .gui .components .tabs .TabNavigationBar ;
16+ //? if <26.2
17+ //import net.minecraft.client.gui.components.tabs.TabNavigationBar;
1518import net .minecraft .client .gui .layouts .Layout ;
1619import net .minecraft .client .gui .layouts .LinearLayout ;
1720import net .minecraft .util .Mth ;
1821import org .jetbrains .annotations .Nullable ;
1922
20- public class ScrollableNavigationBar extends TabNavigationBar {
23+ public class ScrollableNavigationBar
24+ extends /*? if >=26.2 {*/ MenuTabBar /*?} else {*/ /*TabNavigationBar*/ /*?}*/ {
2125 private static final int NAVBAR_MARGIN = 28 ;
2226
2327 private static final Font font = Minecraft .getInstance ().font ;
@@ -28,7 +32,15 @@ public class ScrollableNavigationBar extends TabNavigationBar {
2832 private final TabNavigationBarAccessor accessor ;
2933
3034 public ScrollableNavigationBar (int width , TabManager tabManager , Iterable <? extends Tab > tabs ) {
31- super (width , tabManager , ImmutableList .copyOf (tabs ));
35+ //? if >=26.2 {
36+ var tabsList = ImmutableList .<Tab >copyOf (tabs );
37+ var tabButtonsList = ImmutableList .copyOf (tabsList .stream ()
38+ .<TabButton >map (tab -> new MenuTabButton (tabManager , tab , 0 , 24 ))
39+ .toList ());
40+ super (0 , 0 , width , 24 , tabManager , tabButtonsList , tabsList );
41+ //?} else {
42+ /*super(width, tabManager, ImmutableList.copyOf(tabs));
43+ */ //?}
3244 this .accessor = (TabNavigationBarAccessor ) this ;
3345
3446 // add tab tooltips to the tab buttons
@@ -40,9 +52,12 @@ public ScrollableNavigationBar(int width, TabManager tabManager, Iterable<? exte
4052 }
4153
4254 @ Override
43- public void arrangeElements () {
55+ public void arrangeElements (/*? if >=26.2 {*/ final int pWidth /*?}*/ ) {
56+ int width = /*? if >=26.2 {*/ pWidth ; /*?} else {*/ /*accessor.yacl$getWidth(); */ /*?}*/
57+ Layout layout = /*? if >=26.2 {*/ this .layout ; /*?} else {*/ /*accessor.yacl$getLayout(); */ /*?}*/
58+
4459 ImmutableList <TabButton > tabButtons = accessor .yacl$getTabButtons ();
45- int noScrollWidth = accessor . yacl$getWidth () - NAVBAR_MARGIN *2 ;
60+ int noScrollWidth = width - NAVBAR_MARGIN *2 ;
4661
4762 int allTabsWidth = 0 ;
4863 // first pass: set the width of each tab button
@@ -65,26 +80,34 @@ public void arrangeElements() {
6580 allTabsWidth = noScrollWidth ;
6681 }
6782
68- Layout layout = ((TabNavigationBarAccessor ) this ).yacl$getLayout ();
6983 layout .arrangeElements ();
7084 layout .setY (0 );
7185 scrollOffset = 0 ;
7286
73- layout .setX (Math .max ((accessor . yacl$getWidth () - allTabsWidth ) / 2 , NAVBAR_MARGIN ));
87+ layout .setX (Math .max ((width - allTabsWidth ) / 2 , NAVBAR_MARGIN ));
7488 this .maxScrollOffset = Math .max (0 , allTabsWidth - noScrollWidth );
7589 }
7690
7791 @ Override
78- public void extractRenderState (GuiGraphicsExtractor graphics , int mouseX , int mouseY , float a ) {
92+ //? if >=26.2 {
93+ public void extractWidgetRenderState (GuiGraphicsExtractor graphics , int mouseX , int mouseY , float a ) {
94+ //?} else {
95+ /*public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
96+ */ //?}
7997 graphics .pose ().pushMatrix ();
8098 // render option list BELOW the navbar without need to scissor
8199
82- super .extractRenderState (graphics , mouseX , mouseY , a );
100+ //? if >=26.2 {
101+ super .extractWidgetRenderState (graphics , mouseX , mouseY , a );
102+ //?} else {
103+ /*super.extractRenderState(graphics, mouseX, mouseY, a);
104+ */ //?}
83105
84- LinearLayout layout = accessor .yacl$getLayout ();
106+ Layout layout = /*? if >=26.2 {*/ this .layout ; /*?} else {*/ /*accessor.yacl$getLayout(); */ /*?}*/
107+ int width = /*? if >=26.2 {*/ this .getWidth (); /*?} else {*/ /*accessor.yacl$getWidth(); */ /*?}*/
85108 // draw right fade
86109 if (this .scrollOffset < this .maxScrollOffset - NAVBAR_MARGIN ) {
87- int right = accessor . yacl$getWidth () ;
110+ int right = width ;
88111 ColorGradientRenderState .createHorizontal (
89112 graphics ,
90113 right - 40 ,
@@ -126,7 +149,7 @@ public boolean isMouseOver(double mouseX, double mouseY) {
126149 }
127150
128151 public void setScrollOffset (int scrollOffset ) {
129- Layout layout = (( TabNavigationBarAccessor ) this ). yacl$getLayout ();
152+ Layout layout = /*? if >=26.2 {*/ this . layout ; /*?} else {*/ /*accessor. yacl$getLayout(); */ /*?}*/
130153
131154 layout .setX (layout .getX () + this .scrollOffset );
132155 this .scrollOffset = Mth .clamp (scrollOffset , 0 , maxScrollOffset );
@@ -146,10 +169,12 @@ public void setFocused(@Nullable GuiEventListener child) {
146169 }
147170
148171 protected void ensureVisible (TabButton tabButton ) {
172+ int width = /*? if >=26.2 {*/ this .getWidth (); /*?} else {*/ /*accessor.yacl$getWidth(); */ /*?}*/
173+
149174 if (tabButton .getX () < NAVBAR_MARGIN ) {
150175 this .setScrollOffset (this .scrollOffset - (NAVBAR_MARGIN - tabButton .getX ()));
151- } else if (tabButton .getX () + tabButton .getWidth () > accessor . yacl$getWidth () - NAVBAR_MARGIN ) {
152- this .setScrollOffset (this .scrollOffset + (tabButton .getX () + tabButton .getWidth () - (accessor . yacl$getWidth () - NAVBAR_MARGIN )));
176+ } else if (tabButton .getX () + tabButton .getWidth () > width - NAVBAR_MARGIN ) {
177+ this .setScrollOffset (this .scrollOffset + (tabButton .getX () + tabButton .getWidth () - (width - NAVBAR_MARGIN )));
153178 }
154179 }
155180
0 commit comments