@@ -53,7 +53,7 @@ public class ExpandingList extends ContainerObjectSelectionList<ExpandingList.En
5353 * @param y the y position of the list widget.
5454 * @param width the full width of the list widget.
5555 * @param maxHeight the maximum allowable height of the list widget.
56- * @param itemHeight the space to allocate for each list entry.
56+ * @param defaultEntryHeight the space to allocate for each list entry.
5757 * @param entryHeight the actual height of each list entry.
5858 * @param xMargin the space between the side of each entry and the edge of the list widget.
5959 */
@@ -62,23 +62,27 @@ public ExpandingList(
6262 int y ,
6363 int width ,
6464 int maxHeight ,
65- int itemHeight ,
65+ int defaultEntryHeight ,
6666 int entryHeight ,
6767 int xMargin
6868 ) {
69- super (Minecraft .getInstance (), width , 0 , y , itemHeight );
69+ super (Minecraft .getInstance (), width , 0 , y , defaultEntryHeight );
7070 super .setX (x );
7171 this .maxHeight = maxHeight ;
7272 this .entryWidth = width - SCROLLBAR_WIDTH - (xMargin * 2 );
7373 this .entryHeight = entryHeight ;
7474 this .entryX = x + xMargin ;
7575 }
7676
77+ protected Entry getEntry (int index ) {
78+ return this .children ().get (index );
79+ }
80+
7781 /**
7882 * Scrolls the list as required to make the {@link Entry} at {@code index} visible.
7983 */
8084 public void ensureVisible (int index ) {
81- ensureVisible (getEntry (index ));
85+ scrollToEntry (getEntry (index ));
8286 }
8387
8488 public boolean isEmpty () {
@@ -104,7 +108,7 @@ public AbstractWidget get(int index) {
104108 public void replaceWidgets (Iterable <AbstractWidget > widgets ) {
105109 clearWidgets ();
106110 widgets .forEach (this ::addWidget );
107- setHeight (Math .min (itemHeight * children ().size () + VERTICAL_BUFFER , maxHeight ));
111+ setHeight (Math .min (defaultEntryHeight * children ().size () + VERTICAL_BUFFER , maxHeight ));
108112 }
109113
110114 /**
@@ -120,7 +124,7 @@ public void clearWidgets() {
120124 */
121125 public void addWidget (AbstractWidget widget ) {
122126 addEntry (new Entry (entryX , entryWidth , entryHeight , widget ));
123- setHeight (Math .min (itemHeight * children ().size () + VERTICAL_BUFFER , maxHeight ));
127+ setHeight (Math .min (defaultEntryHeight * children ().size () + VERTICAL_BUFFER , maxHeight ));
124128 }
125129
126130 @ Override
@@ -129,14 +133,9 @@ protected void renderItem(
129133 int mouseX ,
130134 int mouseY ,
131135 float delta ,
132- int index ,
133- int x ,
134- int y ,
135- int width ,
136- int height
136+ ExpandingList .Entry widget
137137 ) {
138- if (index == highlightIndex ) {
139- AbstractWidget widget = getEntry (index ).widget ;
138+ if (highlightIndex != -1 && widget == getEntry (highlightIndex )) {
140139 graphics .fill (
141140 widget .getX (),
142141 widget .getY (),
@@ -145,7 +144,7 @@ protected void renderItem(
145144 HIGHLIGHT_COLOR
146145 );
147146 }
148- super .renderItem (graphics , mouseX , mouseY , delta , index , x , y , width , height );
147+ super .renderItem (graphics , mouseX , mouseY , delta , widget );
149148 }
150149
151150 @ Override
@@ -188,19 +187,14 @@ public AbstractWidget getWidget() {
188187 }
189188
190189 @ Override
191- public void render (
190+ public void renderContent (
192191 @ NotNull GuiGraphics graphics ,
193- int index ,
194- int y ,
195- int x ,
196- int entryWidth ,
197- int entryHeight ,
198192 int mouseX ,
199193 int mouseY ,
200194 boolean hovered ,
201195 float delta
202196 ) {
203- widget .setY (y );
197+ widget .setY (getContentY () );
204198 widget .render (graphics , mouseX , mouseY , delta );
205199 }
206200 }
0 commit comments