|
1 | 1 | package com.enaboapps.switchify.screens.pc |
2 | 2 |
|
3 | 3 | import androidx.annotation.StringRes |
| 4 | +import androidx.compose.foundation.BorderStroke |
| 5 | +import androidx.compose.foundation.clickable |
| 6 | +import androidx.compose.foundation.interaction.MutableInteractionSource |
| 7 | +import androidx.compose.foundation.interaction.collectIsPressedAsState |
4 | 8 | import androidx.compose.foundation.layout.Arrangement |
| 9 | +import androidx.compose.foundation.layout.Box |
5 | 10 | import androidx.compose.foundation.layout.Column |
| 11 | +import androidx.compose.foundation.layout.aspectRatio |
| 12 | +import androidx.compose.foundation.layout.fillMaxSize |
6 | 13 | import androidx.compose.foundation.layout.fillMaxWidth |
7 | 14 | import androidx.compose.foundation.layout.heightIn |
| 15 | +import androidx.compose.foundation.layout.padding |
8 | 16 | import androidx.compose.foundation.layout.Row |
9 | 17 | import androidx.compose.foundation.layout.Spacer |
10 | | -import androidx.compose.material3.Button |
| 18 | +import androidx.compose.foundation.shape.RoundedCornerShape |
11 | 19 | import androidx.compose.material3.MaterialTheme |
12 | 20 | import androidx.compose.material3.SegmentedButton |
13 | 21 | import androidx.compose.material3.SegmentedButtonDefaults |
14 | 22 | import androidx.compose.material3.SingleChoiceSegmentedButtonRow |
| 23 | +import androidx.compose.material3.Surface |
15 | 24 | import androidx.compose.material3.Text |
16 | 25 | import androidx.compose.runtime.Composable |
| 26 | +import androidx.compose.runtime.getValue |
| 27 | +import androidx.compose.runtime.remember |
| 28 | +import androidx.compose.ui.Alignment |
17 | 29 | import androidx.compose.ui.Modifier |
18 | 30 | import androidx.compose.ui.res.stringResource |
| 31 | +import androidx.compose.ui.semantics.Role |
19 | 32 | import androidx.compose.ui.text.style.TextAlign |
| 33 | +import androidx.compose.ui.text.style.TextOverflow |
20 | 34 | import androidx.compose.ui.unit.dp |
21 | 35 | import com.enaboapps.switchify.R |
22 | 36 | import com.enaboapps.switchify.pc.PcMouseCommand |
@@ -219,17 +233,55 @@ private fun PcCommandButton( |
219 | 233 | minHeightDp: Int, |
220 | 234 | modifier: Modifier = Modifier |
221 | 235 | ) { |
222 | | - Button( |
223 | | - onClick = { onCommandSelected(spec.command) }, |
224 | | - enabled = connected, |
| 236 | + val interactionSource = remember { MutableInteractionSource() } |
| 237 | + val pressed by interactionSource.collectIsPressedAsState() |
| 238 | + val backgroundColor = when { |
| 239 | + !connected -> MaterialTheme.colorScheme.surfaceVariant |
| 240 | + pressed -> MaterialTheme.colorScheme.primaryContainer |
| 241 | + else -> MaterialTheme.colorScheme.surface |
| 242 | + } |
| 243 | + val borderColor = if (connected) { |
| 244 | + MaterialTheme.colorScheme.outline |
| 245 | + } else { |
| 246 | + MaterialTheme.colorScheme.outlineVariant |
| 247 | + } |
| 248 | + val contentColor = if (connected) { |
| 249 | + MaterialTheme.colorScheme.onSurface |
| 250 | + } else { |
| 251 | + MaterialTheme.colorScheme.onSurfaceVariant |
| 252 | + } |
| 253 | + |
| 254 | + Surface( |
225 | 255 | modifier = modifier |
226 | 256 | .fillMaxWidth() |
| 257 | + .aspectRatio(1f) |
227 | 258 | .heightIn(min = minHeightDp.dp) |
| 259 | + .clickable( |
| 260 | + enabled = connected, |
| 261 | + role = Role.Button, |
| 262 | + interactionSource = interactionSource, |
| 263 | + indication = null, |
| 264 | + onClick = { onCommandSelected(spec.command) } |
| 265 | + ), |
| 266 | + shape = RoundedCornerShape(8.dp), |
| 267 | + color = backgroundColor, |
| 268 | + border = BorderStroke(1.dp, borderColor) |
228 | 269 | ) { |
229 | | - Text( |
230 | | - text = stringResource(spec.labelResId), |
231 | | - textAlign = TextAlign.Center |
232 | | - ) |
| 270 | + Box( |
| 271 | + modifier = Modifier |
| 272 | + .fillMaxSize() |
| 273 | + .padding(8.dp), |
| 274 | + contentAlignment = Alignment.Center |
| 275 | + ) { |
| 276 | + Text( |
| 277 | + text = stringResource(spec.labelResId), |
| 278 | + style = MaterialTheme.typography.labelLarge, |
| 279 | + color = contentColor, |
| 280 | + textAlign = TextAlign.Center, |
| 281 | + maxLines = 2, |
| 282 | + overflow = TextOverflow.Ellipsis |
| 283 | + ) |
| 284 | + } |
233 | 285 | } |
234 | 286 | } |
235 | 287 |
|
|
0 commit comments