Skip to content

Instantly share code, notes, and snippets.

View Salzian's full-sized avatar

Fabian Fritzsche Salzian

View GitHub Profile
@Salzian
Salzian / RoundBoxInset.kt
Last active October 27, 2022 22:34
This piece of math recreates the BoxInsetLayout class behaviour for View based UI building on Wear OS in Jetpack Compose. Using this @Composabe will create a Box within the confines of a round display without cutting off the corners.
@Composable
fun RoundBoxInset(content: @Composable () -> Unit = {}) {
BoxWithConstraints {
val horizontalPadding = (maxWidth.value - (maxWidth.value / 2.0 * sqrt(2.0))) / 2.0
val verticalPadding = (maxHeight.value - (maxHeight.value / 2.0 * sqrt(2.0))) / 2.0
Box(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = horizontalPadding.dp, vertical = verticalPadding.dp)