View textcanvas8.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalTextApi::class) | |
@Composable | |
fun ExampleTextOverFlow() { | |
val textMeasure = rememberTextMeasurer() | |
Canvas( | |
onDraw = { | |
drawRect(color = Color.Black) |
View textcanvas7.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalTextApi::class) | |
@Composable | |
fun ExampleTextLayoutResult() { | |
val textMeasure = rememberTextMeasurer() | |
var textLayoutResult by remember { mutableStateOf<TextLayoutResult?>(null) } | |
Canvas( | |
modifier = Modifier | |
.fillMaxWidth() | |
.height(100.dp) |
View textcanvas7.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val textMeasure = rememberTextMeasurer() | |
var textLayoutResult by remember { mutableStateOf<TextLayoutResult?>(null) } | |
Canvas( | |
modifier = Modifier | |
.layout { measurable, constraints -> | |
val placeable = measurable.measure(constraints) | |
textLayoutResult = textMeasure.measure( | |
AnnotatedString("Text on Canvas!"), |
View textcanvas6.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalTextApi | |
fun DrawScope.drawText( | |
textLayoutResult: TextLayoutResult, | |
color: Color = Color.Unspecified, | |
topLeft: Offset = Offset.Zero, | |
alpha: Float = Float.NaN, | |
shadow: Shadow? = null, | |
textDecoration: TextDecoration? = null | |
){} | |
@ExperimentalTextApi |
View textcanvas5.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun ExampleTextString() { | |
val textMeasure = rememberTextMeasurer() | |
Canvas(modifier = Modifier | |
.fillMaxWidth() | |
.height(100.dp), onDraw = { | |
drawRect(color = Color.Black) |
View textcanvas4.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalTextApi | |
fun DrawScope.drawText( | |
textMeasurer: TextMeasurer, | |
text: String, | |
// Other configuration | |
) |
View textcanvas3.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalTextApi::class) | |
@Composable | |
fun ExampleTextAnnotatedString() { | |
val textMeasure = rememberTextMeasurer() | |
val text = buildAnnotatedString { | |
withStyle( | |
style = SpanStyle( | |
color = Color.White, |
View textcanvas2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun DrawScope.drawText( | |
textMeasurer: TextMeasurer, | |
text: AnnotatedString, | |
// other configuration... | |
) |
View textcanvas1.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun NativeDrawText() { | |
val paint = Paint().asFrameworkPaint().apply { | |
// paint configuration | |
} | |
Canvas(modifier = Modifier | |
.fillMaxWidth() | |
.height(100.dp), onDraw = { |
View click-effect-12.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun NoRippleEffect3() { | |
CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) { | |
Button( | |
onClick = { | |
//Clicked | |
}, shape = RoundedCornerShape(12.dp), | |
contentPadding = PaddingValues(16.dp) | |
) { | |
Text(text = "Click me") |
NewerOlder