Skip to content

Instantly share code, notes, and snippets.

@chiragthummar
Created January 17, 2024 12:40
Show Gist options
  • Save chiragthummar/a48c2ecaf44e775a6660e833e19a4431 to your computer and use it in GitHub Desktop.
Save chiragthummar/a48c2ecaf44e775a6660e833e19a4431 to your computer and use it in GitHub Desktop.
import android.content.ContentValues.TAG
import android.util.Log
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@Composable
fun Stack018() {
val textToDraw =
"Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups"
Text(text = textToDraw,
modifier = Modifier.fillMaxSize(),
onTextLayout = { textLayoutResult ->
val lineCount = textLayoutResult.lineCount
var lineOffset = 0
for (i in 0 until lineCount ) {
val lineEndIndex = textLayoutResult.getLineEnd(
lineIndex = i,
visibleEnd = true
)
val lineContent = textToDraw
.substring(lineOffset,lineEndIndex)
Log.e(TAG,"=== Word Count $i= ${lineContent.split(" ").count()}")
lineOffset = lineEndIndex
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment