Colton Idle
03/02/2025, 5:20 AMChris Sinco [G]
03/02/2025, 7:30 PMPau Marzo
03/02/2025, 8:53 PMval state = rememberWindowState(
size = DpSize(Dp.Unspecified, Dp.Unspecified)
)
i think this sets initial value of size to the content, it does not update it if changes afterwards thoughColton Idle
03/03/2025, 1:25 PMAlexander Maryanovsky
03/03/2025, 2:57 PMColton Idle
03/03/2025, 3:21 PMColton Idle
03/03/2025, 3:58 PMAlexander Maryanovsky
03/03/2025, 4:00 PMColton Idle
03/03/2025, 4:45 PMAlexander Maryanovsky
03/03/2025, 5:21 PMColton Idle
03/03/2025, 5:22 PMColton Idle
03/03/2025, 5:23 PMAlexander Maryanovsky
03/03/2025, 5:24 PMColton Idle
03/03/2025, 5:29 PMAlexander Maryanovsky
03/03/2025, 5:30 PMColton Idle
03/03/2025, 5:32 PMColton Idle
03/03/2025, 5:43 PMChris Sinco [G]
03/03/2025, 8:50 PMColton Idle
03/03/2025, 8:55 PMColton Idle
03/04/2025, 12:11 AMAlexander Maryanovsky
03/04/2025, 9:03 AMimport androidx.compose.animation.core.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.*
import androidx.compose.ui.unit.*
import androidx.compose.ui.window.*
fun main() = application {
val windowState = rememberWindowState(size = DpSize(Dp.Unspecified, Dp.Unspecified))
Window(
onCloseRequest = ::exitApplication,
state = windowState,
resizable = false,
) {
var tabIndex by remember { mutableIntStateOf(0) }
LaunchedEffect(tabIndex) {
val prefSize = window.preferredSize.let {
DpSize(it.width.dp, it.height.dp)
}
// Optional animation; can just assign windowState.size immediately instead
val animation = Animatable(
initialValue = windowState.size,
typeConverter = DpSizeConverter
)
animation.animateTo(prefSize) {
windowState.size = value
}
}
Column(
modifier = Modifier.width(IntrinsicSize.Max),
horizontalAlignment = Alignment.CenterHorizontally
) {
Row(
modifier = Modifier.fillMaxWidth().padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Button(onClick = { tabIndex = 0 }) { Text("Small Tab")}
Spacer(Modifier.width(16.dp))
Button(onClick = { tabIndex = 1 }) { Text("Large Tab")}
}
when (tabIndex) {
0 -> {
Box(Modifier.size(400.dp, 400.dp), contentAlignment = Alignment.Center) {
Text("Small Tab Content")
}
}
1 -> {
Box(Modifier.size(400.dp, 800.dp), contentAlignment = Alignment.Center) {
Text("Large Tab Content")
}
}
}
}
}
}
private val DpSizeConverter = TwoWayConverter<DpSize, AnimationVector2D>(
convertToVector = { AnimationVector2D(it.width.value, it.height.value) },
convertFromVector = { DpSize(it.v1.dp, it.v2.dp) }
)
Alexander Maryanovsky
03/04/2025, 9:04 AMAlexander Maryanovsky
03/04/2025, 9:05 AMColton Idle
03/04/2025, 1:47 PMwindowState.size
even when resizable = false.
Adding this one to my "Window tricks" doc. lol thank you!Colton Idle
03/04/2025, 1:48 PMMarcin Wisniowski
03/04/2025, 3:31 PMChris Sinco [G]
03/04/2025, 4:01 PM