I am developing UI Layout for an app based on Compose for Desktop
It consist of few check boxes.
But there is no functionality in Compose for Desktop to align views to each other.
In Android, we can use the Constraint Layout
for view alignment and it is super easy.
But what to do for Compose for Desktop?
Here is the layout I need to design in Desktop Compose
And here is the code I have written in Main.kt
file:
But the output is very different.
Would you please guide as there are no official documentation/videos for Compose For Desktop Layout Alignment and sizing ?
@Composable
@Preview
fun App() {
MaterialTheme(
) {
BoxWithConstraints {
TwoColumnsLayout()
}
}
}
@Composable
fun TwoColumnsLayout() {
Row(Modifier.fillMaxSize()) {
Box(modifier = Modifier.fillMaxWidth(0.4f), contentAlignment = Alignment.Center) {
LeftPaneContent()
Divider(
color = Color.Blue,
modifier = Modifier
.fillMaxHeight()
.width(1.dp)
)
}
RightPaneContent()
}
}
@Composable
fun LeftPaneContent() {
Column(
Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "Left Pane First Text Box")
Text(text = "Left Pane Second Text Box")
Column {
Text(text = "Left Pane Radio button Box ", modifier = Modifier.padding(start = 8.dp))
val options = listOf("Option 1", "Option 2", "Option 3", "Option 4", "Option 5")
}
Text(text = "Left Pane bottom Text Box")
}
}
@Composable
fun RightPaneContent() {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Column(
Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = "Right Pane First Text Box")
Text(text = "Right Pane Second Text Box")
Text(text = "Right Pane Third Text Box")
}
}
}
fun main() = application {
Window(
onCloseRequest = ::exitApplication,
state = WindowState(size = DpSize(1440.dp, 768.dp))
) {
App()
}
}
I do not need the complete code.
I just need help with the view placement, alignment and sizing as per the above design.
I am unable to create a UI layout as shown in above image and also there are no documentation around Compose For Desktop UI Layout.