Trejkaz
08/11/2024, 9:21 AMTrejkaz
08/11/2024, 10:07 AMimport androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Switch
import androidx.compose.material.Text
import androidx.compose.material.darkColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
class Settings {
val doTheThing = mutableStateOf(false)
val reallyDoTheThing = mutableStateOf(false)
}
@Composable
fun SwitchRow(
state: MutableState<Boolean>,
label: String,
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Switch(checked = state.value, onCheckedChange = { state.value = it })
Text(text = label)
}
}
fun main() = application {
val settings = remember { Settings() }
val windowState = rememberWindowState(size = DpSize.Unspecified)
LaunchedEffect(settings.doTheThing.value) {
windowState.size = DpSize.Unspecified
}
Window(
state = windowState,
onCloseRequest = ::exitApplication,
) {
MaterialTheme(colors = darkColors()) {
Surface {
Column(
modifier = Modifier.padding(16.dp)
) {
SwitchRow(settings.doTheThing, "Do the thing")
if (settings.doTheThing.value) {
SwitchRow(settings.reallyDoTheThing, "Really do the thing")
}
}
}
}
}
}
Trejkaz
08/11/2024, 10:09 AMTrejkaz
08/11/2024, 10:11 AMTrejkaz
08/11/2024, 10:13 AM