Refactor keyboard cell height logic for consistency (#10501)
Adjust keyboard cell height calculation for better layout consistency across different screen sizes. Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
co-authored by
GitHub
Ben Meadors
parent
894c5556cf
commit
f3cb2bff78
@@ -142,8 +142,9 @@ void VirtualKeyboard::draw(OLEDDisplay *display, int16_t offsetX, int16_t offset
|
|||||||
if (keyboardStartY < 0)
|
if (keyboardStartY < 0)
|
||||||
keyboardStartY = 0;
|
keyboardStartY = 0;
|
||||||
} else {
|
} else {
|
||||||
// Default (non-wide, non-64px) behavior: use key height heuristic and place at bottom
|
// Default (non-wide, non-64px) e.g. SH1107 128x128:
|
||||||
cellH = KEY_HEIGHT;
|
// cellH = FONT_HEIGHT_SMALL - 2 so rows are tighter while still hosting the font
|
||||||
|
cellH = std::max((int)KEY_HEIGHT, FONT_HEIGHT_SMALL - 2);
|
||||||
int keyboardHeight = KEYBOARD_ROWS * cellH;
|
int keyboardHeight = KEYBOARD_ROWS * cellH;
|
||||||
keyboardStartY = screenH - keyboardHeight;
|
keyboardStartY = screenH - keyboardHeight;
|
||||||
if (keyboardStartY < 0)
|
if (keyboardStartY < 0)
|
||||||
@@ -446,11 +447,8 @@ void VirtualKeyboard::drawKey(OLEDDisplay *display, const VirtualKey &key, bool
|
|||||||
if (textX < x)
|
if (textX < x)
|
||||||
textX = x; // guard
|
textX = x; // guard
|
||||||
} else {
|
} else {
|
||||||
if (display->getHeight() <= 64 && (key.character >= '0' && key.character <= '9')) {
|
// Use ceil rounding for all screens (consistent with 128x64 behavior for numbers)
|
||||||
textX = x + (width - textWidth + 1) / 2;
|
textX = x + (width - textWidth + 1) / 2;
|
||||||
} else {
|
|
||||||
textX = x + (width - textWidth) / 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int contentTop = y;
|
int contentTop = y;
|
||||||
int contentH = height;
|
int contentH = height;
|
||||||
@@ -746,4 +744,4 @@ bool VirtualKeyboard::isTimedOut() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace graphics
|
} // namespace graphics
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user