Fix miscalculation of the space between the keys

'keyVerticalInterval' was mistakenly used to compute the height of the
keyboard and the vertical position of keys.
While the code handling pointers did not use this value, the hit box of
the bottom row was shifted by several pixels.

Make sure 'keyVerticalInterval' is only used for rendering and not for
placing the keys.
This commit is contained in:
Jules Aguillon 2022-01-15 20:24:27 +01:00
parent fa9250a89e
commit 833dfa31bb
2 changed files with 10 additions and 8 deletions

View File

@ -86,7 +86,9 @@ final class Config
longPressTimeout = prefs.getInt("longpress_timeout", (int)longPressTimeout);
longPressInterval = prefs.getInt("longpress_interval", (int)longPressInterval);
marginBottom = getDipPref(dm, prefs, "margin_bottom", marginBottom);
keyHeight = getDipPref(dm, prefs, "key_height", keyHeight);
// Add keyVerticalInterval to keyHeight because the space between the keys
// is removed from the keys during rendering
keyHeight = getDipPref(dm, prefs, "key_height", keyHeight) + keyVerticalInterval;
horizontalMargin = getDipPref(dm, prefs, "horizontal_margin", horizontalMargin);
preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat);
characterSize = prefs.getFloat("character_size", characterSize);

View File

@ -349,7 +349,7 @@ public class Keyboard2View extends View
int width = dm.widthPixels;
int height =
(int)(_config.keyHeight * _keyboard.keysHeight
+ _keyboard.rows.size() * _config.keyVerticalInterval
+ _keyboard.rows.size()
+ _config.marginTop + _config.marginBottom);
setMeasuredDimension(width, height);
_keyWidth = (width - (_config.horizontalMargin * 2)) / _keyboard.keysWidth;
@ -358,15 +358,15 @@ public class Keyboard2View extends View
@Override
protected void onDraw(Canvas canvas)
{
float y = _config.marginTop;
float y = _config.marginTop + _config.keyVerticalInterval / 2;
for (KeyboardData.Row row : _keyboard.rows)
{
y += row.shift * _config.keyHeight;
float x = _config.horizontalMargin;
float keyH = row.height * _config.keyHeight;
float x = _config.horizontalMargin + _config.keyHorizontalInterval / 2;
float keyH = row.height * _config.keyHeight - _config.keyVerticalInterval;
for (KeyboardData.Key k : row.keys)
{
x += k.shift * _keyWidth + _config.keyHorizontalInterval;
x += k.shift * _keyWidth;
float keyW = _keyWidth * k.width - _config.keyHorizontalInterval;
KeyDown keyDown = getKeyDown(k);
_tmpRect.set(x, y, x + keyW, y + keyH);
@ -383,9 +383,9 @@ public class Keyboard2View extends View
drawSubLabel(canvas, k.key2, x + keyW - subPadding, y + subPadding, true, true, keyDown);
if (k.key4 != null)
drawSubLabel(canvas, k.key4, x + keyW - subPadding, y + keyH - subPadding, true, false, keyDown);
x += keyW;
x += _keyWidth * k.width;
}
y += keyH + _config.keyVerticalInterval;
y += row.height * _config.keyHeight;
}
}