Fixed
Status Update
Comments
za...@gmail.com <za...@gmail.com> #2
It would also be great to support API similar to StaticLayout (https://developer.android.com/reference/android/text/StaticLayout ), that would allow for measuring/drawing of text that gets wrapped automatically, so that these don't need to be manually calculated.
an...@google.com <an...@google.com>
si...@google.com <si...@google.com> #3
It would also be great to support API similar to StaticLayout
Paragraph() is the equivalent of StaticLayout
se...@gmail.com <se...@gmail.com> #4
Hi! Just checking to see if any progress has been made on this. Thanks.
ha...@google.com <ha...@google.com>
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-main
commit f8827dce0c2aff66def97f032e8fc7b381801a51
Author: Halil Ozercan <halilibo@google.com>
Date: Thu Jun 23 18:27:06 2022
Add DrawScope.drawText method to enable drawing text on Compose Canvas using TextMeasurer.
This function has 4 overloads categorized into two; implicit and explicit use of TextMeasurer.
First two overloads take required parameters to draw a text in its entirety and a text measurer that actually computes the final layout. Difference between overloads is that one accepts AnnotatedString and the other one accepts String. Essentially AnnotatedString overload provides multi-styling while String overload provides an easy-to-use API.
The other two overloads draw a `TextLayoutResult` which can be generated by `TextMeasurer.measure` call. These functions can be useful for advanced use cases that optimize text measurement on top of the internal cache of a `TextMeasurer`. These functions also expose the ability to change non-layout-affecting attributes like color, brush, shadow during draw phase.
Fix: b/190787898
Relnote: "Added `drawText` extension function on `DrawScope` to provide a way to draw multi-styled text on composables and modifiers that operate on a DrawScope like `Canvas` and `drawBehind`."
Test: TextPainterTest.kt
Change-Id: I16a6226ae83d879f2c493fb811f1ecef77a1fc15
A compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/TextPainterTest.kt
M compose/ui/ui-text/api/restricted_current.txt
M compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/TextPainter.kt
M compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt
M compose/ui/ui-text/api/public_plus_experimental_current.txt
A compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/DrawTextDemo.kt
M compose/ui/ui-text/api/current.txt
A compose/ui/ui-text/samples/src/main/java/androidx/compose/ui/text/samples/DrawTextSamples.kt
https://android-review.googlesource.com/2135315
Branch: androidx-main
commit f8827dce0c2aff66def97f032e8fc7b381801a51
Author: Halil Ozercan <halilibo@google.com>
Date: Thu Jun 23 18:27:06 2022
Add DrawScope.drawText method to enable drawing text on Compose Canvas using TextMeasurer.
This function has 4 overloads categorized into two; implicit and explicit use of TextMeasurer.
First two overloads take required parameters to draw a text in its entirety and a text measurer that actually computes the final layout. Difference between overloads is that one accepts AnnotatedString and the other one accepts String. Essentially AnnotatedString overload provides multi-styling while String overload provides an easy-to-use API.
The other two overloads draw a `TextLayoutResult` which can be generated by `TextMeasurer.measure` call. These functions can be useful for advanced use cases that optimize text measurement on top of the internal cache of a `TextMeasurer`. These functions also expose the ability to change non-layout-affecting attributes like color, brush, shadow during draw phase.
Fix:
Relnote: "Added `drawText` extension function on `DrawScope` to provide a way to draw multi-styled text on composables and modifiers that operate on a DrawScope like `Canvas` and `drawBehind`."
Test: TextPainterTest.kt
Change-Id: I16a6226ae83d879f2c493fb811f1ecef77a1fc15
A compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/TextPainterTest.kt
M compose/ui/ui-text/api/restricted_current.txt
M compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/TextPainter.kt
M compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt
M compose/ui/ui-text/api/public_plus_experimental_current.txt
A compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/DrawTextDemo.kt
M compose/ui/ui-text/api/current.txt
A compose/ui/ui-text/samples/src/main/java/androidx/compose/ui/text/samples/DrawTextSamples.kt
Description
Currently, the
drawText
function is not available for @Composable Canvas. To draw a text, we need to usecanvas.nativeCanvas.drawText
, which is the function from android.graphics.Canvas.java. The drawText function could have similar parameters like drawLine or other functions from @Composable Canvas. for example: fun drawText(text: String, color: Color, position: Offset, alpha: Float = 1.0f) This probably should also have style, size, and other parameters from @Composable Text.