Take the preset palette from floret-kit (#198)

This commit is contained in:
makiolaj committed 2026-11-30 21:58:36 +01:00
1 parent f0492cae3a
commit 32213d46f8
5 files changed
+23 -53

No files matched your search

@@ -1,49 +1,33 @@
package de.jeanlucmakiola.calendula.data.calendar
import de.jeanlucmakiola.floret.components.PresetColors
/**
* The colours offered when creating or editing a calendar; ARGB ints for a raw
* `CALENDAR_COLOR` / `EVENT_COLOR`.
*
* Hues rather than final fills: every surface that draws a calendar colour runs
* it through the app's own tone pass first, which pins lightness to one of two
* poles. So the set is spread by hue first, and the naturally light colours
* (amber, cyan, pink) sit on the light pole, which keeps them apart in lightness
* too, for colour-vision deficiencies as much as anything (#198). Distinctness
* is checked painted, in both themes and raw, by `CalendarColorPaletteTest`.
*
* Stored colours are never rewritten to match: a calendar or event coloured
* from an earlier palette simply shows as a custom colour ([presetOf]).
* `CALENDAR_COLOR` / `EVENT_COLOR`. The values are floret-kit's [PresetColors],
* shared with Agendula; distinctness after this app's tone pass is checked by
* `CalendarColorPaletteTest`.
*
* The named entries exist for callers that need one specific hue (the managed
* special-dates calendars), so they can't drift from the swatches on offer.
*/
object CalendarColorPalette {
val Mauve = 0xFF614F54.toInt()
val Red = 0xFFEC4851.toInt()
val Orange = 0xFFE28139.toInt()
val Amber = 0xFFF3CD66.toInt()
val Olive = 0xFF666722.toInt()
val Green = 0xFF00852E.toInt()
val Teal = 0xFF009391.toInt()
val Cyan = 0xFF58C3F5.toInt()
val Blue = 0xFF2676C4.toInt()
val Indigo = 0xFF625CC5.toInt()
val Purple = 0xFF9352A5.toInt()
val Pink = 0xFFFD9EBF.toInt()
val Mauve = PresetColors.Mauve
val Red = PresetColors.Red
val Orange = PresetColors.Orange
val Amber = PresetColors.Amber
val Olive = PresetColors.Olive
val Green = PresetColors.Green
val Teal = PresetColors.Teal
val Cyan = PresetColors.Cyan
val Blue = PresetColors.Blue
val Indigo = PresetColors.Indigo
val Purple = PresetColors.Purple
val Pink = PresetColors.Pink
/** The full palette, in swatch-grid order. */
val all: List<Int> = listOf(
Mauve, Red, Orange, Amber, Olive, Green,
Teal, Cyan, Blue, Indigo, Purple, Pink,
)
val all: List<Int> = PresetColors.all
/**
* The preset [argb] is, or null when it is a custom colour. Alpha is
* ignored: providers differ in whether they store it.
*/
fun presetOf(argb: Int?): Int? = argb?.let { all.firstOrNull { preset -> sameColor(preset, it) } }
/** The preset [argb] is, or null when it is a custom colour (never rewritten to match). */
fun presetOf(argb: Int?): Int? = PresetColors.presetOf(argb)
}
/** Whether [a] and [b] are the same RGB colour, whatever their alpha. */
fun sameColor(a: Int?, b: Int?): Boolean =
a != null && b != null && (a and 0xFFFFFF) == (b and 0xFFFFFF)
@@ -73,7 +73,7 @@ import de.jeanlucmakiola.calendula.domain.isNotSynced
import de.jeanlucmakiola.calendula.domain.orderedForManager
import de.jeanlucmakiola.calendula.domain.stateLabels
import de.jeanlucmakiola.calendula.data.calendar.CalendarColorPalette
import de.jeanlucmakiola.calendula.data.calendar.sameColor
import de.jeanlucmakiola.floret.components.sameColor
import de.jeanlucmakiola.calendula.ui.common.CustomColorPicker
import de.jeanlucmakiola.calendula.ui.common.CustomColorRow
import de.jeanlucmakiola.calendula.ui.common.RecentColorsRow
@@ -22,7 +22,7 @@ import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import androidx.compose.foundation.selection.selectable
import de.jeanlucmakiola.calendula.data.calendar.sameColor
import de.jeanlucmakiola.floret.components.sameColor
import de.jeanlucmakiola.floret.components.formatHexColor
/**
@@ -11,13 +11,6 @@ class CalendarColorPaletteTest {
private val palette = CalendarColorPalette.all
@Test
fun `presets are twelve distinct opaque colours`() {
assertThat(palette).hasSize(12)
assertThat(palette.toSet()).hasSize(12)
palette.forEach { assertThat(it ushr 24).isEqualTo(0xFF) }
}
@Test
fun `painted swatches stay apart in both themes`() {
assertMinDistance("light fill", MIN_FILL_DISTANCE) { eventTone(it, dark = false, harmonise = true).container }
@@ -61,13 +54,6 @@ class CalendarColorPaletteTest {
assertThat(CalendarColorPalette.presetOf(null)).isNull()
}
@Test
fun `sameColor compares rgb only`() {
assertThat(sameColor(0xFF112233.toInt(), 0x00112233)).isTrue()
assertThat(sameColor(0xFF112233.toInt(), 0xFF112234.toInt())).isFalse()
assertThat(sameColor(null, 0xFF112233.toInt())).isFalse()
}
private fun assertMinDistance(label: String, min: Float, paint: (Int) -> Int) {
val painted = palette.map(paint).map(::oklchOf)
for (i in painted.indices) for (j in i + 1 until painted.size) {