Skip to content

Commit

Permalink
Implemented dynamic rendering of pagination arrows based on current p…
Browse files Browse the repository at this point in the history
…age number.
  • Loading branch information
lanceewing committed Apr 3, 2024
1 parent a0c2cd2 commit f7d1a76
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
9 changes: 9 additions & 0 deletions core/src/main/java/com/agifans/agile/HomeScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,15 @@ private void showGamePage(int gameIndex, boolean skipScroll) {
}
}

public PagedScrollPane getPagedScrollPane() {
Stage currentStage = viewportManager.isPortrait()? portraitStage : landscapeStage;
if (currentStage.getActors().notEmpty()) {
return (PagedScrollPane)((Table)currentStage.getActors().get(0)).getChild(0);
} else {
return null;
}
}

/**
* An AnimatedPieMenu (i.e. radial menu) for interacting with games on the home screen.
*/
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/com/agifans/agile/ui/PagedScrollPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ public void reset() {
public int getNumOfPages() {
return content.getChildren().size;
}

public int getCurrentPageNumber() {
int pageNumber = 0;
if (content.getChildren().notEmpty()) {
int pageWidth = (int)content.getChild(0).getWidth();
pageNumber = Math.round(getScrollX() / pageWidth);
}
return pageNumber;
}

private void scrollToPage() {
final float width = getWidth();
Expand Down
16 changes: 14 additions & 2 deletions core/src/main/java/com/agifans/agile/ui/PaginationWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,20 @@ public void draw(Batch batch, float parentAlpha) {

pixmap.setColor(1.0f, 1.0f, 1.0f, 0.10f);
pixmap.fill();
pixmap.drawPixmap(prevIconPixmap, 0, 5);
pixmap.drawPixmap(nextIconPixmap, width - ICON_SIZE, 5);

PagedScrollPane pagedScrollPane = homeScreen.getPagedScrollPane();
if (pagedScrollPane != null) {
int numOfPages = pagedScrollPane.getNumOfPages();
if (numOfPages > 0) {
int currentPage = pagedScrollPane.getCurrentPageNumber();
if (currentPage > 0) {
pixmap.drawPixmap(prevIconPixmap, 0, 5);
}
if (currentPage < (numOfPages - 1)) {
pixmap.drawPixmap(nextIconPixmap, width - ICON_SIZE, 5);
}
}
}

texture.draw(pixmap, 0, 0);

Expand Down

0 comments on commit f7d1a76

Please sign in to comment.