diff --git a/example/lib/positioning_demo.dart b/example/lib/positioning_demo.dart index a0eef6c..2f1c03f 100644 --- a/example/lib/positioning_demo.dart +++ b/example/lib/positioning_demo.dart @@ -53,6 +53,11 @@ final _events = [ _DemoEvent(7, 1, LocalTime(2, 30, 0), LocalTime(3, 30, 0)), _DemoEvent(7, 2, LocalTime(3, 0, 0), LocalTime(4, 0, 0)), _DemoEvent(8, 0, LocalTime(20, 0, 0), LocalTime(4, 0, 0), endDateOffset: 1), + _DemoEvent(9, 1, LocalTime(12, 0, 0), LocalTime(16, 0, 0)), + _DemoEvent(9, 2, LocalTime(12, 0, 0), LocalTime(13, 0, 0)), + _DemoEvent(9, 3, LocalTime(12, 0, 0), LocalTime(13, 0, 0)), + _DemoEvent(9, 4, LocalTime(12, 0, 0), LocalTime(13, 0, 0)), + _DemoEvent(9, 5, LocalTime(15, 0, 0), LocalTime(16, 0, 0)), _DemoEvent.allDay(0, 0, 1), _DemoEvent.allDay(1, 1, 1), _DemoEvent.allDay(2, 0, 2), diff --git a/lib/src/content/date_events.dart b/lib/src/content/date_events.dart index 4a9342d..7e9dacf 100644 --- a/lib/src/content/date_events.dart +++ b/lib/src/content/date_events.dart @@ -126,8 +126,9 @@ class _DayEventsLayoutDelegate positions.groupColumnCounts[position.group]; final columnLeft = columnWidth * position.column; final left = columnLeft + position.index * stackedEventSpacing; - final width = - columnWidth - position.index * stackedEventSpacing - eventSpacing; + final width = columnWidth * position.columnSpan - + position.index * stackedEventSpacing - + eventSpacing; final childSize = Size(width.coerceAtLeast(minWidth), height); layoutChild(event.id, BoxConstraints.tight(childSize)); @@ -217,6 +218,30 @@ class _DayEventsLayoutDelegate positions.groupColumnCounts.length, minColumn, minIndex + 1); columns[minColumn].add(event); } + + // Expand events to multiple columns if possible. + for (final event in currentGroup) { + final position = positions.eventPositions[event]; + if (position.column == columns.length - 1) { + continue; + } + + final cols = + (position.column + 1).rangeTo(columns.length - 1).where((column) { + return currentGroup + .where((e) => positions.eventPositions[e].column == column) + .where((e) => + event.start < _actualEnd(e, height) && + e.start < _actualEnd(event, height)) + .isEmpty; + }).toList(); + final maxColumnWithoutIntersections = cols.max() ?? position.column; + + positions.eventPositions[event] = position.copyWith( + columnSpan: maxColumnWithoutIntersections - position.column + 1, + ); + } + positions.groupColumnCounts.add(columns.length); } @@ -254,12 +279,27 @@ class _EventPositions { } class _SingleEventPosition { - _SingleEventPosition(this.group, this.column, this.index) - : assert(group != null), + _SingleEventPosition( + this.group, + this.column, + this.index, { + this.columnSpan = 1, + }) : assert(group != null), assert(column != null), + assert(columnSpan != null), assert(index != null); final int group; final int column; + final int columnSpan; final int index; + + _SingleEventPosition copyWith({int columnSpan}) { + return _SingleEventPosition( + group, + column, + index, + columnSpan: columnSpan ?? this.columnSpan, + ); + } }