Bryan Herbst
04/23/2021, 1:51 PMText()
measure as though its text is bold even when its not so that the size of the Text()
component doesn’t change as text gets bolded/unbolded.
What’s the best way to accomplish that?
Here’s an example of the behavior I don’t want:grandstaish
04/23/2021, 2:18 PMgrandstaish
04/23/2021, 2:18 PMZach Klippenstein (he/him) [MOD]
04/23/2021, 2:18 PMBryan Herbst
04/23/2021, 2:19 PMfun Modifier.widthByTextStyle(
text: String,
style: TextStyle
) = composed {
val maxIntrinsics = MultiParagraphIntrinsics(
annotatedString = AnnotatedString(text),
style = style,
placeholders = emptyList(),
density = LocalDensity.current,
resourceLoader = LocalFontLoader.current
)
val widthDp = with(LocalDensity.current) {
maxIntrinsics.maxIntrinsicWidth.toDp()
}
width(widthDp)
}
Bryan Herbst
04/23/2021, 2:19 PMZach Klippenstein (he/him) [MOD]
04/23/2021, 2:19 PMBryan Herbst
04/23/2021, 2:19 PMJavier
04/23/2021, 2:22 PMZach Klippenstein (he/him) [MOD]
04/23/2021, 2:23 PMZach Klippenstein (he/him) [MOD]
04/23/2021, 2:24 PMZach Klippenstein (he/him) [MOD]
04/23/2021, 2:24 PMBryan Herbst
04/23/2021, 2:24 PMBryan Herbst
04/23/2021, 2:25 PMprivate fun Modifier.scrollableSegmentBackground(selected: Boolean) = composed {
val elevationDp by animateDpAsState(
targetValue = if (selected) TargetElevation.OnLight.medium else 0.dp
)
val backgroundColor by animateColorAsState(
targetValue = if (selected) {
TargetTheme.colors.background.default
} else {
TargetTheme.colors.background.container
}
)
graphicsLayer(
shadowElevation = with(LocalDensity.current) { elevationDp.toPx() },
shape = SegmentShape
).background(
color = backgroundColor,
shape = SegmentShape
)
}
Siyamed
04/23/2021, 4:40 PMSiyamed
04/23/2021, 4:40 PMSiyamed
04/23/2021, 4:40 PMZach Klippenstein (he/him) [MOD]
04/23/2021, 5:01 PMThis makes grade a useful axis of variation as it can be varied or animated without causing reflow of the text itself.Wow this is super interesting. Learning so much today!
Colton Idle
04/23/2021, 5:04 PMBryan Herbst
04/23/2021, 5:08 PMscrollableSegmentBackground()
does both the background color and the elevation.