diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/TestA11Y.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/TestA11Y.kt new file mode 100644 index 0000000000000000000000000000000000000000..bf5022ccb3fa9cb41fef8a1f04725b5da4d115a7 --- /dev/null +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/TestA11Y.kt @@ -0,0 +1,72 @@ +/* + * Briar Desktop + * Copyright (C) 2021-2022 The Briar Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package org.briarproject.briar.desktop + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding +import androidx.compose.material.Button +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.compose.ui.window.WindowState +import androidx.compose.ui.window.singleWindowApplication + +fun main() = singleWindowApplication( + title = "Accessible Buttons", state = WindowState(size = DpSize(800.dp, 600.dp)) +) { + Column { + ButtonRow("Some label:") + ButtonRow("Another label:") + } +} + +@Composable +fun ButtonRow(label: String) { + var count by remember { mutableStateOf(0) } + Row(verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.semantics(mergeDescendants = true) { + contentDescription = "Click to increment value" + }) { + Text(label, modifier = Modifier.padding(start = 16.dp, end = 8.dp)) + Button( + onClick = { count += 1 }, + modifier = Modifier.background(Color.LightGray).semantics { contentDescription = "foo" } + ) { + val text = when (count) { + 0 -> "Click Me!" + 1 -> "Clicked" + else -> "Clicked $count times" + } + Text(text, fontSize = 24.sp) + } + } +} \ No newline at end of file