Skip to content

Commit f8ebd11

Browse files
feat: color system name in home screen title using system color
Adds toThemeAdapted() utility that clamps HSV brightness for legibility (≤0.55 in light theme, ≥0.75 in dark theme). Only the system name is colored; "Welcome, " retains the default top bar text color.
1 parent 9ca9285 commit f8ebd11

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎sheaf/app/src/main/java/systems/lupine/sheaf/ui/components/Components.kt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.compose.material.icons.Icons
1818
import androidx.compose.material.icons.filled.Warning
1919
import androidx.compose.material3.*
2020
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
21+
import androidx.compose.foundation.isSystemInDarkTheme
2122
import androidx.compose.runtime.*
2223
import androidx.compose.ui.Alignment
2324
import androidx.compose.ui.Modifier
@@ -116,6 +117,17 @@ fun parseColor(hex: String): Color? = runCatching {
116117
Color(android.graphics.Color.parseColor(hex))
117118
}.getOrNull()
118119

120+
// Adjusts a color's HSV brightness so it stays legible on the current theme background:
121+
// darkened to ≤0.55 in light theme, brightened to ≥0.75 in dark theme.
122+
@Composable
123+
fun Color.toThemeAdapted(): Color {
124+
val dark = isSystemInDarkTheme()
125+
val hsv = FloatArray(3)
126+
android.graphics.Color.colorToHSV(this.toArgb(), hsv)
127+
hsv[2] = if (dark) hsv[2].coerceAtLeast(0.75f) else hsv[2].coerceAtMost(0.55f)
128+
return Color(android.graphics.Color.HSVToColor(hsv))
129+
}
130+
119131
// ── Member card ───────────────────────────────────────────────────────────────
120132

121133
@OptIn(ExperimentalFoundationApi::class)

‎sheaf/app/src/main/java/systems/lupine/sheaf/ui/home/HomeScreen.kt‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import androidx.compose.material3.pulltorefresh.PullToRefreshBox
1515
import androidx.compose.runtime.*
1616
import androidx.compose.ui.Alignment
1717
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.text.SpanStyle
19+
import androidx.compose.ui.text.buildAnnotatedString
1820
import androidx.compose.ui.text.style.TextOverflow
21+
import androidx.compose.ui.text.withStyle
1922
import androidx.compose.ui.unit.dp
2023
import androidx.hilt.navigation.compose.hiltViewModel
2124
import androidx.lifecycle.Lifecycle
@@ -55,7 +58,20 @@ fun HomeScreen(
5558
contentWindowInsets = WindowInsets(0),
5659
topBar = {
5760
SheafCenterAlignedTopAppBar(
58-
title = { Text(state.system?.name?.let { "Welcome, $it" } ?: "Welcome") },
61+
title = {
62+
val systemColor = state.system?.color?.let { parseColor(it)?.toThemeAdapted() }
63+
Text(
64+
text = buildAnnotatedString {
65+
append("Welcome")
66+
state.system?.name?.let { name ->
67+
append(", ")
68+
withStyle(SpanStyle(color = systemColor ?: LocalContentColor.current)) {
69+
append(name)
70+
}
71+
}
72+
},
73+
)
74+
},
5975
)
6076
},
6177
floatingActionButton = {

0 commit comments

Comments
 (0)