Clip color swatch click indicator correctly

This commit is contained in:
MM20 2023-08-26 19:02:45 +02:00
parent ff7a72f7c4
commit 7d48db455c
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 50 additions and 47 deletions

View File

@ -2,6 +2,7 @@ package de.mm20.launcher2.ui.settings.colorscheme
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
@ -22,7 +23,8 @@ import hct.Hct
fun ColorSwatch(
color: Color,
modifier: Modifier = Modifier,
selected: Boolean = false
selected: Boolean = false,
onClick: (() -> Unit)? = null
) {
val darkTheme = LocalDarkTheme.current
val iconColor = Color(Hct.fromInt(color.toArgb()).let {
@ -46,6 +48,7 @@ fun ColorSwatch(
Box(
modifier = modifier
.clip(CircleShape)
.clickable(enabled = onClick != null, onClick = onClick ?: {})
.border(
if (selected) 4.dp else 1.dp,
borderColor,

View File

@ -48,8 +48,8 @@ fun CorePaletteColorPreference(
color = Color(value ?: defaultValue),
modifier = modifier
.size(48.dp)
.tooltipTrigger()
.clickable { showDialog = true },
.tooltipTrigger(),
onClick = { showDialog = true },
)
}

View File

@ -75,8 +75,8 @@ fun ThemeColorPreference(
color = Color((value ?: defaultValue).get(corePalette)),
modifier = modifier
.size(48.dp)
.tooltipTrigger()
.clickable { showDialog = true },
.tooltipTrigger(),
onClick = { showDialog = true },
)
}
@ -176,14 +176,14 @@ fun ThemeColorPreference(
),
modifier = Modifier
.padding(8.dp)
.size(64.dp)
.clickable {
currentValue = ColorRef(
CorePaletteColor.Primary,
tone.roundToInt()
)
},
.size(64.dp),
selected = themeColor.color == CorePaletteColor.Primary,
onClick = {
currentValue = ColorRef(
CorePaletteColor.Primary,
tone.roundToInt()
)
},
)
Spacer(modifier = Modifier.weight(1f))
ColorSwatch(
@ -194,14 +194,14 @@ fun ThemeColorPreference(
),
modifier = Modifier
.padding(8.dp)
.size(64.dp)
.clickable {
currentValue = ColorRef(
CorePaletteColor.Secondary,
tone.roundToInt()
)
},
.size(64.dp),
selected = themeColor.color == CorePaletteColor.Secondary,
onClick = {
currentValue = ColorRef(
CorePaletteColor.Secondary,
tone.roundToInt()
)
},
)
Spacer(modifier = Modifier.weight(1f))
ColorSwatch(
@ -212,14 +212,14 @@ fun ThemeColorPreference(
),
modifier = Modifier
.padding(8.dp)
.size(64.dp)
.clickable {
currentValue = ColorRef(
CorePaletteColor.Tertiary,
tone.roundToInt()
)
},
.size(64.dp),
selected = themeColor.color == CorePaletteColor.Tertiary,
onClick = {
currentValue = ColorRef(
CorePaletteColor.Tertiary,
tone.roundToInt()
)
},
)
}
Row(
@ -233,14 +233,14 @@ fun ThemeColorPreference(
),
modifier = Modifier
.padding(8.dp)
.size(64.dp)
.clickable {
currentValue = ColorRef(
CorePaletteColor.Neutral,
tone.roundToInt()
)
},
.size(64.dp),
selected = themeColor.color == CorePaletteColor.Neutral,
onClick = {
currentValue = ColorRef(
CorePaletteColor.Neutral,
tone.roundToInt()
)
},
)
Spacer(modifier = Modifier.weight(1f))
ColorSwatch(
@ -251,14 +251,14 @@ fun ThemeColorPreference(
),
modifier = Modifier
.padding(8.dp)
.size(64.dp)
.clickable {
currentValue = ColorRef(
CorePaletteColor.NeutralVariant,
tone.roundToInt()
)
},
.size(64.dp),
selected = themeColor.color == CorePaletteColor.NeutralVariant,
onClick = {
currentValue = ColorRef(
CorePaletteColor.NeutralVariant,
tone.roundToInt()
)
},
)
Spacer(modifier = Modifier.weight(1f))
ColorSwatch(
@ -269,14 +269,14 @@ fun ThemeColorPreference(
),
modifier = Modifier
.padding(8.dp)
.size(64.dp)
.clickable {
currentValue = ColorRef(
CorePaletteColor.Error,
tone.roundToInt()
)
},
.size(64.dp),
selected = themeColor.color == CorePaletteColor.Error,
onClick = {
currentValue = ColorRef(
CorePaletteColor.Error,
tone.roundToInt()
)
},
)
}
Row(