Ui adjustments

This commit is contained in:
Koitharu
2022-06-28 12:44:59 +03:00
parent a55ff5ce5a
commit d9459dc8fa
3 changed files with 9 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ class ReadingProgressDrawable(
private val textColor: Int
private val textPattern = context.getString(R.string.percent_string_pattern)
private val textBounds = Rect()
private val tempRect = Rect()
private val hasBackground: Boolean
private val hasOutline: Boolean
private val hasText: Boolean
@@ -63,6 +64,8 @@ class ReadingProgressDrawable(
if (autoFitTextSize) {
val innerWidth = bounds.width() - (paint.strokeWidth * 2f)
paint.textSize = getTextSizeForWidth(innerWidth, "100%")
paint.getTextBounds(text, 0, text.length, textBounds)
invalidateSelf()
}
}
@@ -122,7 +125,7 @@ class ReadingProgressDrawable(
private fun getTextSizeForWidth(width: Float, text: String): Float {
val testTextSize = 48f
paint.textSize = testTextSize
paint.getTextBounds(text, 0, text.length, textBounds)
return testTextSize * width / textBounds.width()
paint.getTextBounds(text, 0, text.length, tempRect)
return testTextSize * width / tempRect.width()
}
}