Skip to content

Commit

Permalink
Reworked fillContents method to keep track of previous and next pages
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
fulminazzo committed Apr 18, 2024
1 parent c3e58d2 commit e380d22
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions gui/base/src/main/java/it/angrybear/yagl/guis/DataGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,19 @@ public void open(@NotNull Viewer viewer, int page) {
}

private @NotNull GUI fillContents(final @NotNull GUI gui, final int page) {
int emptySlots = gui.emptySlots().size();
int emptySlots = emptySlots().size();
if (this.previousPage.isPresent()) emptySlots--;
if (this.nextPage.isPresent()) emptySlots--;
int min = emptySlots * page;
int max = emptySlots * (page + 1);
int size = this.data.size();
for (int i = Math.min(min, size); i < Math.min(max, size); i++)
gui.addContent(this.dataConverter.apply(this.data.get(i)));
if (min >= this.data.size())
throw new IllegalArgumentException(String.format("No such page '%s'", page));
if (page > 0) min++;
int size = Math.min(gui.emptySlots().size() + min, this.data.size());
for (int i = min; i < size; i++) {
T data = this.data.get(i);
GUIContent content = this.dataConverter.apply(data);
gui.addContent(content);
}
return gui;
}

Expand Down

0 comments on commit e380d22

Please sign in to comment.