From d7f576d6b7eff06975eeff5941cf4fee13ada687 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 5 Jun 2012 07:38:58 -0700 Subject: [PATCH] fix board dimensioning for small (needs-scrolling) screens. Since this effects larger screens needs some testing. --- .../org/eehouse/android/xw4/BoardView.java | 45 +++++++++++++------ .../eehouse/android/xw4/jni/JNIThread.java | 8 +++- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java index 366bace3c..f41929e8d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -256,24 +256,41 @@ public class BoardView extends View implements DrawCtx, BoardHandler, } result.maxCellSize = maxCellSize; - result.trayHt = cellSize * 3; - result.scoreHt = 2 * m_defaultFontHt; - int wantHt = result.trayHt + result.scoreHt + (cellSize * nCells); - int nToScroll = 0; + // Now determine if vertical scrolling will be necessary. + // There's a minimum tray and scoreboard height. If we can + // fit them and all cells no scrolling's needed. Otherwise + // determine the minimum number that must be hidden to fit. + // Finally grow scoreboard and tray to use whatever's left. + int trayHt = (5 * cellSize) / 2; + int scoreHt = (cellSize * 3) / 2; + int wantHt = trayHt + scoreHt + (cellSize * nCells); + int nToScroll; if ( wantHt <= height ) { - result.top = (height - wantHt) / 2; + nToScroll = 0; } else { - int minTray = 3 * m_defaultFontHt; - nToScroll = - nCells - ((height - minTray - result.scoreHt) / cellSize); - result.trayHt = - height - result.scoreHt - (cellSize * (nCells-nToScroll)); - result.top = 0; + nToScroll = nCells - ((height - trayHt - scoreHt) / cellSize); } - result.boardHt = cellSize * (nCells-nToScroll); - result.trayTop = result.scoreHt + result.boardHt; - result.height = result.scoreHt + result.boardHt + result.trayHt; + int heightUsed = trayHt + scoreHt + (nCells - nToScroll) * cellSize; + int heightLeft = height - heightUsed; + if ( 0 < heightLeft ) { + if ( heightLeft > (cellSize * 3 / 2) ) { + heightLeft = cellSize * 3 / 2; + } + heightLeft /= 3; + trayHt += heightLeft * 2; + scoreHt += heightLeft; + } + heightUsed = trayHt + scoreHt + ((nCells - nToScroll) * cellSize); + heightLeft = height - heightUsed; + result.top = heightLeft / 2; + + result.trayHt = trayHt; + result.scoreHt = scoreHt; + + result.boardHt = cellSize * nCells; + result.trayTop = scoreHt + (cellSize * (nCells-nToScroll)); + result.height = heightUsed; result.cellSize = cellSize; if ( gi.timerEnabled ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index 50c1a9f8f..c5a13473e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -233,12 +233,16 @@ public class JNIThread extends Thread { XwJNI.board_setScoreboardLoc( m_jniGamePtr, 0, 0, scoreWidth, dims.scoreHt, true ); + // Have no idea why I was doing -1 below, but it breaks layout + // for small (QVGA) boards. If it needs to be done, do it + // early in figureBoardDims so the calculations that follow + // are consistent. XwJNI.board_setPos( m_jniGamePtr, 0, dims.scoreHt, - dims.width-1, dims.boardHt, dims.maxCellSize, + dims.width/*-1*/, dims.boardHt, dims.maxCellSize, false ); XwJNI.board_setTrayLoc( m_jniGamePtr, 0, dims.trayTop, - dims.width-1, dims.trayHt, kMinDivWidth ); + dims.width/*-1*/, dims.trayHt, kMinDivWidth ); XwJNI.board_invalAll( m_jniGamePtr ); }