mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-14 14:45:33 +00:00
refactor: switch theme dispatch from boolean pair to DefaultTheme
Two clarity fixes from the audit.
- ChatWallpaper: the private color helper was named gen — too short to
carry its purpose. Rename to colorForElement, the term it actually
computes (a single oklch Color from preset + mode + element params).
- Appearance.FormulaDevTools: both the generateScheme dispatch and the
slider rendering branched via `when { isLight -> ; isBlack -> ; else
-> dark }` and `if (isLight) { } else { ; if (!isBlack) ... }`. Two
parallel dispatches over the same proposition, expressed as boolean
pairs. DefaultTheme already carries that proposition with a name;
switch to `when (baseTheme)` so each branch states which theme it is
and lists its sliders / scheme call. Black's three-slider set becomes
its own branch instead of negative gates inside the dark branch.
The isLight/isBlack locals stay for the small conditionals inside the
defaults map computation (where the ternaries read fine inline).
Pure refactor — no behavior change.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+6
-6
@@ -332,7 +332,7 @@ private enum class ThemeElem(val params: ElemParams) {
|
||||
private const val BG_LIGHT_L = 0.9657f
|
||||
private const val BG_LIGHT_C_BASE = 0.02721f
|
||||
|
||||
private fun gen(mode: DefaultTheme, elem: ThemeElem, p: PresetWallpaper): Color {
|
||||
private fun colorForElement(mode: DefaultTheme, elem: ThemeElem, p: PresetWallpaper): Color {
|
||||
val m = MODE_PARAMS[mode]!!
|
||||
val e = elem.params
|
||||
return oklch(m.lBase + m.lSpread * e.lOffset, m.cFactor * e.cFactor * p.cScale, p.hue)
|
||||
@@ -342,15 +342,15 @@ private fun generateBackground(p: PresetWallpaper): Map<DefaultTheme, Color> =
|
||||
wallpaperBackgrounds(light = oklch(BG_LIGHT_L, BG_LIGHT_C_BASE * p.cScale, p.hue))
|
||||
|
||||
private fun generateTint(p: PresetWallpaper): Map<DefaultTheme, Color> =
|
||||
DefaultTheme.entries.associateWith { gen(it, ThemeElem.TINT, p) }
|
||||
DefaultTheme.entries.associateWith { colorForElement(it, ThemeElem.TINT, p) }
|
||||
|
||||
private fun generateColors(p: PresetWallpaper): Map<DefaultTheme, ResolvedColors> =
|
||||
DefaultTheme.entries.associateWith { mode ->
|
||||
ResolvedColors(
|
||||
sentMessage = gen(mode, ThemeElem.SENT_MESSAGE, p),
|
||||
sentQuote = gen(mode, ThemeElem.SENT_QUOTE, p),
|
||||
receivedMessage = gen(mode, ThemeElem.RECEIVED_MESSAGE, p),
|
||||
receivedQuote = gen(mode, ThemeElem.RECEIVED_QUOTE, p),
|
||||
sentMessage = colorForElement(mode, ThemeElem.SENT_MESSAGE, p),
|
||||
sentQuote = colorForElement(mode, ThemeElem.SENT_QUOTE, p),
|
||||
receivedMessage = colorForElement(mode, ThemeElem.RECEIVED_MESSAGE, p),
|
||||
receivedQuote = colorForElement(mode, ThemeElem.RECEIVED_QUOTE, p),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+26
-18
@@ -808,13 +808,13 @@ object AppearanceScope {
|
||||
val colorChroma = remember(preset, baseTheme, resetKey) { mutableFloatStateOf(saved("colorChroma") ?: defaults["colorChroma"] ?: 0f) }
|
||||
|
||||
// Compute formula result (O(1) math, no need to memoize)
|
||||
val result = when {
|
||||
isLight -> generateSchemeLight(
|
||||
val result = when (baseTheme) {
|
||||
DefaultTheme.LIGHT -> generateSchemeLight(
|
||||
hue.floatValue, bgL.floatValue, bgC.floatValue, step.floatValue,
|
||||
patternDepth.floatValue, patternChromaVal.floatValue, receivedTint.floatValue,
|
||||
bgLOffset.floatValue,
|
||||
)
|
||||
isBlack -> generateSchemeBlack(
|
||||
DefaultTheme.BLACK -> generateSchemeBlack(
|
||||
hue.floatValue, step.floatValue, colorChroma.floatValue,
|
||||
)
|
||||
else -> generateSchemeDark(
|
||||
@@ -846,21 +846,29 @@ object AppearanceScope {
|
||||
}
|
||||
|
||||
SectionView("FORMULA: ${preset.filename.uppercase()} / ${baseTheme.name}") {
|
||||
if (isLight) {
|
||||
FormulaSlider("Hue", hue, 0f..360f)
|
||||
FormulaSlider("Lightness", bgL, 0.85f..1f)
|
||||
FormulaSlider("BG Lightness", bgLOffset, -0.05f..0.05f)
|
||||
FormulaSlider("Chroma", bgC, 0f..0.10f)
|
||||
FormulaSlider("Contrast", step, 0.01f..0.10f)
|
||||
FormulaSlider("Received tint", receivedTint, 0f..0.07f)
|
||||
FormulaSlider("Pattern depth", patternDepth, 0f..10f)
|
||||
FormulaSlider("Pattern chroma", patternChromaVal, 0f..0.15f)
|
||||
} else {
|
||||
FormulaSlider("Hue", hue, 0f..360f)
|
||||
if (!isBlack) FormulaSlider("Lightness", bgL, 0.05f..0.30f)
|
||||
FormulaSlider("Contrast", step, 0.01f..0.10f)
|
||||
FormulaSlider("Accent chroma", colorChroma, 0f..0.20f)
|
||||
if (!isBlack) FormulaSlider("Secondary chroma", mutedChroma, 0f..0.05f)
|
||||
when (baseTheme) {
|
||||
DefaultTheme.LIGHT -> {
|
||||
FormulaSlider("Hue", hue, 0f..360f)
|
||||
FormulaSlider("Lightness", bgL, 0.85f..1f)
|
||||
FormulaSlider("BG Lightness", bgLOffset, -0.05f..0.05f)
|
||||
FormulaSlider("Chroma", bgC, 0f..0.10f)
|
||||
FormulaSlider("Contrast", step, 0.01f..0.10f)
|
||||
FormulaSlider("Received tint", receivedTint, 0f..0.07f)
|
||||
FormulaSlider("Pattern depth", patternDepth, 0f..10f)
|
||||
FormulaSlider("Pattern chroma", patternChromaVal, 0f..0.15f)
|
||||
}
|
||||
DefaultTheme.BLACK -> {
|
||||
FormulaSlider("Hue", hue, 0f..360f)
|
||||
FormulaSlider("Contrast", step, 0.01f..0.10f)
|
||||
FormulaSlider("Accent chroma", colorChroma, 0f..0.20f)
|
||||
}
|
||||
else -> {
|
||||
FormulaSlider("Hue", hue, 0f..360f)
|
||||
FormulaSlider("Lightness", bgL, 0.05f..0.30f)
|
||||
FormulaSlider("Contrast", step, 0.01f..0.10f)
|
||||
FormulaSlider("Accent chroma", colorChroma, 0f..0.20f)
|
||||
FormulaSlider("Secondary chroma", mutedChroma, 0f..0.05f)
|
||||
}
|
||||
}
|
||||
SectionItemView({
|
||||
savedParams.keys.filter { it.startsWith(pk) }.forEach { savedParams.remove(it) }
|
||||
|
||||
Reference in New Issue
Block a user