mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
feat: Add single digit change feature for calculation summary
Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
parent
2097ab593b
commit
5a694ea5c8
@ -262,6 +262,11 @@ private fun NumberBase(
|
||||
.then(with(density) { Modifier.height(dragState.offset.absoluteValue.toDp()) }),
|
||||
basis = uiState.unitTo,
|
||||
result = uiState.result,
|
||||
onResultChange = { newValue ->
|
||||
val valueConverted = uiState.unitTo.convert(uiState.unitFrom, newValue)
|
||||
|
||||
updateInput1(TextFieldValue(valueConverted))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,16 @@
|
||||
package app.myzel394.numberhub.feature.converter.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.myzel394.numberhub.data.converter.ConverterResult
|
||||
import app.myzel394.numberhub.data.model.converter.unit.BasicUnit
|
||||
@ -17,6 +20,7 @@ internal fun BaseCalculationSummary(
|
||||
modifier: Modifier = Modifier,
|
||||
basis: BasicUnit.NumberBase,
|
||||
result: ConverterResult.NumberBase,
|
||||
onResultChange: (String) -> Unit,
|
||||
) {
|
||||
val fontStyle = MaterialTheme.typography.headlineSmall
|
||||
|
||||
@ -30,24 +34,45 @@ internal fun BaseCalculationSummary(
|
||||
val digit = character.digitToInt(16);
|
||||
val base = basis.factor.toInt()
|
||||
|
||||
Text(
|
||||
text = "$digit",
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
Text(
|
||||
text = " · $base",
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Text(
|
||||
text = "${result.value.length - index - 1}",
|
||||
modifier = Modifier.offset(y = -(MaterialTheme.typography.bodySmall.fontSize.div(2)).value.dp),
|
||||
style = fontStyle.copy(
|
||||
fontSize = MaterialTheme.typography.bodySmall.fontSize,
|
||||
),
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clip(MaterialTheme.shapes.small)
|
||||
.clickable {
|
||||
val newCurrentValue = (digit + 1) % base
|
||||
val newResultText = result.value.substring(
|
||||
0,
|
||||
index,
|
||||
) + newCurrentValue.toString(16) + result.value.substring(index + 1)
|
||||
|
||||
onResultChange(newResultText)
|
||||
}
|
||||
.padding(vertical = 2.dp, horizontal = 6.dp),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = "$digit",
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
Text(
|
||||
text = " · $base",
|
||||
style = fontStyle,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Text(
|
||||
text = "${result.value.length - index - 1}",
|
||||
modifier = Modifier.offset(
|
||||
y = -(MaterialTheme.typography.bodySmall.fontSize.div(
|
||||
2,
|
||||
)).value.dp,
|
||||
),
|
||||
style = fontStyle.copy(
|
||||
fontSize = MaterialTheme.typography.bodySmall.fontSize,
|
||||
),
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
)
|
||||
}
|
||||
|
||||
if (index < result.value.length - 1) {
|
||||
Text(
|
||||
|
Loading…
x
Reference in New Issue
Block a user