Trejkaz
07/26/2024, 2:56 AMModifier.requiredSize
would be more aggressive with forcing the size I passed in, but it looks like the size of the containing component matters more? 🤔Trejkaz
07/26/2024, 2:56 AMimport androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.darkColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.singleWindowApplication
@Composable
fun SquareCell(
text: String,
size: Dp = 150.dp,
borderWidth: Dp,
) {
OutlinedButton(
shape = RectangleShape,
border = BorderStroke(borderWidth, Color.Blue),
onClick = {},
contentPadding = PaddingValues(0.dp),
modifier = Modifier
.wrapContentSize()
) {
val fontHeight = size * (2.0f / 3.0f)
val fontSize = with(LocalDensity.current) { fontHeight.toSp() }
Text(
text = text,
fontSize = fontSize,
textAlign = TextAlign.Center,
modifier = Modifier
.requiredSize(size = size)
)
}
}
fun main() = singleWindowApplication {
MaterialTheme(colorScheme = darkColorScheme()) {
Surface {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
SquareCell(text = "a", borderWidth = 0.dp)
SquareCell(text = "a", borderWidth = 1.dp)
SquareCell(text = "a", borderWidth = 10.dp)
SquareCell(text = "a", borderWidth = 20.dp)
SquareCell(text = "a", borderWidth = 40.dp)
}
}
}
}
Trejkaz
07/26/2024, 2:57 AMTrejkaz
07/26/2024, 2:59 AMTrejkaz
07/26/2024, 3:00 AMTrejkaz
07/26/2024, 3:01 AMephemient
07/26/2024, 3:03 AMephemient
07/26/2024, 3:05 AMTrejkaz
07/26/2024, 3:06 AMTrejkaz
07/26/2024, 3:06 AMephemient
07/26/2024, 3:07 AMTrejkaz
07/26/2024, 3:07 AMTrejkaz
07/26/2024, 3:07 AMTrejkaz
07/26/2024, 3:07 AMTrejkaz
07/26/2024, 3:07 AMTrejkaz
07/26/2024, 3:08 AMTrejkaz
07/26/2024, 3:09 AMTrejkaz
07/26/2024, 4:13 AMTrejkaz
07/26/2024, 4:14 AMTrejkaz
07/26/2024, 4:14 AMTrejkaz
07/26/2024, 4:14 AMTrejkaz
07/26/2024, 4:15 AMTrejkaz
07/26/2024, 4:16 AMTrejkaz
07/26/2024, 4:17 AMTrejkaz
07/26/2024, 4:17 AMTrejkaz
07/26/2024, 4:54 AMTrejkaz
07/26/2024, 4:55 AMTrejkaz
07/26/2024, 4:56 AMTrejkaz
07/26/2024, 4:56 AM