fix: add card elevation and interaction feedback (Closes #8) (#75)

This commit was merged in pull request #75.
This commit is contained in:
2026-03-13 14:24:20 +01:00
parent 7a020cbdc5
commit 587180dd91
2 changed files with 179 additions and 134 deletions

View File

@@ -2,10 +2,10 @@ package org.shahondin1624.lib.components.charactermodel.attributespage
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@@ -13,6 +13,7 @@ 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.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
@@ -36,14 +37,36 @@ fun Attribute(
onEdit: (() -> Unit)? = null,
) {
val textColor = contrastTextColor(attribute.type.color)
Card(
modifier = Modifier
.testTag(TestTags.attributeCard(attribute.type.name))
.then(
if (onEdit != null) Modifier.clickable { onEdit() }
else Modifier
val cardModifier = Modifier.testTag(TestTags.attributeCard(attribute.type.name))
val elevation = CardDefaults.cardElevation(
defaultElevation = 2.dp,
pressedElevation = 6.dp,
hoveredElevation = 4.dp
)
if (onEdit != null) {
Card(
onClick = onEdit,
modifier = cardModifier,
elevation = elevation
) {
AttributeCardContent(attribute, textColor, onRoll)
}
} else {
Card(
modifier = cardModifier,
elevation = elevation
) {
AttributeCardContent(attribute, textColor, onRoll)
}
}
}
@Composable
private fun AttributeCardContent(
attribute: Attribute,
textColor: Color,
onRoll: (DiceRoll) -> Unit
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Start,
@@ -97,5 +120,4 @@ fun Attribute(
)
}
}
}
}

View File

@@ -2,7 +2,6 @@ package org.shahondin1624.lib.components.charactermodel.attributespage
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
@@ -11,6 +10,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@@ -18,6 +18,7 @@ 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.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
@@ -43,14 +44,37 @@ fun Talent(
onEdit: (() -> Unit)? = null,
) {
val textColor = contrastTextColor(talent.attribute.color)
Card(
modifier = Modifier
.testTag(TestTags.talentCard(talent.name))
.then(
if (onEdit != null) Modifier.clickable { onEdit() }
else Modifier
val cardModifier = Modifier.testTag(TestTags.talentCard(talent.name))
val elevation = CardDefaults.cardElevation(
defaultElevation = 2.dp,
pressedElevation = 6.dp,
hoveredElevation = 4.dp
)
if (onEdit != null) {
Card(
onClick = onEdit,
modifier = cardModifier,
elevation = elevation
) {
TalentCardContent(talent, attributes, textColor, onRoll)
}
} else {
Card(
modifier = cardModifier,
elevation = elevation
) {
TalentCardContent(talent, attributes, textColor, onRoll)
}
}
}
@Composable
private fun TalentCardContent(
talent: TalentDefinition,
attributes: Attributes,
textColor: Color,
onRoll: (DiceRoll) -> Unit
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Start,
@@ -118,5 +142,4 @@ fun Talent(
)
}
}
}
}