Skip to content

Commit 358e889

Browse files
committed
Some fixes to the padding calculations for the home screen. Wasn't quite right.
1 parent ff0490f commit 358e889

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

core/src/main/java/emu/joric/HomeScreen.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,17 @@ private void addAppButtonsToStage(Stage stage, PaginationWidget paginationWidget
197197
float viewportWidth = viewportManager.getWidth();
198198
float viewportHeight = viewportManager.getHeight();
199199

200-
int sidePadding = (viewportHeight > (viewportWidth / 1.25f))? 15 : 30;
200+
// This is the padding on the left and right sides of the screen, not app buttons.
201+
int sidePadding = (viewportHeight > (viewportWidth / 1.25f))? 12 : 15;
201202

202203
int availableHeight = (int)(viewportHeight - PAGINATION_HEIGHT);
203-
int columns = (int)((viewportWidth - sidePadding) / ICON_IMAGE_WIDTH);
204+
int columns = (int)((viewportWidth - (sidePadding * 2)) / ICON_IMAGE_WIDTH);
204205
int rows = (int)(availableHeight / (ICON_IMAGE_HEIGHT + ICON_LABEL_HEIGHT + 10));
205206

207+
// This is the total amount of padding after removal of side padding.
206208
int totalHorizPadding = 0;
209+
210+
// This is the amount of padding either side of each app button.
207211
int horizPaddingUnit = 0;
208212

209213
Button infoButton = buildButton("INFO", null, "png/info.png", 96, 96, null, null);
@@ -874,7 +878,9 @@ public void showProgramPage(int programIndex, boolean skipScroll) {
874878

875879
// Work out how far to move from far left to get to program's page.
876880
int programsPerPage = pagedScrollPane.getProgramsPerPage();
877-
float pageWidth = viewportManager.isPortrait()? 1130.0f : 1970.0f;
881+
float pageWidth = viewportManager.isPortrait()?
882+
1080 + pagedScrollPane.getContentSpacing() :
883+
1920 + pagedScrollPane.getContentSpacing();
878884
float newScrollX = pageWidth * (programIndex / programsPerPage) + pageWidth;
879885

880886
// Set program highlight to the program with the specified index.

core/src/main/java/emu/joric/ui/PagedScrollPane.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
public class PagedScrollPane extends ScrollPane {
1818

19+
private static final int CONTENT_SPACING = 50;
20+
1921
private boolean wasPanDragFling = false;
2022

2123
private float lastScrollX = 0;
@@ -58,7 +60,7 @@ public void setHomeScreen(HomeScreen homeScreen) {
5860

5961
private void setup() {
6062
content = new Table();
61-
content.defaults().space(50);
63+
content.defaults().space(CONTENT_SPACING);
6264
super.setWidget(content);
6365
Button.debugCellColor = new Color(1, 1, 1, 1.0f);
6466
}
@@ -209,7 +211,7 @@ public int getNumOfPages() {
209211
public int getCurrentPageNumber() {
210212
int pageNumber = 0;
211213
if (content.getChildren().notEmpty()) {
212-
int pageWidth = (int)(content.getChild(0).getWidth() + 50);
214+
int pageWidth = (int)(content.getChild(0).getWidth() + CONTENT_SPACING);
213215
pageNumber = Math.round(getScrollX() / pageWidth);
214216
}
215217
return pageNumber;
@@ -386,6 +388,15 @@ public void prevProgramPage() {
386388
updateSelection(currentSelectionIndex - getProgramsPerPage(), false);
387389
}
388390

391+
/**
392+
* Gets the number of pixels gap between pages.
393+
*
394+
* @return The number of pixels gap between pages.
395+
*/
396+
public int getContentSpacing() {
397+
return CONTENT_SPACING;
398+
}
399+
389400
/**
390401
* This method is used by the key navigation, i.e. when it has calculated a specific
391402
* program index to move to. The navigation keys are used to navigation +/- one
@@ -397,7 +408,8 @@ public void prevProgramPage() {
397408
private void showProgramPage(int programIndex) {
398409
// Work out how far to move from far left to get to program's page.
399410
int programsPerPage = getProgramsPerPage();
400-
float pageWidth = ViewportManager.getInstance().isPortrait()? 1130.0f : 1970.0f;
411+
float pageWidth = ViewportManager.getInstance().isPortrait()?
412+
1080.0f + CONTENT_SPACING : 1920.0f + CONTENT_SPACING;
401413
float newScrollX = pageWidth * (programIndex / programsPerPage) + pageWidth;
402414

403415
setScrollX(newScrollX);

0 commit comments

Comments
 (0)