-
-
Notifications
You must be signed in to change notification settings - Fork 459
fix: multiple UI and functionality fixes #1971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e8a7d81
aff3f7c
56d8be9
d5ff4ec
66bc812
368fe54
5be91b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -328,7 +328,8 @@ class KeyView( | |
|
|
||
| val centerX = (width - paddingLeft - paddingRight) / 2f + paddingLeft | ||
| val centerY = (height - paddingTop - paddingBottom) / 2f + paddingTop | ||
| val adjustmentY = (textPaint.textSize - textPaint.descent()) / 2f | ||
| val fontMetrics = textPaint.fontMetrics | ||
| val adjustmentY = -(fontMetrics.ascent + fontMetrics.descent) / 2f | ||
|
|
||
| canvas.drawText(label, centerX + sp(key.keyTextOffsetX), centerY + adjustmentY + sp(key.keyTextOffsetY), textPaint) | ||
| } | ||
|
|
@@ -397,15 +398,22 @@ class KeyView( | |
| typeface = FontManager.getTypeface("symbol_font") | ||
| } | ||
|
|
||
| val lines = text.split("\n") | ||
| val fontMetrics = symbolPaint.fontMetrics | ||
| val lineHeight = fontMetrics.descent - fontMetrics.ascent | ||
| val totalHeight = lineHeight * lines.size | ||
|
|
||
|
Comment on lines
+401
to
+405
|
||
| val centerX = (width - paddingLeft - paddingRight) / 2f + paddingLeft + sp(offsetX) | ||
| val centerY = if (isTop) { | ||
| paddingTop - fontMetrics.top + sp(offsetY) | ||
| val startY = if (isTop) { | ||
| paddingTop - fontMetrics.top + sp(offsetY) - (totalHeight - lineHeight) / 2 | ||
| } else { | ||
| height - paddingBottom - fontMetrics.bottom + sp(offsetY) | ||
| height - paddingBottom - fontMetrics.bottom + sp(offsetY) - (totalHeight - lineHeight) / 2 | ||
| } | ||
|
|
||
| canvas.drawText(text, centerX, centerY, symbolPaint) | ||
| for (i in lines.indices) { | ||
| val lineY = startY + lineHeight * i | ||
| canvas.drawText(lines[i], centerX, lineY, symbolPaint) | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calculateTranslateX()divides byscaleX, butscaleXcan become 0 (e.g., whencontentWidth == 0in Horizontal/Proportional mode). That would produceInfinity/NaNfortranslateXand can break drawing. Add a guard forscaleX == 0f(and potentiallycontentWidth <= 0) to return a safe translation, or clampscaleXto a small positive value before dividing.