|
| 1 | +// SPDX-License-Identifier: GPL-3.0-only |
| 2 | +package helium314.keyboard.settings |
| 3 | + |
| 4 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 5 | +import androidx.compose.foundation.layout.padding |
| 6 | +import androidx.compose.material3.Icon |
| 7 | +import androidx.compose.material3.IconButton |
| 8 | +import androidx.compose.material3.MaterialTheme |
| 9 | +import androidx.compose.material3.OutlinedTextField |
| 10 | +import androidx.compose.material3.Text |
| 11 | +import androidx.compose.runtime.Composable |
| 12 | +import androidx.compose.runtime.getValue |
| 13 | +import androidx.compose.runtime.saveable.rememberSaveable |
| 14 | +import androidx.compose.runtime.setValue |
| 15 | +import androidx.compose.runtime.mutableStateOf |
| 16 | +import androidx.compose.ui.Modifier |
| 17 | +import androidx.compose.ui.res.painterResource |
| 18 | +import androidx.compose.ui.res.stringResource |
| 19 | +import androidx.compose.ui.unit.dp |
| 20 | +import helium314.keyboard.latin.R |
| 21 | + |
| 22 | +/** |
| 23 | + * Text field to try the keyboard directly in the settings, e.g. to see a changed theme |
| 24 | + * or key size without leaving the settings. |
| 25 | + */ |
| 26 | +@Composable |
| 27 | +fun KeyboardTestField(modifier: Modifier = Modifier) { |
| 28 | + var text by rememberSaveable { mutableStateOf("") } |
| 29 | + OutlinedTextField( |
| 30 | + value = text, |
| 31 | + onValueChange = { text = it }, |
| 32 | + label = { Text(stringResource(R.string.keyboard_test_field)) }, |
| 33 | + supportingText = { Text(stringResource(R.string.keyboard_test_field_hint)) }, |
| 34 | + trailingIcon = if (text.isEmpty()) null else { |
| 35 | + { |
| 36 | + IconButton(onClick = { text = "" }) { |
| 37 | + Icon(painterResource(R.drawable.ic_close), stringResource(R.string.delete)) |
| 38 | + } |
| 39 | + } |
| 40 | + }, |
| 41 | + textStyle = contentTextDirectionStyle.merge(MaterialTheme.typography.bodyLarge), |
| 42 | + maxLines = 3, |
| 43 | + modifier = modifier |
| 44 | + .fillMaxWidth() |
| 45 | + .padding(horizontal = 16.dp, vertical = 4.dp) |
| 46 | + ) |
| 47 | +} |
0 commit comments