Created
January 28, 2020 16:15
-
-
Save Semper-Viventem/0960652a66d78c1a7e8bb7cf072e071d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun drawBackground( | |
c: Canvas, | |
p: Paint, | |
left: Int, | |
right: Int, | |
top: Int, | |
baseline: Int, | |
bottom: Int, | |
text: CharSequence, | |
start: Int, | |
end: Int, | |
lnum: Int | |
) { | |
val actualWidth = p.measureText(text, start, end) + 2f * padding | |
val width = if (lnum == 0) { | |
actualWidth | |
} else if ((actualWidth < prevWidth) && (abs(prevWidth - actualWidth) < 2f * radius)) { | |
prevWidth | |
} else if ((actualWidth > prevWidth) && (abs(prevWidth - actualWidth) < 2f * radius)) { | |
actualWidth + (2f * radius - abs(prevWidth - actualWidth)) | |
} else { | |
actualWidth | |
} | |
val shiftLeft = 0f - padding | |
val shiftRight = width + shiftLeft | |
rect.set(shiftLeft, top.toFloat(), shiftRight, bottom.toFloat()) | |
c.drawRoundRect(rect, radius, radius, paint) | |
if (lnum > 0) { | |
drawCornerType1(c, path, rect, radius) | |
when { | |
prevWidth < width -> drawCornerType2(c, path, rect, radius) | |
prevWidth > width -> drawCornerType3(c, path, rect, radius) | |
else -> drawCornerType4(c, path, rect, radius) | |
} | |
} | |
prevWidth = width | |
prevLeft = rect.left | |
prevRight = rect.right | |
prevBottom = rect.bottom | |
prevTop = rect.top | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment