Skip to content

Vertical and Horizontal space around the text are used additional values #1

Open

Description

@XFRAY

As I see you use some additional values to measure vertical and horizontal padding

val verticalSpaceAroundText = (textHeight * .12f + 6 + paddingVertical).toInt()

What is 6 and .12 here ?

Same for
val horizontalSpaceAroundText = ((textHeight * .24f) + 8 + paddingHorizontal).toInt()

What is 8 and .24 here ?

Activity

  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
  2. SmartToolFactory commented on May 21, 2022

    @SmartToolFactory
    Owner

    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.

  3. XFRAY commented on May 21, 2022

    @XFRAY
    Author

    6 and 8 are used also by that reason ?

  4. SmartToolFactory commented on May 21, 2022

    @SmartToolFactory
    Owner

    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

  5. XFRAY commented on Jun 2, 2022

    @XFRAY
    Author

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions