Last active
October 27, 2022 22:34
-
-
Save Salzian/f6a6ecb1939f25243fa035b2d8a66b6e to your computer and use it in GitHub Desktop.
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.
This file contains hidden or 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 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) | |
) { | |
content() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment