fix: ограничил подсветку кнопок только операторами

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Heller
2026-06-18 23:53:41 +00:00
parent babec55122
commit cf35982b37
2 changed files with 52 additions and 20 deletions

View File

@@ -152,7 +152,8 @@ private fun ButtonGrid(
label = label,
type = type,
onClick = { handleButtonClick(label, viewModel) },
isSelected = labelToOperation(label) == pendingOperation,
isSelected = type == CalculatorButtonType.Operator &&
labelToOperation(label) == pendingOperation,
modifier = Modifier
.weight(weight)
.aspectRatio(if (label == "0") 2.15f else 1f),

View File

@@ -1,16 +1,21 @@
package com.heller.calculator.ui.components
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@@ -29,8 +34,11 @@ fun CalculatorButton(
modifier: Modifier = Modifier,
isSelected: Boolean = false,
) {
val showSelected = isSelected && type == CalculatorButtonType.Operator
val shape = RoundedCornerShape(24.dp)
val containerColor = when {
isSelected -> MaterialTheme.colorScheme.primary
showSelected -> MaterialTheme.colorScheme.primary
type == CalculatorButtonType.Digit -> MaterialTheme.colorScheme.surfaceVariant
type == CalculatorButtonType.Operator -> MaterialTheme.colorScheme.primaryContainer
type == CalculatorButtonType.Equals -> MaterialTheme.colorScheme.primary
@@ -38,30 +46,14 @@ fun CalculatorButton(
}
val contentColor = when {
isSelected -> MaterialTheme.colorScheme.onPrimary
showSelected -> MaterialTheme.colorScheme.onPrimary
type == CalculatorButtonType.Digit -> MaterialTheme.colorScheme.onSurfaceVariant
type == CalculatorButtonType.Operator -> MaterialTheme.colorScheme.onPrimaryContainer
type == CalculatorButtonType.Equals -> MaterialTheme.colorScheme.onPrimary
else -> MaterialTheme.colorScheme.onErrorContainer
}
Button(
onClick = onClick,
modifier = modifier,
shape = RoundedCornerShape(24.dp),
colors = ButtonDefaults.buttonColors(
containerColor = containerColor,
contentColor = contentColor,
),
border = if (isSelected) {
BorderStroke(2.dp, MaterialTheme.colorScheme.onPrimary)
} else {
null
},
elevation = ButtonDefaults.buttonElevation(
defaultElevation = if (isSelected) 6.dp else 2.dp,
),
) {
val labelContent = @Composable {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center,
@@ -70,7 +62,46 @@ fun CalculatorButton(
text = label,
fontSize = 24.sp,
style = MaterialTheme.typography.bodyLarge,
color = contentColor,
)
}
}
if (type == CalculatorButtonType.Digit) {
Surface(
modifier = modifier
.clip(shape)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onClick = onClick,
),
shape = shape,
color = containerColor,
shadowElevation = 2.dp,
) {
labelContent()
}
return
}
Button(
onClick = onClick,
modifier = modifier,
shape = shape,
colors = ButtonDefaults.buttonColors(
containerColor = containerColor,
contentColor = contentColor,
),
border = if (showSelected) {
BorderStroke(2.dp, MaterialTheme.colorScheme.onPrimary)
} else {
null
},
elevation = ButtonDefaults.buttonElevation(
defaultElevation = if (showSelected) 6.dp else 2.dp,
),
) {
labelContent()
}
}