Section / Theme: extract sectionCardColor() helper

Three SectionView overloads were each computing the same cardColor inline:
if (CurrentColors.value.base == DefaultTheme.LIGHT) Color.White
else MaterialTheme.colors.background.mixWith(...). DRY violation paired with
the canvasColorForCurrentTheme() helper that already covers the canvas side
of the same theme split. Add a sectionCardColor() function in Theme.kt and
collapse the 3 inline formulas to one call.
This commit is contained in:
another-simple-pixel
2026-05-18 04:12:05 -07:00
parent f99cf9b881
commit 5c4a24f15e
2 changed files with 12 additions and 6 deletions
@@ -613,6 +613,15 @@ fun canvasColorForCurrentTheme(): Color {
}
}
// Card background color for SectionView. LIGHT: pure white (raised above the
// off-white canvas). DARK/BLACK/SIMPLEX: founder's mixWith formula (lifts cards
// above palette bg using onBackground tint).
fun sectionCardColor(): Color {
val theme = CurrentColors.value
return if (theme.base == DefaultTheme.LIGHT) Color.White
else theme.colors.background.mixWith(theme.colors.onBackground, 0.95f)
}
fun Modifier.themedBackground(baseTheme: DefaultTheme = CurrentColors.value.base, bgLayerSize: MutableState<IntSize>?, bgLayer: GraphicsLayer?/*, shape: Shape = RectangleShape*/): Modifier {
return drawBehind {
copyBackgroundToAppBar(bgLayerSize, bgLayer) {
@@ -46,8 +46,7 @@ private fun Modifier.sectionItemDivider(): Modifier {
@Composable
fun SectionView(title: String? = null, contentPadding: PaddingValues = PaddingValues(), headerBottomPadding: Dp = 8.dp, content: (@Composable ColumnScope.() -> Unit)) {
val cardColor = if (CurrentColors.value.base == DefaultTheme.LIGHT) Color.White
else MaterialTheme.colors.background.mixWith(MaterialTheme.colors.onBackground, 0.95f)
val cardColor = sectionCardColor()
Column {
if (title != null) {
Text(
@@ -77,8 +76,7 @@ fun SectionView(
padding: PaddingValues = PaddingValues(),
content: (@Composable ColumnScope.() -> Unit)
) {
val cardColor = if (CurrentColors.value.base == DefaultTheme.LIGHT) Color.White
else MaterialTheme.colors.background.mixWith(MaterialTheme.colors.onBackground, 0.95f)
val cardColor = sectionCardColor()
Column {
val iconSize = with(LocalDensity.current) { 21.sp.toDp() }
Row(Modifier.padding(start = DEFAULT_PADDING + DEFAULT_PADDING_HALF, bottom = 5.dp), verticalAlignment = Alignment.CenterVertically) {
@@ -101,8 +99,7 @@ fun SectionView(
@Composable
fun SectionViewWithButton(title: String? = null, titleButton: (@Composable () -> Unit)?, contentPadding: PaddingValues = PaddingValues(), headerBottomPadding: Dp = 8.dp, content: (@Composable ColumnScope.() -> Unit)) {
val cardColor = if (CurrentColors.value.base == DefaultTheme.LIGHT) Color.White
else MaterialTheme.colors.background.mixWith(MaterialTheme.colors.onBackground, 0.95f)
val cardColor = sectionCardColor()
Column {
if (title != null || titleButton != null) {
Row(modifier = Modifier.padding(start = DEFAULT_PADDING + DEFAULT_PADDING_HALF, end = DEFAULT_PADDING + DEFAULT_PADDING_HALF, bottom = headerBottomPadding).fillMaxWidth()) {