File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
src/main/java/com/cleanroommc/modularui/widgets Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 44import com .cleanroommc .modularui .widget .Widget ;
55
66import org .jetbrains .annotations .NotNull ;
7+ import org .jetbrains .annotations .Nullable ;
78import org .jetbrains .annotations .Unmodifiable ;
89
910import java .util .ArrayList ;
1011import java .util .List ;
12+ import java .util .function .IntConsumer ;
1113
1214public class PagedWidget <W extends PagedWidget <W >> extends Widget <W > {
1315
1416 private final List <IWidget > pages = new ArrayList <>();
1517 private IWidget currentPage ;
1618 private int currentPageIndex = 0 ;
19+ @ Nullable
20+ private IntConsumer onPageChange ;
1721
1822 @ Override
1923 public void afterInit () {
2024 setPage (0 );
2125 }
2226
27+ /**
28+ * Set a consumer that is accepted <b>right after</b> the page is actually changed and the next page widget is enabled. <br/>
29+ * Will also be called with {@code 0} when after this widget is initialized.
30+ */
31+ public W onPageChange (@ Nullable IntConsumer onPageChange ) {
32+ this .onPageChange = onPageChange ;
33+ return getThis ();
34+ }
35+
2336 public void setPage (int page ) {
2437 if (page < 0 || page >= this .pages .size ()) {
2538 throw new IndexOutOfBoundsException ();
@@ -30,6 +43,10 @@ public void setPage(int page) {
3043 }
3144 this .currentPage = this .pages .get (this .currentPageIndex );
3245 this .currentPage .setEnabled (true );
46+
47+ if (this .onPageChange != null ) {
48+ this .onPageChange .accept (page );
49+ }
3350 }
3451
3552 public void nextPage () {
You can’t perform that action at this time.
0 commit comments