You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Vertical and Horizontal space around the text are used additional values #1
changed the title [-]Vertical and Horizontal space around the text additional values[/-][+]Vertical and Horizontal space around the text are used additional values[/+]on May 21, 2022
Those are the base values to use when fontSize, or text height, is too small. 24% or 12% of small text height values doesn't look good. You can test it out by removing static values and use 12.sp or less. If you can come up with better formula for paddings for any size of text or paddings, feel free to open a PR.
Yes, but i think it would be better to changed them with Float.coerceAtLeast as ((textHeight * .12f).coerceAtLeast(Some number) + paddingVertical).toInt() would be better
I looked into this and your "magic" values would work only with default Android fonts.
During testing it I figured out that would be better to use val textHeight = (paint.fontFetrics.bottom - paint.fontFetrics.top)
Then val verticalSpaceAroundText = textHight - textSize
Then we need to calculate horizontalSpace to make background a circle if text.lenght == 1 otherwise rect
val paddedTextWidth = (textWidth + spaceAroundText * 2 + paddingStart + paddingEnd).toInt()
val desiredHeight = (textHeight + spaceAroundText + paddingTop + paddingBottom).toInt()
val desiredWidth = paddedTextWidth.coerceAtLeast(desiredHeight)
I used all space as a left and right padding to expand a rect
otherwise it will be smaller then circle shape when there is text.length == 2
Activity
[-]Vertical and Horizontal space around the text additional values[/-][+]Vertical and Horizontal space around the text are used additional values[/+]SmartToolFactory commentedon May 21, 2022
Those are the base values to use when fontSize, or text height, is too small. 24% or 12% of small text height values doesn't look good. You can test it out by removing static values and use 12.sp or less. If you can come up with better formula for paddings for any size of text or paddings, feel free to open a PR.
XFRAY commentedon May 21, 2022
6 and 8 are used also by that reason ?
SmartToolFactory commentedon May 21, 2022
Yes, but i think it would be better to changed them with
Float.coerceAtLeastas((textHeight * .12f).coerceAtLeast(Some number) + paddingVertical).toInt()would be betterXFRAY commentedon Jun 2, 2022
I looked into this and your "magic" values would work only with default Android fonts.
During testing it I figured out that would be better to use
val textHeight = (paint.fontFetrics.bottom - paint.fontFetrics.top)Then
val verticalSpaceAroundText = textHight - textSizeThen we need to calculate
horizontalSpaceto make background a circle iftext.lenght== 1 otherwise rectI used all space as a left and right padding to expand a rect
otherwise it will be smaller then circle shape when there is
text.length== 2