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()) }),
|
.then(with(density) { Modifier.height(dragState.offset.absoluteValue.toDp()) }),
|
||||||
basis = uiState.unitTo,
|
basis = uiState.unitTo,
|
||||||
result = uiState.result,
|
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
|
package app.myzel394.numberhub.feature.converter.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.offset
|
import androidx.compose.foundation.layout.offset
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import app.myzel394.numberhub.data.converter.ConverterResult
|
import app.myzel394.numberhub.data.converter.ConverterResult
|
||||||
import app.myzel394.numberhub.data.model.converter.unit.BasicUnit
|
import app.myzel394.numberhub.data.model.converter.unit.BasicUnit
|
||||||
@ -17,6 +20,7 @@ internal fun BaseCalculationSummary(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
basis: BasicUnit.NumberBase,
|
basis: BasicUnit.NumberBase,
|
||||||
result: ConverterResult.NumberBase,
|
result: ConverterResult.NumberBase,
|
||||||
|
onResultChange: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val fontStyle = MaterialTheme.typography.headlineSmall
|
val fontStyle = MaterialTheme.typography.headlineSmall
|
||||||
|
|
||||||
@ -30,24 +34,45 @@ internal fun BaseCalculationSummary(
|
|||||||
val digit = character.digitToInt(16);
|
val digit = character.digitToInt(16);
|
||||||
val base = basis.factor.toInt()
|
val base = basis.factor.toInt()
|
||||||
|
|
||||||
Text(
|
Row(
|
||||||
text = "$digit",
|
modifier = Modifier
|
||||||
style = fontStyle,
|
.clip(MaterialTheme.shapes.small)
|
||||||
color = MaterialTheme.colorScheme.primary,
|
.clickable {
|
||||||
)
|
val newCurrentValue = (digit + 1) % base
|
||||||
Text(
|
val newResultText = result.value.substring(
|
||||||
text = " · $base",
|
0,
|
||||||
style = fontStyle,
|
index,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
) + newCurrentValue.toString(16) + result.value.substring(index + 1)
|
||||||
)
|
|
||||||
Text(
|
onResultChange(newResultText)
|
||||||
text = "${result.value.length - index - 1}",
|
}
|
||||||
modifier = Modifier.offset(y = -(MaterialTheme.typography.bodySmall.fontSize.div(2)).value.dp),
|
.padding(vertical = 2.dp, horizontal = 6.dp),
|
||||||
style = fontStyle.copy(
|
horizontalArrangement = Arrangement.Center,
|
||||||
fontSize = MaterialTheme.typography.bodySmall.fontSize,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
),
|
) {
|
||||||
color = MaterialTheme.colorScheme.tertiary,
|
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) {
|
if (index < result.value.length - 1) {
|
||||||
Text(
|
Text(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user