Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand part-day events to fill empty columns #30

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions example/lib/positioning_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ final _events = <BasicEvent>[
_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),
Expand Down
48 changes: 44 additions & 4 deletions lib/src/content/date_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ class _DayEventsLayoutDelegate<E extends Event>
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));
Expand Down Expand Up @@ -217,6 +218,30 @@ class _DayEventsLayoutDelegate<E extends Event>
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);
}

Expand Down Expand Up @@ -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,
);
}
}