Skip to content

Commit f696bab

Browse files
committed
setter for initial page in PagedWidget
1 parent 06a9ba8 commit f696bab

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/com/cleanroommc/modularui/widgets/PagedWidget.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class PagedWidget<W extends PagedWidget<W>> extends Widget<W> {
2121

2222
@Override
2323
public void afterInit() {
24-
setPage(0);
24+
setPage(this.currentPageIndex);
2525
}
2626

2727
/**
@@ -35,7 +35,7 @@ public W onPageChange(@Nullable IntConsumer onPageChange) {
3535

3636
public void setPage(int page) {
3737
if (page < 0 || page >= this.pages.size()) {
38-
throw new IndexOutOfBoundsException();
38+
throw new IndexOutOfBoundsException("Setting page of " + this + " to " + page + " failed. Only values from 0 to " + (this.pages.size() - 1) + " are allowed.");
3939
}
4040
this.currentPageIndex = page;
4141
if (this.currentPage != null) {
@@ -80,6 +80,13 @@ public int getCurrentPageIndex() {
8080
return this.pages;
8181
}
8282

83+
public W initialPage(int page) {
84+
if (!isValid()) {
85+
this.currentPageIndex = page;
86+
}
87+
return getThis();
88+
}
89+
8390
public W addPage(IWidget widget) {
8491
this.pages.add(widget);
8592
widget.setEnabled(false);

0 commit comments

Comments
 (0)