mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
am 5dda75b5
: Add methods to get a Key\'s horizontal and vertical gaps.
* commit '5dda75b538ee53351fdfd800e0e5a9f329ad7c2e': Add methods to get a Key's horizontal and vertical gaps.
This commit is contained in:
commit
40ba31a9cc
@ -98,6 +98,16 @@ public class Key implements Comparable<Key> {
|
|||||||
private final int mWidth;
|
private final int mWidth;
|
||||||
/** Height of the key, excluding the gap */
|
/** Height of the key, excluding the gap */
|
||||||
private final int mHeight;
|
private final int mHeight;
|
||||||
|
/**
|
||||||
|
* The combined width in pixels of the horizontal gaps belonging to this key, both to the left
|
||||||
|
* and to the right. I.e., mWidth + mHorizontalGap = total width belonging to the key.
|
||||||
|
*/
|
||||||
|
private final int mHorizontalGap;
|
||||||
|
/**
|
||||||
|
* The combined height in pixels of the vertical gaps belonging to this key, both above and
|
||||||
|
* below. I.e., mHeight + mVerticalGap = total height belonging to the key.
|
||||||
|
*/
|
||||||
|
private final int mVerticalGap;
|
||||||
/** X coordinate of the top-left corner of the key in the keyboard layout, excluding the gap. */
|
/** X coordinate of the top-left corner of the key in the keyboard layout, excluding the gap. */
|
||||||
private final int mX;
|
private final int mX;
|
||||||
/** Y coordinate of the top-left corner of the key in the keyboard layout, excluding the gap. */
|
/** Y coordinate of the top-left corner of the key in the keyboard layout, excluding the gap. */
|
||||||
@ -198,8 +208,10 @@ public class Key implements Comparable<Key> {
|
|||||||
final String hintLabel, final int labelFlags, final int backgroundType, final int x,
|
final String hintLabel, final int labelFlags, final int backgroundType, final int x,
|
||||||
final int y, final int width, final int height, final int horizontalGap,
|
final int y, final int width, final int height, final int horizontalGap,
|
||||||
final int verticalGap) {
|
final int verticalGap) {
|
||||||
mHeight = height - verticalGap;
|
|
||||||
mWidth = width - horizontalGap;
|
mWidth = width - horizontalGap;
|
||||||
|
mHeight = height - verticalGap;
|
||||||
|
mHorizontalGap = horizontalGap;
|
||||||
|
mVerticalGap = verticalGap;
|
||||||
mHintLabel = hintLabel;
|
mHintLabel = hintLabel;
|
||||||
mLabelFlags = labelFlags;
|
mLabelFlags = labelFlags;
|
||||||
mBackgroundType = backgroundType;
|
mBackgroundType = backgroundType;
|
||||||
@ -214,7 +226,7 @@ public class Key implements Comparable<Key> {
|
|||||||
mEnabled = (code != CODE_UNSPECIFIED);
|
mEnabled = (code != CODE_UNSPECIFIED);
|
||||||
mIconId = iconId;
|
mIconId = iconId;
|
||||||
// Horizontal gap is divided equally to both sides of the key.
|
// Horizontal gap is divided equally to both sides of the key.
|
||||||
mX = x + horizontalGap / 2;
|
mX = x + mHorizontalGap / 2;
|
||||||
mY = y;
|
mY = y;
|
||||||
mHitBox.set(x, y, x + width + 1, y + height);
|
mHitBox.set(x, y, x + width + 1, y + height);
|
||||||
mKeyVisualAttributes = null;
|
mKeyVisualAttributes = null;
|
||||||
@ -235,18 +247,21 @@ public class Key implements Comparable<Key> {
|
|||||||
*/
|
*/
|
||||||
public Key(final String keySpec, final TypedArray keyAttr, final KeyStyle style,
|
public Key(final String keySpec, final TypedArray keyAttr, final KeyStyle style,
|
||||||
final KeyboardParams params, final KeyboardRow row) {
|
final KeyboardParams params, final KeyboardRow row) {
|
||||||
final float horizontalGap = isSpacer() ? 0 : params.mHorizontalGap;
|
mHorizontalGap = isSpacer() ? 0 : params.mHorizontalGap;
|
||||||
|
mVerticalGap = params.mVerticalGap;
|
||||||
|
|
||||||
|
final float horizontalGapFloat = mHorizontalGap;
|
||||||
final int rowHeight = row.getRowHeight();
|
final int rowHeight = row.getRowHeight();
|
||||||
mHeight = rowHeight - params.mVerticalGap;
|
mHeight = rowHeight - mVerticalGap;
|
||||||
|
|
||||||
final float keyXPos = row.getKeyX(keyAttr);
|
final float keyXPos = row.getKeyX(keyAttr);
|
||||||
final float keyWidth = row.getKeyWidth(keyAttr, keyXPos);
|
final float keyWidth = row.getKeyWidth(keyAttr, keyXPos);
|
||||||
final int keyYPos = row.getKeyY();
|
final int keyYPos = row.getKeyY();
|
||||||
|
|
||||||
// Horizontal gap is divided equally to both sides of the key.
|
// Horizontal gap is divided equally to both sides of the key.
|
||||||
mX = Math.round(keyXPos + horizontalGap / 2);
|
mX = Math.round(keyXPos + horizontalGapFloat / 2);
|
||||||
mY = keyYPos;
|
mY = keyYPos;
|
||||||
mWidth = Math.round(keyWidth - horizontalGap);
|
mWidth = Math.round(keyWidth - horizontalGapFloat);
|
||||||
mHitBox.set(Math.round(keyXPos), keyYPos, Math.round(keyXPos + keyWidth) + 1,
|
mHitBox.set(Math.round(keyXPos), keyYPos, Math.round(keyXPos + keyWidth) + 1,
|
||||||
keyYPos + rowHeight);
|
keyYPos + rowHeight);
|
||||||
// Update row to have current x coordinate.
|
// Update row to have current x coordinate.
|
||||||
@ -388,6 +403,8 @@ public class Key implements Comparable<Key> {
|
|||||||
mIconId = key.mIconId;
|
mIconId = key.mIconId;
|
||||||
mWidth = key.mWidth;
|
mWidth = key.mWidth;
|
||||||
mHeight = key.mHeight;
|
mHeight = key.mHeight;
|
||||||
|
mHorizontalGap = key.mHorizontalGap;
|
||||||
|
mVerticalGap = key.mVerticalGap;
|
||||||
mX = key.mX;
|
mX = key.mX;
|
||||||
mY = key.mY;
|
mY = key.mY;
|
||||||
mHitBox.set(key.mHitBox);
|
mHitBox.set(key.mHitBox);
|
||||||
@ -787,6 +804,24 @@ public class Key implements Comparable<Key> {
|
|||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The combined width in pixels of the horizontal gaps belonging to this key, both above and
|
||||||
|
* below. I.e., getWidth() + getHorizontalGap() = total width belonging to the key.
|
||||||
|
* @return Horizontal gap belonging to this key.
|
||||||
|
*/
|
||||||
|
public int getHorizontalGap() {
|
||||||
|
return mHorizontalGap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The combined height in pixels of the vertical gaps belonging to this key, both above and
|
||||||
|
* below. I.e., getHeight() + getVerticalGap() = total height belonging to the key.
|
||||||
|
* @return Vertical gap belonging to this key.
|
||||||
|
*/
|
||||||
|
public int getVerticalGap() {
|
||||||
|
return mVerticalGap;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the x-coordinate of the top-left corner of the key in pixels, excluding the gap.
|
* Gets the x-coordinate of the top-left corner of the key in pixels, excluding the gap.
|
||||||
* @return The x-coordinate of the top-left corner of the key in pixels, excluding the gap.
|
* @return The x-coordinate of the top-left corner of the key in pixels, excluding the gap.
|
||||||
|
Loading…
Reference in New Issue
Block a user