Skip to content

Commit

Permalink
UIWrappedText: Fix calculation of the max number of lines that can fi…
Browse files Browse the repository at this point in the history
…t within the component
  • Loading branch information
Sk1er committed Oct 5, 2022
1 parent c8a95a2 commit e68fdf8
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ open class UIWrappedText @JvmOverloads constructor(
textState.get(),
width,
textScale,
((getHeight() / textScale - extraHeightState.get()) / lineSpacing).toInt(),
getMaxLines(),
ensureSpaceAtEndOfLines = false,
fontProvider = getFontProvider(),
trimmedTextSuffix = trimmedTextSuffix
Expand Down Expand Up @@ -196,4 +196,16 @@ open class UIWrappedText @JvmOverloads constructor(

super.draw(matrixStack)
}

private fun getMaxLines(): Int {
val fontProvider = getFontProvider()
val height = getHeight() / getTextScale() - extraHeightState.get()
val baseLineHeight = fontProvider.getBaseLineHeight() + fontProvider.getBelowLineHeight() + fontProvider.getShadowHeight()

if (height < baseLineHeight) {
return 0
}

return 1 + ((height - baseLineHeight) / lineSpacing).toInt()
}
}

0 comments on commit e68fdf8

Please sign in to comment.