Thread
#compose
    d

    Denis

    1 year ago
    Could anybody explain how
    lineHeight
    works? Why doesn't it affect the first line? What is the space below the first line? (Code in thread)
    Code:
    @Preview(showBackground = true)
    @Composable
    fun LineHeightPreview(size: Int = 100) {
        val dm = AmbientContext.current.resources.displayMetrics
        val text = buildAnnotatedString {
            pushStyle(ParagraphStyle(lineHeight = (4 * size).sp))
            pushStyle(SpanStyle(fontSize = size.sp))
            append("ABCfly\nABCfly")
        }
        val textDelegate = TextDelegate(text, TextStyle.Default, resourceLoader = AmbientFontLoader.current, density = Density(dm.density))
        val r = textDelegate.layout(Constraints(), LayoutDirection.Ltr)
        Canvas(modifier = Modifier.width((r.size.width / dm.density).dp).height((r.size.height / dm.density).dp)) {
            val t0 = r.getLineTop(0)
            drawLine(Color.Blue, start = Offset(y = t0, x = 0f), end = Offset(y = t0, x = r.size.width.toFloat()), strokeWidth = 20f)
            val b0 = r.getLineBottom(0)
            drawLine(Color.Magenta, start = Offset(y = b0, x = 0f), end = Offset(y = b0, x = r.size.width.toFloat()), strokeWidth = 40f)
            val t1 = r.getLineTop(1)
            drawLine(Color.Blue, start = Offset(y = t1, x = 0f), end = Offset(y = t1, x = r.size.width.toFloat()), strokeWidth = 20f)
            drawIntoCanvas { TextDelegate.paint(canvas = it, r) }
        }
    }
    Chris Sinco [G]

    Chris Sinco [G]

    1 year ago
    @Siyamed thoughts?
    Siyamed

    Siyamed

    1 year ago
    looks like an inherit from android platform
    @HaoyuZhang in case they remember if this is on purpose or what the decision was