Skip to content

Commit

Permalink
Initial work towards dynamically adjusting home screen icon rows and …
Browse files Browse the repository at this point in the history
…columns based on screen dimensions.
  • Loading branch information
lanceewing committed Mar 30, 2024
1 parent 69bef5b commit 5545726
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions core/src/main/java/com/agifans/agile/HomeScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,32 @@ private void addAppButtonsToStage(Stage stage, AppConfig appConfig, int columns,
stage.addActor(container);
container.setFillParent(true);

int sidePadding = 0;
float viewportWidth = viewportManager.getWidth();
float viewportHeight = viewportManager.getHeight();

int sidePadding = (viewportHeight > (viewportWidth / 1.32f))? 15 : 85;

columns = (int)((viewportWidth - sidePadding) / ICON_IMAGE_WIDTH);
rows = (int)((viewportHeight - sidePadding) / (ICON_IMAGE_HEIGHT + ICON_LABEL_HEIGHT));

System.out.print("width: " + viewportWidth +
", height: " + viewportHeight +
", rows: " + rows +
", columns: " + columns +
"\n");

int totalHorizPadding = 0;
int horizPaddingUnit = 0;

if (columns > rows) {
if (viewportManager.isLandscape()) {
// Landscape.
sidePadding = 85; // 100 leaves 24 (i.e. 12 * 2) between. 85 leaves 30.
//sidePadding = 85; // 100 leaves 24 (i.e. 12 * 2) between. 85 leaves 30.
container.setBackground(new Image(backgroundLandscape).getDrawable());
totalHorizPadding = 1920 - (ICON_IMAGE_WIDTH * columns) - (sidePadding * 2);
horizPaddingUnit = totalHorizPadding / (columns * 2);
} else {
// Portrait.
sidePadding = 15; // 24 leaves 24 between. 15 leaves 30.
//sidePadding = 15; // 24 leaves 24 between. 15 leaves 30.
container.setBackground(new Image(backgroundPortrait).getDrawable());
totalHorizPadding = 1080 - (ICON_IMAGE_WIDTH * columns) - (sidePadding * 2);
horizPaddingUnit = totalHorizPadding / (columns * 2);
Expand Down Expand Up @@ -342,6 +355,7 @@ public void resize(int width, int height) {
} else {
Gdx.input.setInputProcessor(landscapeInputProcessor);
}
updateHomeScreenButtonStages();
}

@Override
Expand Down Expand Up @@ -490,6 +504,7 @@ public Texture drawEmptyIcon(int iconWidth, int iconHeight) {

private static final int ICON_IMAGE_WIDTH = 320;
private static final int ICON_IMAGE_HEIGHT = 240;
private static final int ICON_LABEL_HEIGHT = 110;

/**
* Creates a button to represent the given AppConfigItem.
Expand Down

0 comments on commit 5545726

Please sign in to comment.