fix(month): seat the split style's dots by lane (#53)
The dots gathered a day's *distinct colours*, which meant dot i stood for no particular event and two events sharing a calendar collapsed into one — undercounting the day. Seat them off the same lane assignment the paged grid draws from, so a dot and the bar in that lane are the same event. That fixes the count, and it is what will let one morph into the other when the grid expands. The cap is now MAX_EVENT_ROWS rather than a constant of its own: the two have to agree or a dot would have no bar to become. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -902,7 +902,9 @@ private fun SplitMonthContent(
|
||||
*/
|
||||
private val SPLIT_ROW_HEIGHT = 46.dp
|
||||
private val SPLIT_DOT_SIZE = 5.dp
|
||||
private const val SPLIT_MAX_DOTS = 3
|
||||
// Dots are capped by MAX_EVENT_ROWS, not a constant of their own: they stand for
|
||||
// the paged grid's lanes, so the two caps have to be the same number or a dot
|
||||
// would have no bar to become (#53).
|
||||
|
||||
/**
|
||||
* Rows the split grid always reserves — the most any month needs. A month that
|
||||
@@ -945,11 +947,15 @@ internal fun SplitMonthGrid(
|
||||
.fillMaxHeight(),
|
||||
)
|
||||
}
|
||||
week.days.forEach { day ->
|
||||
week.days.forEachIndexed { col, day ->
|
||||
val inMonth = day.month == month.month && day.year == month.year
|
||||
// Seated by lane rather than gathered by colour, so each dot
|
||||
// is the event the expanded grid draws in that same lane.
|
||||
val seated = week.laneEvents(col, day, MAX_EVENT_ROWS)
|
||||
SplitDayCell(
|
||||
date = day,
|
||||
events = state.instancesByDay[day].orEmpty(),
|
||||
events = seated,
|
||||
hidden = (week.countByDay[day] ?: 0) - seated.size,
|
||||
isToday = day == state.today,
|
||||
// A page marks only the days its own month owns. Paging
|
||||
// moves the selection before this month's replacement
|
||||
@@ -979,7 +985,7 @@ internal fun SplitMonthGrid(
|
||||
}
|
||||
|
||||
/**
|
||||
* One compact day: its number over up to [SPLIT_MAX_DOTS] event dots.
|
||||
* One compact day: its number over up to [MAX_EVENT_ROWS] lane-seated event dots.
|
||||
*
|
||||
* Selection and today are deliberately different signals — a tinted, outlined
|
||||
* cell versus the filled circle the other views already use for today — so the
|
||||
@@ -989,6 +995,8 @@ internal fun SplitMonthGrid(
|
||||
private fun SplitDayCell(
|
||||
date: LocalDate,
|
||||
events: List<EventInstance>,
|
||||
/** Events on this day that didn't fit a lane, shown as a "+N" beside the dots. */
|
||||
hidden: Int,
|
||||
isToday: Boolean,
|
||||
isSelected: Boolean,
|
||||
inMonth: Boolean,
|
||||
@@ -1037,32 +1045,37 @@ private fun SplitDayCell(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
Spacer(Modifier.height(2.dp))
|
||||
SplitDots(events = events, dark = dark)
|
||||
SplitDots(events = events, hidden = hidden, dark = dark)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Up to three colour dots for a day, plus a count when more are hidden. */
|
||||
/**
|
||||
* One dot per seated event, in lane order, plus a "+N" for those that didn't fit.
|
||||
*
|
||||
* Deliberately *not* de-duplicated by colour: [events] arrives lane-seated so the
|
||||
* dots line up with the bars the expanded grid draws, and collapsing two events
|
||||
* that share a calendar into one dot would both undercount the day and leave a
|
||||
* bar with no dot to grow out of.
|
||||
*/
|
||||
@Composable
|
||||
private fun SplitDots(events: List<EventInstance>, dark: Boolean) {
|
||||
private fun SplitDots(events: List<EventInstance>, hidden: Int, dark: Boolean) {
|
||||
if (events.isEmpty()) return
|
||||
val soften = LocalSoftenColors.current
|
||||
val colors = remember(events) { events.map { it.color }.distinct().take(SPLIT_MAX_DOTS) }
|
||||
val extra = events.size - colors.size
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(2.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
colors.forEach { argb ->
|
||||
events.forEach { event ->
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(SPLIT_DOT_SIZE)
|
||||
.background(eventFill(argb, dark, soften), CircleShape),
|
||||
.background(eventFill(event.color, dark, soften), CircleShape),
|
||||
)
|
||||
}
|
||||
if (extra > 0) {
|
||||
if (hidden > 0) {
|
||||
Text(
|
||||
text = "+$extra",
|
||||
text = "+$hidden",
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
|
||||
@@ -39,6 +39,34 @@ data class MonthWeek(
|
||||
val countByDay: Map<LocalDate, Int>,
|
||||
)
|
||||
|
||||
/**
|
||||
* The events occupying each lane of [day] — column [col] of this week — in lane
|
||||
* order, capped at [laneCap] lanes.
|
||||
*
|
||||
* This is the same seating [spans]/[timedByDay] get when the paged grid draws a
|
||||
* week: bars keep the lane the row layout gave them, and the day's timed events
|
||||
* fill whatever slots are left, top-most first. Reading it here means the split
|
||||
* style's dots and the paged style's bars describe a day in the *same order*, so
|
||||
* dot _i_ and lane _i_ are the same event and one can morph into the other (#53).
|
||||
*
|
||||
* Deriving the dots independently — by distinct colour, as they first were —
|
||||
* left dot _i_ standing for no particular event, and quietly merged two events
|
||||
* that shared a calendar into a single dot.
|
||||
*/
|
||||
fun MonthWeek.laneEvents(col: Int, day: LocalDate, laneCap: Int): List<EventInstance> {
|
||||
val byLane = arrayOfNulls<EventInstance>(laneCap)
|
||||
spans.forEach { span ->
|
||||
if (span.lane < laneCap && col in span.startCol..span.endCol) {
|
||||
byLane[span.lane] = span.event
|
||||
}
|
||||
}
|
||||
val free = (0 until laneCap).filter { byLane[it] == null }
|
||||
timedByDay[day].orEmpty().take(free.size).forEachIndexed { i, event ->
|
||||
byLane[free[i]] = event
|
||||
}
|
||||
return byLane.filterNotNull()
|
||||
}
|
||||
|
||||
/**
|
||||
* State for the continuous style (#38): a vertical stream of *self-contained*
|
||||
* months rather than one undifferentiated run of weeks. Each month is keyed by
|
||||
|
||||
Reference in New Issue
Block a user