Call Mr. Clean to clean up Calculator module

This commit is contained in:
Sad Ellie 2024-02-14 21:58:11 +03:00
parent e5696173f4
commit 51700687a2
7 changed files with 299 additions and 387 deletions

View File

@ -126,6 +126,8 @@ fun TextFieldValue.deleteTokens(): TextFieldValue {
) )
} }
fun TextFieldValue.placeCursorAtTheEnd(): TextFieldValue = copy(selection = TextRange(text.length))
/** /**
* Tries to get a [TextFieldValue]. Places cursor at the end. * Tries to get a [TextFieldValue]. Places cursor at the end.
* *

View File

@ -38,30 +38,9 @@ class CalculatorScreenTest {
val composeTestRule = createAndroidComposeRule<ComponentActivity>() val composeTestRule = createAndroidComposeRule<ComponentActivity>()
@Test @Test
fun loading_showLoadingKeyboard(): Unit = with(composeTestRule) { fun ready(): Unit = with(composeTestRule) {
setContent { setContent {
CalculatorScreen( Ready(
uiState = CalculatorUIState.Loading,
openDrawer = {},
addTokens = {},
addBracket = {},
clearInput = {},
deleteTokens = {},
onValueChange = {},
toggleCalculatorMode = {},
equal = {},
clearHistory = {},
onDelete = {},
)
}
onNodeWithTag("loading").assertExists()
}
@Test
fun ready_showRealKeyboard(): Unit = with(composeTestRule) {
setContent {
CalculatorScreen(
uiState = CalculatorUIState.Ready( uiState = CalculatorUIState.Ready(
input = TextFieldValue(), input = TextFieldValue(),
output = CalculationResult.Empty, output = CalculationResult.Empty,
@ -75,16 +54,15 @@ class CalculatorScreenTest {
partialHistoryView = true partialHistoryView = true
), ),
openDrawer = {}, openDrawer = {},
addTokens = {}, onInputChange = {},
addBracket = {}, onAddTokenClick = {},
clearInput = {}, onBracketsClick = {},
deleteTokens = {}, onDeleteClick = {},
onValueChange = {}, onClearClick = {},
toggleCalculatorMode = {}, onEqualClick = {},
equal = {}, onAngleClick = {},
clearHistory = {}, onClearHistoryClick = {},
onDelete = {}, ) {}
)
} }
onNodeWithTag("loading").assertDoesNotExist() onNodeWithTag("loading").assertDoesNotExist()
@ -94,7 +72,7 @@ class CalculatorScreenTest {
@Test @Test
fun ready_swipeForHistory(): Unit = with(composeTestRule) { fun ready_swipeForHistory(): Unit = with(composeTestRule) {
setContent { setContent {
CalculatorScreen( Ready(
uiState = CalculatorUIState.Ready( uiState = CalculatorUIState.Ready(
input = TextFieldValue(), input = TextFieldValue(),
output = CalculationResult.Empty, output = CalculationResult.Empty,
@ -108,16 +86,15 @@ class CalculatorScreenTest {
partialHistoryView = true partialHistoryView = true
), ),
openDrawer = {}, openDrawer = {},
addTokens = {}, onInputChange = {},
addBracket = {}, onAddTokenClick = {},
clearInput = {}, onBracketsClick = {},
deleteTokens = {}, onDeleteClick = {},
onValueChange = {}, onClearClick = {},
toggleCalculatorMode = {}, onEqualClick = {},
equal = {}, onAngleClick = {},
clearHistory = {}, onClearHistoryClick = {},
onDelete = {}, ) {}
)
} }
onNodeWithTag("inputBox") onNodeWithTag("inputBox")

View File

@ -86,68 +86,37 @@ internal fun CalculatorRoute(
openDrawer: () -> Unit, openDrawer: () -> Unit,
viewModel: CalculatorViewModel = hiltViewModel(), viewModel: CalculatorViewModel = hiltViewModel(),
) { ) {
val uiState = viewModel.uiState.collectAsStateWithLifecycle() when (val uiState = viewModel.uiState.collectAsStateWithLifecycle().value) {
CalculatorUIState.Loading -> EmptyScreen()
CalculatorScreen(
uiState = uiState.value,
openDrawer = openDrawer,
addTokens = viewModel::addTokens,
addBracket = viewModel::addBracket,
clearInput = viewModel::clearInput,
deleteTokens = viewModel::deleteTokens,
onValueChange = viewModel::updateInput,
toggleCalculatorMode = viewModel::updateRadianMode,
equal = viewModel::equal,
clearHistory = viewModel::clearHistory,
onDelete = viewModel::deleteHistoryItem,
)
}
@Composable
internal fun CalculatorScreen(
uiState: CalculatorUIState,
openDrawer: () -> Unit,
addTokens: (String) -> Unit,
addBracket: () -> Unit,
clearInput: () -> Unit,
deleteTokens: () -> Unit,
onValueChange: (TextFieldValue) -> Unit,
toggleCalculatorMode: (Boolean) -> Unit,
equal: () -> Unit,
clearHistory: () -> Unit,
onDelete: (HistoryItem) -> Unit,
) {
when (uiState) {
is CalculatorUIState.Loading -> EmptyScreen()
is CalculatorUIState.Ready -> Ready( is CalculatorUIState.Ready -> Ready(
uiState = uiState, uiState = uiState,
openDrawer = openDrawer, openDrawer = openDrawer,
addSymbol = addTokens, onInputChange = viewModel::updateInput,
addBracket = addBracket, onAddTokenClick = viewModel::addTokens,
clearSymbols = clearInput, onBracketsClick = viewModel::addBracket,
deleteSymbol = deleteTokens, onDeleteClick = viewModel::deleteTokens,
onValueChange = onValueChange, onClearClick = viewModel::clearInput,
toggleAngleMode = { toggleCalculatorMode(!uiState.radianMode) }, onEqualClick = viewModel::equal,
equal = equal, onAngleClick = viewModel::updateRadianMode,
clearHistory = clearHistory, onClearHistoryClick = viewModel::clearHistory,
onDelete = onDelete, onDeleteHistoryItemClick = viewModel::deleteHistoryItem,
) )
} }
} }
@Composable @Composable
private fun Ready( internal fun Ready(
uiState: CalculatorUIState.Ready, uiState: CalculatorUIState.Ready,
openDrawer: () -> Unit, openDrawer: () -> Unit,
addSymbol: (String) -> Unit, onInputChange: (TextFieldValue) -> Unit,
addBracket: () -> Unit, onAddTokenClick: (String) -> Unit,
clearSymbols: () -> Unit, onBracketsClick: () -> Unit,
deleteSymbol: () -> Unit, onDeleteClick: () -> Unit,
onValueChange: (TextFieldValue) -> Unit, onClearClick: () -> Unit,
toggleAngleMode: () -> Unit, onEqualClick: () -> Unit,
equal: () -> Unit, onAngleClick: (Boolean) -> Unit,
clearHistory: () -> Unit, onClearHistoryClick: () -> Unit,
onDelete: (HistoryItem) -> Unit, onDeleteHistoryItemClick: (HistoryItem) -> Unit,
) { ) {
val focusManager = LocalFocusManager.current val focusManager = LocalFocusManager.current
var showClearHistoryDialog by rememberSaveable { mutableStateOf(false) } var showClearHistoryDialog by rememberSaveable { mutableStateOf(false) }
@ -240,8 +209,8 @@ private fun Ready(
.height(historyListHeight), .height(historyListHeight),
historyItems = uiState.history, historyItems = uiState.history,
formatterSymbols = uiState.formatterSymbols, formatterSymbols = uiState.formatterSymbols,
addTokens = addSymbol, addTokens = onAddTokenClick,
onDelete = onDelete, onDelete = onDeleteHistoryItemClick,
showDeleteButtons = isOpen showDeleteButtons = isOpen
) )
@ -256,7 +225,7 @@ private fun Ready(
), ),
formatterSymbols = uiState.formatterSymbols, formatterSymbols = uiState.formatterSymbols,
input = uiState.input, input = uiState.input,
onValueChange = onValueChange, onValueChange = onInputChange,
output = uiState.output output = uiState.output
) )
@ -274,16 +243,16 @@ private fun Ready(
.height(keyboardHeight) .height(keyboardHeight)
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 8.dp, vertical = 4.dp), .padding(horizontal = 8.dp, vertical = 4.dp),
onAddTokenClick = onAddTokenClick,
onBracketsClick = onBracketsClick,
onDeleteClick = onDeleteClick,
onClearClick = onClearClick,
onEqualClick = { focusManager.clearFocus(); onEqualClick() },
onAngleClick = onAngleClick,
radianMode = uiState.radianMode, radianMode = uiState.radianMode,
fractional = uiState.formatterSymbols.fractional, showAcButton = uiState.acButton,
addSymbol = addSymbol,
clearSymbols = clearSymbols,
deleteSymbol = deleteSymbol,
toggleAngleMode = toggleAngleMode,
equal = { focusManager.clearFocus(); equal() },
middleZero = uiState.middleZero, middleZero = uiState.middleZero,
acButton = uiState.acButton, fractional = uiState.formatterSymbols.fractional,
addBracket = addBracket
) )
} }
} }
@ -302,7 +271,7 @@ private fun Ready(
confirmButton = { confirmButton = {
TextButton( TextButton(
onClick = { onClick = {
clearHistory() onClearHistoryClick()
showClearHistoryDialog = false showClearHistoryDialog = false
} }
) { ) {
@ -349,7 +318,7 @@ private fun PreviewCalculatorScreen() {
) )
} }
CalculatorScreen( Ready(
uiState = CalculatorUIState.Ready( uiState = CalculatorUIState.Ready(
input = TextFieldValue("1.2345"), input = TextFieldValue("1.2345"),
output = CalculationResult.Default("1234"), output = CalculationResult.Default("1234"),
@ -363,14 +332,13 @@ private fun PreviewCalculatorScreen() {
partialHistoryView = true partialHistoryView = true
), ),
openDrawer = {}, openDrawer = {},
addTokens = {}, onInputChange = {},
addBracket = {}, onAddTokenClick = {},
clearInput = {}, onBracketsClick = {},
deleteTokens = {}, onDeleteClick = {},
onValueChange = {}, onClearClick = {},
toggleCalculatorMode = {}, onEqualClick = {},
equal = {}, onAngleClick = {},
clearHistory = {}, onClearHistoryClick = {},
onDelete = {}, ) {}
)
} }

View File

@ -18,10 +18,8 @@
package com.sadellie.unitto.feature.calculator package com.sadellie.unitto.feature.calculator
import androidx.annotation.StringRes
import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.input.TextFieldValue
import com.sadellie.unitto.core.base.FormatterSymbols import com.sadellie.unitto.core.base.FormatterSymbols
import com.sadellie.unitto.core.base.R
import com.sadellie.unitto.data.model.HistoryItem import com.sadellie.unitto.data.model.HistoryItem
internal sealed class CalculatorUIState { internal sealed class CalculatorUIState {
@ -48,13 +46,7 @@ sealed class CalculationResult {
data object Empty : CalculationResult() data object Empty : CalculationResult()
data object DivideByZeroError : CalculationResult() { data object DivideByZeroError : CalculationResult()
@StringRes
val label: Int = R.string.calculator_divide_by_zero_error
}
data object Error : CalculationResult() { data object Error : CalculationResult()
@StringRes
val label: Int = R.string.error_label
}
} }

View File

@ -28,6 +28,7 @@ import com.sadellie.unitto.core.ui.common.textfield.addBracket
import com.sadellie.unitto.core.ui.common.textfield.addTokens import com.sadellie.unitto.core.ui.common.textfield.addTokens
import com.sadellie.unitto.core.ui.common.textfield.deleteTokens import com.sadellie.unitto.core.ui.common.textfield.deleteTokens
import com.sadellie.unitto.core.ui.common.textfield.getTextField import com.sadellie.unitto.core.ui.common.textfield.getTextField
import com.sadellie.unitto.core.ui.common.textfield.placeCursorAtTheEnd
import com.sadellie.unitto.data.common.format import com.sadellie.unitto.data.common.format
import com.sadellie.unitto.data.common.isExpression import com.sadellie.unitto.data.common.isExpression
import com.sadellie.unitto.data.common.stateIn import com.sadellie.unitto.data.common.stateIn
@ -114,62 +115,43 @@ internal class CalculatorViewModel @Inject constructor(
} }
.stateIn(viewModelScope, CalculatorUIState.Loading) .stateIn(viewModelScope, CalculatorUIState.Loading)
fun addTokens(tokens: String) = _input.update { fun addTokens(tokens: String) {
val isClearInputNeeded = _equalClicked.value and Token.Digit.allWithDot.contains(tokens) val isClearInputNeeded = _equalClicked.value and Token.Digit.allWithDot.contains(tokens)
val newValue = when {
var newValue = when {
// Clean input after clicking "=" and any token that is a Digit // Clean input after clicking "=" and any token that is a Digit
isClearInputNeeded -> TextFieldValue() isClearInputNeeded -> TextFieldValue()
_equalClicked.value -> it.copy(selection = TextRange(it.text.length)) _equalClicked.value -> _input.value.placeCursorAtTheEnd()
else -> it else -> _input.value
} }.addTokens(tokens)
newValue = newValue.addTokens(tokens) updateInput(newValue)
_equalClicked.update { false }
_fractionJob?.cancel()
savedStateHandle[_inputKey] = newValue.text
newValue
} }
fun addBracket() = _input.update { fun addBracket() {
var newValue = if (_equalClicked.value) { val newValue = if (_equalClicked.value) {
// Cursor is set to 0 when equal is clicked // Cursor is set to 0 when equal is clicked
it.copy(selection = TextRange(it.text.length)) _input.value.placeCursorAtTheEnd()
} else { } else {
it _input.value
} }.addBracket()
newValue = newValue.addBracket() updateInput(newValue)
_equalClicked.update { false }
_fractionJob?.cancel()
savedStateHandle[_inputKey] = newValue.text
newValue
} }
fun deleteTokens() = _input.update { fun deleteTokens() {
val newValue = if (_equalClicked.value) { val newValue = if (_equalClicked.value) {
TextFieldValue() TextFieldValue()
} else { } else {
it.deleteTokens() _input.value.deleteTokens()
} }
_equalClicked.update { false } updateInput(newValue)
_fractionJob?.cancel()
savedStateHandle[_inputKey] = newValue.text
newValue
} }
fun clearInput() = _input.update { fun clearInput() = updateInput(TextFieldValue())
_equalClicked.update { false }
_fractionJob?.cancel()
savedStateHandle[_inputKey] = ""
TextFieldValue()
}
fun updateInput(value: TextFieldValue) = _input.update { fun updateInput(value: TextFieldValue) {
// Without this line: will place token (even in the middle of the input) and place cursor at _fractionJob?.cancel()
// the end. This line also removes fractional output once user touches input text field
_equalClicked.update { false } _equalClicked.update { false }
value _input.update { value }
savedStateHandle[_inputKey] = value.text
} }
fun updateRadianMode(newValue: Boolean) = viewModelScope.launch { fun updateRadianMode(newValue: Boolean) = viewModelScope.launch {

View File

@ -114,50 +114,50 @@ import com.sadellie.unitto.core.ui.common.icons.iconpack.Tan
@Composable @Composable
internal fun CalculatorKeyboard( internal fun CalculatorKeyboard(
modifier: Modifier, modifier: Modifier,
onAddTokenClick: (String) -> Unit,
onBracketsClick: () -> Unit,
onDeleteClick: () -> Unit,
onClearClick: () -> Unit,
onEqualClick: () -> Unit,
onAngleClick: (Boolean) -> Unit,
radianMode: Boolean, radianMode: Boolean,
fractional: String, showAcButton: Boolean,
middleZero: Boolean, middleZero: Boolean,
acButton: Boolean, fractional: String,
addSymbol: (String) -> Unit,
addBracket: () -> Unit,
clearSymbols: () -> Unit,
deleteSymbol: () -> Unit,
toggleAngleMode: () -> Unit,
equal: () -> Unit
) { ) {
var invMode: Boolean by remember { mutableStateOf(false) } var showInvButtons: Boolean by remember { mutableStateOf(false) }
if (LocalWindowSize.current.heightSizeClass < WindowHeightSizeClass.Medium) { if (LocalWindowSize.current.heightSizeClass < WindowHeightSizeClass.Medium) {
LandscapeKeyboard( LandscapeKeyboard(
modifier = modifier, modifier = modifier,
onAddTokenClick = onAddTokenClick,
onBracketsClick = onBracketsClick,
onDeleteClick = onDeleteClick,
onClearClick = onClearClick,
onEqualClick = onEqualClick,
onInvClick = { showInvButtons = !showInvButtons },
onAngleClick = onAngleClick,
showInvButtons = showInvButtons,
radianMode = radianMode, radianMode = radianMode,
fractional = fractional, showAcButton = showAcButton,
middleZero = middleZero, middleZero = middleZero,
addSymbol = addSymbol, fractional = fractional,
toggleAngleMode = toggleAngleMode,
deleteSymbol = deleteSymbol,
clearSymbols = clearSymbols,
equal = equal,
acButton = acButton,
addBracket = addBracket,
invMode = invMode,
toggleInvMode = { invMode = !invMode },
) )
} else { } else {
PortraitKeyboard( PortraitKeyboard(
modifier = modifier, modifier = modifier,
onAddTokenClick = onAddTokenClick,
onBracketsClick = onBracketsClick,
onDeleteClick = onDeleteClick,
onClearClick = onClearClick,
onEqualClick = onEqualClick,
onInvClick = { showInvButtons = !showInvButtons },
onAngleClick = onAngleClick,
showInvButtons = showInvButtons,
radianMode = radianMode, radianMode = radianMode,
fractional = fractional, showAcButton = showAcButton,
middleZero = middleZero, middleZero = middleZero,
addSymbol = addSymbol, fractional = fractional,
toggleAngleMode = toggleAngleMode,
deleteSymbol = deleteSymbol,
clearSymbols = clearSymbols,
equal = equal,
acButton = acButton,
addBracket = addBracket,
invMode = invMode,
toggleInvMode = { invMode = !invMode },
) )
} }
} }
@ -165,18 +165,18 @@ internal fun CalculatorKeyboard(
@Composable @Composable
private fun PortraitKeyboard( private fun PortraitKeyboard(
modifier: Modifier, modifier: Modifier,
onAddTokenClick: (String) -> Unit,
onBracketsClick: () -> Unit,
onDeleteClick: () -> Unit,
onClearClick: () -> Unit,
onEqualClick: () -> Unit,
onInvClick: () -> Unit,
onAngleClick: (Boolean) -> Unit,
showInvButtons: Boolean,
radianMode: Boolean, radianMode: Boolean,
fractional: String, showAcButton: Boolean,
middleZero: Boolean, middleZero: Boolean,
addSymbol: (String) -> Unit, fractional: String,
toggleAngleMode: () -> Unit,
deleteSymbol: () -> Unit,
clearSymbols: () -> Unit,
equal: () -> Unit,
acButton: Boolean,
addBracket: () -> Unit,
invMode: Boolean,
toggleInvMode: () -> Unit,
) { ) {
val angleIcon = remember(radianMode) { if (radianMode) IconPack.Rad else IconPack.Deg } val angleIcon = remember(radianMode) { if (radianMode) IconPack.Rad else IconPack.Deg }
val angleIconDescription = remember(radianMode) { if (radianMode) R.string.keyboard_radian else R.string.keyboard_degree } val angleIconDescription = remember(radianMode) { if (radianMode) R.string.keyboard_radian else R.string.keyboard_degree }
@ -205,7 +205,7 @@ private fun PortraitKeyboard(
horizontalArrangement = Arrangement.Start horizontalArrangement = Arrangement.Start
) { ) {
Crossfade( Crossfade(
targetState = invMode, targetState = showInvButtons,
label = "Inverse switch", label = "Inverse switch",
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -217,21 +217,21 @@ private fun PortraitKeyboard(
showAdditional = showAdditional, showAdditional = showAdditional,
buttonHeight = additionalButtonHeight, buttonHeight = additionalButtonHeight,
content1 = { buttonModifier -> content1 = { buttonModifier ->
KeyboardButtonAdditional(buttonModifier, IconPack.Modulo, stringResource(R.string.keyboard_modulo), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Operator.modulo) } KeyboardButtonAdditional(buttonModifier, IconPack.Modulo, stringResource(R.string.keyboard_modulo), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Operator.modulo) }
KeyboardButtonAdditional(buttonModifier, IconPack.Pi, stringResource(R.string.keyboard_pi), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Const.pi) } KeyboardButtonAdditional(buttonModifier, IconPack.Pi, stringResource(R.string.keyboard_pi), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Const.pi) }
KeyboardButtonAdditional(buttonModifier, IconPack.Power, stringResource(R.string.keyboard_power), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Operator.power) } KeyboardButtonAdditional(buttonModifier, IconPack.Power, stringResource(R.string.keyboard_power), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Operator.power) }
KeyboardButtonAdditional(buttonModifier, IconPack.Factorial, stringResource(R.string.keyboard_factorial), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Operator.factorial) } KeyboardButtonAdditional(buttonModifier, IconPack.Factorial, stringResource(R.string.keyboard_factorial), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Operator.factorial) }
}, },
content2 = { buttonModifier -> content2 = { buttonModifier ->
KeyboardButtonAdditional(buttonModifier, angleIcon, stringResource(angleIconDescription), KeyboardButtonContentHeightTallAdditional) { toggleAngleMode() } KeyboardButtonAdditional(buttonModifier, angleIcon, stringResource(angleIconDescription), KeyboardButtonContentHeightTallAdditional) { onAngleClick(!radianMode) }
KeyboardButtonAdditional(buttonModifier, IconPack.ArSin, stringResource(R.string.keyboard_arsin), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Func.arsinBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.ArSin, stringResource(R.string.keyboard_arsin), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Func.arsinBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.ArCos, stringResource(R.string.keyboard_arcos), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Func.arcosBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.ArCos, stringResource(R.string.keyboard_arcos), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Func.arcosBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.AcTan, stringResource(R.string.keyboard_actan), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Func.actanBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.AcTan, stringResource(R.string.keyboard_actan), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Func.actanBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.Inv, stringResource(R.string.keyboard_inverse), KeyboardButtonContentHeightTallAdditional) { toggleInvMode() } KeyboardButtonAdditional(buttonModifier, IconPack.Inv, stringResource(R.string.keyboard_inverse), KeyboardButtonContentHeightTallAdditional) { onInvClick() }
KeyboardButtonAdditional(buttonModifier, IconPack.Euler, stringResource(R.string.keyboard_euler), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Const.e) } KeyboardButtonAdditional(buttonModifier, IconPack.Euler, stringResource(R.string.keyboard_euler), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Const.e) }
KeyboardButtonAdditional(buttonModifier, IconPack.Ex, stringResource(R.string.keyboard_exp), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Func.expBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Ex, stringResource(R.string.keyboard_exp), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Func.expBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.Power10, stringResource(R.string.keyboard_power_10), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Digit._1 + Token.Digit._0 + Token.Operator.power) } KeyboardButtonAdditional(buttonModifier, IconPack.Power10, stringResource(R.string.keyboard_power_10), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Digit._1 + Token.Digit._0 + Token.Operator.power) }
} }
) )
} else { } else {
@ -240,21 +240,21 @@ private fun PortraitKeyboard(
showAdditional = showAdditional, showAdditional = showAdditional,
buttonHeight = additionalButtonHeight, buttonHeight = additionalButtonHeight,
content1 = { buttonModifier -> content1 = { buttonModifier ->
KeyboardButtonAdditional(buttonModifier, IconPack.Root, stringResource(R.string.keyboard_root), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Operator.sqrt) } KeyboardButtonAdditional(buttonModifier, IconPack.Root, stringResource(R.string.keyboard_root), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Operator.sqrt) }
KeyboardButtonAdditional(buttonModifier, IconPack.Pi, stringResource(R.string.keyboard_pi), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Const.pi) } KeyboardButtonAdditional(buttonModifier, IconPack.Pi, stringResource(R.string.keyboard_pi), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Const.pi) }
KeyboardButtonAdditional(buttonModifier, IconPack.Power, stringResource(R.string.keyboard_power), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Operator.power) } KeyboardButtonAdditional(buttonModifier, IconPack.Power, stringResource(R.string.keyboard_power), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Operator.power) }
KeyboardButtonAdditional(buttonModifier, IconPack.Factorial, stringResource(R.string.keyboard_factorial), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Operator.factorial) } KeyboardButtonAdditional(buttonModifier, IconPack.Factorial, stringResource(R.string.keyboard_factorial), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Operator.factorial) }
}, },
content2 = { buttonModifier -> content2 = { buttonModifier ->
KeyboardButtonAdditional(buttonModifier, angleIcon, stringResource(angleIconDescription), KeyboardButtonContentHeightTallAdditional) { toggleAngleMode() } KeyboardButtonAdditional(buttonModifier, angleIcon, stringResource(angleIconDescription), KeyboardButtonContentHeightTallAdditional) { onAngleClick(!radianMode) }
KeyboardButtonAdditional(buttonModifier, IconPack.Sin, stringResource(R.string.keyboard_sin), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Func.sinBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Sin, stringResource(R.string.keyboard_sin), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Func.sinBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.Cos, stringResource(R.string.keyboard_cos), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Func.cosBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Cos, stringResource(R.string.keyboard_cos), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Func.cosBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.Tan, stringResource(R.string.keyboard_tan), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Func.tanBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Tan, stringResource(R.string.keyboard_tan), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Func.tanBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.Inv, stringResource(R.string.keyboard_inverse), KeyboardButtonContentHeightTallAdditional) { toggleInvMode() } KeyboardButtonAdditional(buttonModifier, IconPack.Inv, stringResource(R.string.keyboard_inverse), KeyboardButtonContentHeightTallAdditional) { onInvClick() }
KeyboardButtonAdditional(buttonModifier, IconPack.Euler, stringResource(R.string.keyboard_exp), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Const.e) } KeyboardButtonAdditional(buttonModifier, IconPack.Euler, stringResource(R.string.keyboard_exp), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Const.e) }
KeyboardButtonAdditional(buttonModifier, IconPack.Ln, stringResource(R.string.keyboard_ln), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Func.lnBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Ln, stringResource(R.string.keyboard_ln), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Func.lnBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.Log, stringResource(R.string.keyboard_log), KeyboardButtonContentHeightTallAdditional) { addSymbol(Token.Func.logBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Log, stringResource(R.string.keyboard_log), KeyboardButtonContentHeightTallAdditional) { onAddTokenClick(Token.Func.logBracket) }
} }
) )
} }
@ -286,40 +286,40 @@ private fun PortraitKeyboard(
.fillMaxWidth(width) .fillMaxWidth(width)
.fillMaxHeight(height) .fillMaxHeight(height)
if (acButton) { if (showAcButton) {
KeyboardButtonTertiary(mainButtonModifier, IconPack.Clear, stringResource(R.string.clear_label), KeyboardButtonContentHeightTall) { clearSymbols() } KeyboardButtonTertiary(mainButtonModifier, IconPack.Clear, stringResource(R.string.clear_label), KeyboardButtonContentHeightTall) { onClearClick() }
KeyboardButtonFilled(mainButtonModifier, IconPack.Brackets, stringResource(R.string.keyboard_brackets), KeyboardButtonContentHeightTall) { addBracket() } KeyboardButtonFilled(mainButtonModifier, IconPack.Brackets, stringResource(R.string.keyboard_brackets), KeyboardButtonContentHeightTall) { onBracketsClick() }
} else { } else {
KeyboardButtonFilled(mainButtonModifier, IconPack.LeftBracket, stringResource(R.string.keyboard_left_bracket), KeyboardButtonContentHeightTall) { addSymbol(Token.Operator.leftBracket) } KeyboardButtonFilled(mainButtonModifier, IconPack.LeftBracket, stringResource(R.string.keyboard_left_bracket), KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Operator.leftBracket) }
KeyboardButtonFilled(mainButtonModifier, IconPack.RightBracket, stringResource(R.string.keyboard_right_bracket), KeyboardButtonContentHeightTall) { addSymbol(Token.Operator.rightBracket) } KeyboardButtonFilled(mainButtonModifier, IconPack.RightBracket, stringResource(R.string.keyboard_right_bracket), KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Operator.rightBracket) }
} }
KeyboardButtonFilled(mainButtonModifier, IconPack.Percent, stringResource(R.string.keyboard_percent), KeyboardButtonContentHeightTall) { addSymbol(Token.Operator.percent) } KeyboardButtonFilled(mainButtonModifier, IconPack.Percent, stringResource(R.string.keyboard_percent), KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Operator.percent) }
KeyboardButtonFilled(mainButtonModifier, IconPack.Divide, stringResource(R.string.keyboard_divide), KeyboardButtonContentHeightTall) { addSymbol(Token.Operator.divide) } KeyboardButtonFilled(mainButtonModifier, IconPack.Divide, stringResource(R.string.keyboard_divide), KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Operator.divide) }
KeyboardButtonLight(mainButtonModifier, IconPack.Key7, Token.Digit._7, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._7) } KeyboardButtonLight(mainButtonModifier, IconPack.Key7, Token.Digit._7, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._7) }
KeyboardButtonLight(mainButtonModifier, IconPack.Key8, Token.Digit._8, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._8) } KeyboardButtonLight(mainButtonModifier, IconPack.Key8, Token.Digit._8, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._8) }
KeyboardButtonLight(mainButtonModifier, IconPack.Key9, Token.Digit._9, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._9) } KeyboardButtonLight(mainButtonModifier, IconPack.Key9, Token.Digit._9, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._9) }
KeyboardButtonFilled(mainButtonModifier, IconPack.Multiply, stringResource(R.string.keyboard_multiply), KeyboardButtonContentHeightTall) { addSymbol(Token.Operator.multiply) } KeyboardButtonFilled(mainButtonModifier, IconPack.Multiply, stringResource(R.string.keyboard_multiply), KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Operator.multiply) }
KeyboardButtonLight(mainButtonModifier, IconPack.Key4, Token.Digit._4, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._4) } KeyboardButtonLight(mainButtonModifier, IconPack.Key4, Token.Digit._4, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._4) }
KeyboardButtonLight(mainButtonModifier, IconPack.Key5, Token.Digit._5, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._5) } KeyboardButtonLight(mainButtonModifier, IconPack.Key5, Token.Digit._5, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._5) }
KeyboardButtonLight(mainButtonModifier, IconPack.Key6, Token.Digit._6, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._6) } KeyboardButtonLight(mainButtonModifier, IconPack.Key6, Token.Digit._6, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._6) }
KeyboardButtonFilled(mainButtonModifier, IconPack.Minus, stringResource(R.string.keyboard_minus), KeyboardButtonContentHeightTall) { addSymbol(Token.Operator.minus) } KeyboardButtonFilled(mainButtonModifier, IconPack.Minus, stringResource(R.string.keyboard_minus), KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Operator.minus) }
KeyboardButtonLight(mainButtonModifier, IconPack.Key1, Token.Digit._1, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._1) } KeyboardButtonLight(mainButtonModifier, IconPack.Key1, Token.Digit._1, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._1) }
KeyboardButtonLight(mainButtonModifier, IconPack.Key2, Token.Digit._2, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._2) } KeyboardButtonLight(mainButtonModifier, IconPack.Key2, Token.Digit._2, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._2) }
KeyboardButtonLight(mainButtonModifier, IconPack.Key3, Token.Digit._3, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._3) } KeyboardButtonLight(mainButtonModifier, IconPack.Key3, Token.Digit._3, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._3) }
KeyboardButtonFilled(mainButtonModifier, IconPack.Plus, stringResource(R.string.keyboard_plus), KeyboardButtonContentHeightTall) { addSymbol(Token.Operator.plus) } KeyboardButtonFilled(mainButtonModifier, IconPack.Plus, stringResource(R.string.keyboard_plus), KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Operator.plus) }
if (middleZero) { if (middleZero) {
KeyboardButtonLight(mainButtonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightTall) { addSymbol(Token.Digit.dot) } KeyboardButtonLight(mainButtonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit.dot) }
KeyboardButtonLight(mainButtonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._0) } KeyboardButtonLight(mainButtonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._0) }
} else { } else {
KeyboardButtonLight(mainButtonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightTall) { addSymbol(Token.Digit._0) } KeyboardButtonLight(mainButtonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit._0) }
KeyboardButtonLight(mainButtonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightTall) { addSymbol(Token.Digit.dot) } KeyboardButtonLight(mainButtonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightTall) { onAddTokenClick(Token.Digit.dot) }
} }
KeyboardButtonLight(mainButtonModifier, IconPack.Backspace, stringResource(R.string.delete_label), KeyboardButtonContentHeightTall, clearSymbols) { deleteSymbol() } KeyboardButtonLight(mainButtonModifier, IconPack.Backspace, stringResource(R.string.delete_label), KeyboardButtonContentHeightTall, onClearClick) { onDeleteClick() }
KeyboardButtonFilled(mainButtonModifier, IconPack.Equal, stringResource(R.string.keyboard_equal), KeyboardButtonContentHeightTall) { equal() } KeyboardButtonFilled(mainButtonModifier, IconPack.Equal, stringResource(R.string.keyboard_equal), KeyboardButtonContentHeightTall) { onEqualClick() }
} }
Spacer(modifier = Modifier.height(spacerHeight)) Spacer(modifier = Modifier.height(spacerHeight))
@ -397,18 +397,18 @@ private fun AdditionalPortrait(
@Composable @Composable
private fun LandscapeKeyboard( private fun LandscapeKeyboard(
modifier: Modifier, modifier: Modifier,
onAddTokenClick: (String) -> Unit,
onBracketsClick: () -> Unit,
onDeleteClick: () -> Unit,
onClearClick: () -> Unit,
onEqualClick: () -> Unit,
onInvClick: () -> Unit,
onAngleClick: (Boolean) -> Unit,
showInvButtons: Boolean,
radianMode: Boolean, radianMode: Boolean,
fractional: String, showAcButton: Boolean,
middleZero: Boolean, middleZero: Boolean,
addSymbol: (String) -> Unit, fractional: String,
toggleAngleMode: () -> Unit,
deleteSymbol: () -> Unit,
clearSymbols: () -> Unit,
equal: () -> Unit,
acButton: Boolean,
addBracket: () -> Unit,
invMode: Boolean,
toggleInvMode: () -> Unit,
) { ) {
val angleIcon = remember(radianMode) { if (radianMode) IconPack.Rad else IconPack.Deg } val angleIcon = remember(radianMode) { if (radianMode) IconPack.Rad else IconPack.Deg }
val angleIconDescription = remember(radianMode) { if (radianMode) R.string.keyboard_radian else R.string.keyboard_degree } val angleIconDescription = remember(radianMode) { if (radianMode) R.string.keyboard_radian else R.string.keyboard_degree }
@ -417,7 +417,7 @@ private fun LandscapeKeyboard(
val fractionalIconDescription = remember(fractional) { if (fractional == Token.PERIOD) R.string.keyboard_dot else R.string.comma } val fractionalIconDescription = remember(fractional) { if (fractional == Token.PERIOD) R.string.keyboard_dot else R.string.comma }
Crossfade( Crossfade(
targetState = invMode, targetState = showInvButtons,
label = "Inverse switch", label = "Inverse switch",
modifier = modifier modifier = modifier
) { inverse -> ) { inverse ->
@ -431,51 +431,51 @@ private fun LandscapeKeyboard(
.fillMaxWidth(width) .fillMaxWidth(width)
.fillMaxHeight(height) .fillMaxHeight(height)
KeyboardButtonAdditional(buttonModifier, angleIcon, stringResource(angleIconDescription), KeyboardButtonContentHeightShortAdditional) { toggleAngleMode() } KeyboardButtonAdditional(buttonModifier, angleIcon, stringResource(angleIconDescription), KeyboardButtonContentHeightShortAdditional) { onAngleClick(!radianMode) }
KeyboardButtonAdditional(buttonModifier, IconPack.Modulo, stringResource(R.string.keyboard_modulo), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Operator.modulo) } KeyboardButtonAdditional(buttonModifier, IconPack.Modulo, stringResource(R.string.keyboard_modulo), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Operator.modulo) }
KeyboardButtonAdditional(buttonModifier, IconPack.Pi, stringResource(R.string.keyboard_pi), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Const.pi) } KeyboardButtonAdditional(buttonModifier, IconPack.Pi, stringResource(R.string.keyboard_pi), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Const.pi) }
KeyboardButtonLight(buttonModifier, IconPack.Key7, Token.Digit._7, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._7) } KeyboardButtonLight(buttonModifier, IconPack.Key7, Token.Digit._7, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._7) }
KeyboardButtonLight(buttonModifier, IconPack.Key8, Token.Digit._8, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._8) } KeyboardButtonLight(buttonModifier, IconPack.Key8, Token.Digit._8, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._8) }
KeyboardButtonLight(buttonModifier, IconPack.Key9, Token.Digit._9, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._9) } KeyboardButtonLight(buttonModifier, IconPack.Key9, Token.Digit._9, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._9) }
if (acButton) { if (showAcButton) {
KeyboardButtonTertiary(buttonModifier, IconPack.Clear, stringResource(R.string.clear_label), KeyboardButtonContentHeightShort) { clearSymbols() } KeyboardButtonTertiary(buttonModifier, IconPack.Clear, stringResource(R.string.clear_label), KeyboardButtonContentHeightShort) { onClearClick() }
KeyboardButtonFilled(buttonModifier, IconPack.Brackets, stringResource(R.string.keyboard_brackets), KeyboardButtonContentHeightShort) { addBracket() } KeyboardButtonFilled(buttonModifier, IconPack.Brackets, stringResource(R.string.keyboard_brackets), KeyboardButtonContentHeightShort) { onBracketsClick() }
} else { } else {
KeyboardButtonFilled(buttonModifier, IconPack.LeftBracket, stringResource(R.string.keyboard_left_bracket), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.leftBracket) } KeyboardButtonFilled(buttonModifier, IconPack.LeftBracket, stringResource(R.string.keyboard_left_bracket), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.leftBracket) }
KeyboardButtonFilled(buttonModifier, IconPack.RightBracket, stringResource(R.string.keyboard_right_bracket), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.rightBracket) } KeyboardButtonFilled(buttonModifier, IconPack.RightBracket, stringResource(R.string.keyboard_right_bracket), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.rightBracket) }
} }
KeyboardButtonAdditional(buttonModifier, IconPack.Inv, stringResource(R.string.keyboard_inverse), KeyboardButtonContentHeightShortAdditional) { toggleInvMode() } KeyboardButtonAdditional(buttonModifier, IconPack.Inv, stringResource(R.string.keyboard_inverse), KeyboardButtonContentHeightShortAdditional) { onInvClick() }
KeyboardButtonAdditional(buttonModifier, IconPack.Power, stringResource(R.string.keyboard_power), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Operator.power) } KeyboardButtonAdditional(buttonModifier, IconPack.Power, stringResource(R.string.keyboard_power), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Operator.power) }
KeyboardButtonAdditional(buttonModifier, IconPack.Factorial, stringResource(R.string.keyboard_factorial), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Operator.factorial) } KeyboardButtonAdditional(buttonModifier, IconPack.Factorial, stringResource(R.string.keyboard_factorial), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Operator.factorial) }
KeyboardButtonLight(buttonModifier, IconPack.Key4, Token.Digit._4, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._4) } KeyboardButtonLight(buttonModifier, IconPack.Key4, Token.Digit._4, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._4) }
KeyboardButtonLight(buttonModifier, IconPack.Key5, Token.Digit._5, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._5) } KeyboardButtonLight(buttonModifier, IconPack.Key5, Token.Digit._5, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._5) }
KeyboardButtonLight(buttonModifier, IconPack.Key6, Token.Digit._6, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._6) } KeyboardButtonLight(buttonModifier, IconPack.Key6, Token.Digit._6, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._6) }
KeyboardButtonFilled(buttonModifier, IconPack.Multiply, stringResource(R.string.keyboard_multiply), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.multiply) } KeyboardButtonFilled(buttonModifier, IconPack.Multiply, stringResource(R.string.keyboard_multiply), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.multiply) }
KeyboardButtonFilled(buttonModifier, IconPack.Divide, stringResource(R.string.keyboard_divide), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.divide) } KeyboardButtonFilled(buttonModifier, IconPack.Divide, stringResource(R.string.keyboard_divide), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.divide) }
KeyboardButtonAdditional(buttonModifier, IconPack.ArSin, stringResource(R.string.keyboard_arsin), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Func.arsinBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.ArSin, stringResource(R.string.keyboard_arsin), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Func.arsinBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.ArCos, stringResource(R.string.keyboard_arcos), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Func.arcosBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.ArCos, stringResource(R.string.keyboard_arcos), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Func.arcosBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.AcTan, stringResource(R.string.keyboard_actan), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Func.actanBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.AcTan, stringResource(R.string.keyboard_actan), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Func.actanBracket) }
KeyboardButtonLight(buttonModifier, IconPack.Key1, Token.Digit._1, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._1) } KeyboardButtonLight(buttonModifier, IconPack.Key1, Token.Digit._1, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._1) }
KeyboardButtonLight(buttonModifier, IconPack.Key2, Token.Digit._2, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._2) } KeyboardButtonLight(buttonModifier, IconPack.Key2, Token.Digit._2, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._2) }
KeyboardButtonLight(buttonModifier, IconPack.Key3, Token.Digit._3, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._3) } KeyboardButtonLight(buttonModifier, IconPack.Key3, Token.Digit._3, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._3) }
KeyboardButtonFilled(buttonModifier, IconPack.Minus, stringResource(R.string.keyboard_minus), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.minus) } KeyboardButtonFilled(buttonModifier, IconPack.Minus, stringResource(R.string.keyboard_minus), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.minus) }
KeyboardButtonFilled(buttonModifier, IconPack.Percent, stringResource(R.string.keyboard_percent), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.percent) } KeyboardButtonFilled(buttonModifier, IconPack.Percent, stringResource(R.string.keyboard_percent), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.percent) }
KeyboardButtonAdditional(buttonModifier, IconPack.Euler, stringResource(R.string.keyboard_euler), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Const.e) } KeyboardButtonAdditional(buttonModifier, IconPack.Euler, stringResource(R.string.keyboard_euler), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Const.e) }
KeyboardButtonAdditional(buttonModifier, IconPack.Ex, stringResource(R.string.keyboard_exp), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Func.expBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Ex, stringResource(R.string.keyboard_exp), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Func.expBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.Power10, stringResource(R.string.keyboard_power_10), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Digit._1 + Token.Digit._0 + Token.Operator.power) } KeyboardButtonAdditional(buttonModifier, IconPack.Power10, stringResource(R.string.keyboard_power_10), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Digit._1 + Token.Digit._0 + Token.Operator.power) }
if (middleZero) { if (middleZero) {
KeyboardButtonLight(buttonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightShort) { addSymbol(Token.Digit.dot) } KeyboardButtonLight(buttonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit.dot) }
KeyboardButtonLight(buttonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._0) } KeyboardButtonLight(buttonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._0) }
} else { } else {
KeyboardButtonLight(buttonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._0) } KeyboardButtonLight(buttonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._0) }
KeyboardButtonLight(buttonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightShort) { addSymbol(Token.Digit.dot) } KeyboardButtonLight(buttonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit.dot) }
} }
KeyboardButtonLight(buttonModifier, IconPack.Backspace, stringResource(R.string.delete_label), KeyboardButtonContentHeightShort, clearSymbols) { deleteSymbol() } KeyboardButtonLight(buttonModifier, IconPack.Backspace, stringResource(R.string.delete_label), KeyboardButtonContentHeightShort, onClearClick) { onDeleteClick() }
KeyboardButtonFilled(buttonModifier, IconPack.Plus, stringResource(R.string.keyboard_plus), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.plus) } KeyboardButtonFilled(buttonModifier, IconPack.Plus, stringResource(R.string.keyboard_plus), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.plus) }
KeyboardButtonFilled(buttonModifier, IconPack.Equal, stringResource(R.string.keyboard_equal), KeyboardButtonContentHeightShort) { equal() } KeyboardButtonFilled(buttonModifier, IconPack.Equal, stringResource(R.string.keyboard_equal), KeyboardButtonContentHeightShort) { onEqualClick() }
} }
} else { } else {
KeypadFlow( KeypadFlow(
@ -487,51 +487,51 @@ private fun LandscapeKeyboard(
.fillMaxWidth(width) .fillMaxWidth(width)
.fillMaxHeight(height) .fillMaxHeight(height)
KeyboardButtonAdditional(buttonModifier, angleIcon, stringResource(angleIconDescription), KeyboardButtonContentHeightShortAdditional) { toggleAngleMode() } KeyboardButtonAdditional(buttonModifier, angleIcon, stringResource(angleIconDescription), KeyboardButtonContentHeightShortAdditional) { onAngleClick(!radianMode) }
KeyboardButtonAdditional(buttonModifier, IconPack.Root, stringResource(R.string.keyboard_root), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Operator.sqrt) } KeyboardButtonAdditional(buttonModifier, IconPack.Root, stringResource(R.string.keyboard_root), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Operator.sqrt) }
KeyboardButtonAdditional(buttonModifier, IconPack.Pi, stringResource(R.string.keyboard_pi), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Const.pi) } KeyboardButtonAdditional(buttonModifier, IconPack.Pi, stringResource(R.string.keyboard_pi), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Const.pi) }
KeyboardButtonLight(buttonModifier, IconPack.Key7, Token.Digit._7, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._7) } KeyboardButtonLight(buttonModifier, IconPack.Key7, Token.Digit._7, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._7) }
KeyboardButtonLight(buttonModifier, IconPack.Key8, Token.Digit._8, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._8) } KeyboardButtonLight(buttonModifier, IconPack.Key8, Token.Digit._8, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._8) }
KeyboardButtonLight(buttonModifier, IconPack.Key9, Token.Digit._9, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._9) } KeyboardButtonLight(buttonModifier, IconPack.Key9, Token.Digit._9, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._9) }
if (acButton) { if (showAcButton) {
KeyboardButtonTertiary(buttonModifier, IconPack.Clear, stringResource(R.string.clear_label), KeyboardButtonContentHeightShort) { clearSymbols() } KeyboardButtonTertiary(buttonModifier, IconPack.Clear, stringResource(R.string.clear_label), KeyboardButtonContentHeightShort) { onClearClick() }
KeyboardButtonFilled(buttonModifier, IconPack.Brackets, stringResource(R.string.keyboard_brackets), KeyboardButtonContentHeightShort) { addBracket() } KeyboardButtonFilled(buttonModifier, IconPack.Brackets, stringResource(R.string.keyboard_brackets), KeyboardButtonContentHeightShort) { onBracketsClick() }
} else { } else {
KeyboardButtonFilled(buttonModifier, IconPack.LeftBracket, stringResource(R.string.keyboard_left_bracket), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.leftBracket) } KeyboardButtonFilled(buttonModifier, IconPack.LeftBracket, stringResource(R.string.keyboard_left_bracket), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.leftBracket) }
KeyboardButtonFilled(buttonModifier, IconPack.RightBracket, stringResource(R.string.keyboard_right_bracket), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.rightBracket) } KeyboardButtonFilled(buttonModifier, IconPack.RightBracket, stringResource(R.string.keyboard_right_bracket), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.rightBracket) }
} }
KeyboardButtonAdditional(buttonModifier, IconPack.Inv, stringResource(R.string.keyboard_inverse), KeyboardButtonContentHeightShortAdditional) { toggleInvMode() } KeyboardButtonAdditional(buttonModifier, IconPack.Inv, stringResource(R.string.keyboard_inverse), KeyboardButtonContentHeightShortAdditional) { onInvClick() }
KeyboardButtonAdditional(buttonModifier, IconPack.Power, stringResource(R.string.keyboard_power), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Operator.power) } KeyboardButtonAdditional(buttonModifier, IconPack.Power, stringResource(R.string.keyboard_power), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Operator.power) }
KeyboardButtonAdditional(buttonModifier, IconPack.Factorial, stringResource(R.string.keyboard_factorial), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Operator.factorial) } KeyboardButtonAdditional(buttonModifier, IconPack.Factorial, stringResource(R.string.keyboard_factorial), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Operator.factorial) }
KeyboardButtonLight(buttonModifier, IconPack.Key4, Token.Digit._4, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._4) } KeyboardButtonLight(buttonModifier, IconPack.Key4, Token.Digit._4, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._4) }
KeyboardButtonLight(buttonModifier, IconPack.Key5, Token.Digit._5, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._5) } KeyboardButtonLight(buttonModifier, IconPack.Key5, Token.Digit._5, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._5) }
KeyboardButtonLight(buttonModifier, IconPack.Key6, Token.Digit._6, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._6) } KeyboardButtonLight(buttonModifier, IconPack.Key6, Token.Digit._6, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._6) }
KeyboardButtonFilled(buttonModifier, IconPack.Multiply, stringResource(R.string.keyboard_multiply), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.multiply) } KeyboardButtonFilled(buttonModifier, IconPack.Multiply, stringResource(R.string.keyboard_multiply), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.multiply) }
KeyboardButtonFilled(buttonModifier, IconPack.Divide, stringResource(R.string.keyboard_divide), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.divide) } KeyboardButtonFilled(buttonModifier, IconPack.Divide, stringResource(R.string.keyboard_divide), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.divide) }
KeyboardButtonAdditional(buttonModifier, IconPack.Sin, stringResource(R.string.keyboard_sin), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Func.sinBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Sin, stringResource(R.string.keyboard_sin), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Func.sinBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.Cos, stringResource(R.string.keyboard_cos), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Func.cosBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Cos, stringResource(R.string.keyboard_cos), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Func.cosBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.Tan, stringResource(R.string.keyboard_tan), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Func.tanBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Tan, stringResource(R.string.keyboard_tan), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Func.tanBracket) }
KeyboardButtonLight(buttonModifier, IconPack.Key1, Token.Digit._1, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._1) } KeyboardButtonLight(buttonModifier, IconPack.Key1, Token.Digit._1, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._1) }
KeyboardButtonLight(buttonModifier, IconPack.Key2, Token.Digit._2, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._2) } KeyboardButtonLight(buttonModifier, IconPack.Key2, Token.Digit._2, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._2) }
KeyboardButtonLight(buttonModifier, IconPack.Key3, Token.Digit._3, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._3) } KeyboardButtonLight(buttonModifier, IconPack.Key3, Token.Digit._3, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._3) }
KeyboardButtonFilled(buttonModifier, IconPack.Minus, stringResource(R.string.keyboard_minus), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.minus) } KeyboardButtonFilled(buttonModifier, IconPack.Minus, stringResource(R.string.keyboard_minus), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.minus) }
KeyboardButtonFilled(buttonModifier, IconPack.Percent, stringResource(R.string.keyboard_percent), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.percent) } KeyboardButtonFilled(buttonModifier, IconPack.Percent, stringResource(R.string.keyboard_percent), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.percent) }
KeyboardButtonAdditional(buttonModifier, IconPack.Euler, stringResource(R.string.keyboard_euler), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Const.e) } KeyboardButtonAdditional(buttonModifier, IconPack.Euler, stringResource(R.string.keyboard_euler), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Const.e) }
KeyboardButtonAdditional(buttonModifier, IconPack.Ln, stringResource(R.string.keyboard_ln), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Func.lnBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Ln, stringResource(R.string.keyboard_ln), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Func.lnBracket) }
KeyboardButtonAdditional(buttonModifier, IconPack.Log, stringResource(R.string.keyboard_log), KeyboardButtonContentHeightShortAdditional) { addSymbol(Token.Func.logBracket) } KeyboardButtonAdditional(buttonModifier, IconPack.Log, stringResource(R.string.keyboard_log), KeyboardButtonContentHeightShortAdditional) { onAddTokenClick(Token.Func.logBracket) }
if (middleZero) { if (middleZero) {
KeyboardButtonLight(buttonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightShort) { addSymbol(Token.Digit.dot) } KeyboardButtonLight(buttonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit.dot) }
KeyboardButtonLight(buttonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._0) } KeyboardButtonLight(buttonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._0) }
} else { } else {
KeyboardButtonLight(buttonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightShort) { addSymbol(Token.Digit._0) } KeyboardButtonLight(buttonModifier, IconPack.Key0, Token.Digit._0, KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit._0) }
KeyboardButtonLight(buttonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightShort) { addSymbol(Token.Digit.dot) } KeyboardButtonLight(buttonModifier, fractionalIcon, stringResource(fractionalIconDescription), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Digit.dot) }
} }
KeyboardButtonLight(buttonModifier, IconPack.Backspace, stringResource(R.string.delete_label), KeyboardButtonContentHeightShort, clearSymbols) { deleteSymbol() } KeyboardButtonLight(buttonModifier, IconPack.Backspace, stringResource(R.string.delete_label), KeyboardButtonContentHeightShort, onClearClick) { onDeleteClick() }
KeyboardButtonFilled(buttonModifier, IconPack.Plus, stringResource(R.string.keyboard_plus), KeyboardButtonContentHeightShort) { addSymbol(Token.Operator.plus) } KeyboardButtonFilled(buttonModifier, IconPack.Plus, stringResource(R.string.keyboard_plus), KeyboardButtonContentHeightShort) { onAddTokenClick(Token.Operator.plus) }
KeyboardButtonFilled(buttonModifier, IconPack.Equal, stringResource(R.string.keyboard_equal), KeyboardButtonContentHeightShort) { equal() } KeyboardButtonFilled(buttonModifier, IconPack.Equal, stringResource(R.string.keyboard_equal), KeyboardButtonContentHeightShort) { onEqualClick() }
} }
} }
} }
@ -542,18 +542,18 @@ private fun LandscapeKeyboard(
private fun PreviewPortraitKeyboard() { private fun PreviewPortraitKeyboard() {
PortraitKeyboard( PortraitKeyboard(
modifier = Modifier.fillMaxHeight(), modifier = Modifier.fillMaxHeight(),
onAddTokenClick = {},
onBracketsClick = {},
onDeleteClick = {},
onClearClick = {},
onEqualClick = {},
onInvClick = {},
onAngleClick = {},
showInvButtons = false,
radianMode = true, radianMode = true,
fractional = Token.PERIOD, showAcButton = true,
addSymbol = {},
clearSymbols = {},
deleteSymbol = {},
toggleAngleMode = {},
equal = {},
middleZero = false, middleZero = false,
acButton = true, fractional = Token.PERIOD,
addBracket = {},
invMode = false,
toggleInvMode = {}
) )
} }
@ -562,17 +562,17 @@ private fun PreviewPortraitKeyboard() {
private fun PreviewLandscapeKeyboard() { private fun PreviewLandscapeKeyboard() {
LandscapeKeyboard( LandscapeKeyboard(
modifier = Modifier.fillMaxHeight(), modifier = Modifier.fillMaxHeight(),
onAddTokenClick = {},
onBracketsClick = {},
onDeleteClick = {},
onClearClick = {},
onEqualClick = {},
onInvClick = {},
onAngleClick = {},
showInvButtons = false,
radianMode = true, radianMode = true,
fractional = Token.PERIOD, showAcButton = true,
addSymbol = {},
clearSymbols = {},
deleteSymbol = {},
toggleAngleMode = {},
equal = {},
middleZero = false, middleZero = false,
acButton = true, fractional = Token.PERIOD,
addBracket = {},
invMode = false,
toggleInvMode = {}
) )
} }

View File

@ -40,6 +40,7 @@ import androidx.compose.ui.semantics.testTag
import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.sadellie.unitto.core.base.FormatterSymbols import com.sadellie.unitto.core.base.FormatterSymbols
import com.sadellie.unitto.core.base.R
import com.sadellie.unitto.core.ui.LocalWindowSize import com.sadellie.unitto.core.ui.LocalWindowSize
import com.sadellie.unitto.core.ui.WindowHeightSizeClass import com.sadellie.unitto.core.ui.WindowHeightSizeClass
import com.sadellie.unitto.core.ui.common.textfield.ExpressionTextField import com.sadellie.unitto.core.ui.common.textfield.ExpressionTextField
@ -78,26 +79,23 @@ fun TextBox(
formatterSymbols = formatterSymbols formatterSymbols = formatterSymbols
) )
if (LocalWindowSize.current.heightSizeClass > WindowHeightSizeClass.Compact) { if (LocalWindowSize.current.heightSizeClass > WindowHeightSizeClass.Compact) {
val calculationResultModifier = Modifier
.weight(2f)
.fillMaxWidth()
.padding(horizontal = 8.dp)
when (output) { when (output) {
is CalculationResult.Empty -> { is CalculationResult.Empty -> {
Spacer( Spacer(
modifier = Modifier modifier = calculationResultModifier
.weight(2f)
.fillMaxWidth()
.padding(horizontal = 8.dp)
) )
} }
is CalculationResult.Default -> { is CalculationResult.Default -> {
var outputTF by remember(output) { var outputTF by remember(output) { mutableStateOf(TextFieldValue(output.text)) }
mutableStateOf(TextFieldValue(output.text))
}
ExpressionTextField( ExpressionTextField(
modifier = Modifier modifier = calculationResultModifier,
.weight(2f)
.fillMaxWidth()
.padding(horizontal = 8.dp),
value = outputTF, value = outputTF,
minRatio = 0.8f, minRatio = 0.8f,
onValueChange = { outputTF = it }, onValueChange = { outputTF = it },
@ -108,17 +106,13 @@ fun TextBox(
} }
is CalculationResult.Fraction -> { is CalculationResult.Fraction -> {
var outputTF by remember(output) { var outputTF by remember(output) { mutableStateOf(TextFieldValue(output.text)) }
mutableStateOf(TextFieldValue(output.text))
}
ExpressionTextField( ExpressionTextField(
modifier = Modifier modifier = calculationResultModifier,
.weight(2f)
.fillMaxWidth()
.padding(horizontal = 8.dp),
value = outputTF, value = outputTF,
minRatio = 0.8f, minRatio = 0.8f,
onValueChange = { outputTF = it }, onValueChange = { outputTF = outputTF.copy(selection = it.selection) },
textColor = MaterialTheme.colorScheme.onSurfaceVariant.copy(0.6f), textColor = MaterialTheme.colorScheme.onSurfaceVariant.copy(0.6f),
formatterSymbols = formatterSymbols, formatterSymbols = formatterSymbols,
readOnly = true, readOnly = true,
@ -127,11 +121,8 @@ fun TextBox(
is CalculationResult.DivideByZeroError -> { is CalculationResult.DivideByZeroError -> {
SimpleTextField( SimpleTextField(
modifier = Modifier modifier = calculationResultModifier,
.weight(2f) value = TextFieldValue(stringResource(R.string.calculator_divide_by_zero_error)),
.fillMaxWidth()
.padding(horizontal = 8.dp),
value = TextFieldValue(stringResource(output.label)),
minRatio = 0.8f, minRatio = 0.8f,
onValueChange = {}, onValueChange = {},
textColor = MaterialTheme.colorScheme.error, textColor = MaterialTheme.colorScheme.error,
@ -145,7 +136,7 @@ fun TextBox(
.weight(2f) .weight(2f)
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 8.dp), .padding(horizontal = 8.dp),
value = TextFieldValue(stringResource(output.label)), value = TextFieldValue(stringResource(R.string.error_label)),
minRatio = 0.8f, minRatio = 0.8f,
onValueChange = {}, onValueChange = {},
textColor = MaterialTheme.colorScheme.error, textColor = MaterialTheme.colorScheme.error,