Skip to content

Commit

Permalink
Merge pull request #30 from JonasWanke/issue/29-event-size-doesn-t-fi…
Browse files Browse the repository at this point in the history
…ll-all-remaining-space

Expand part-day events to fill empty columns
  • Loading branch information
JonasWanke authored Jul 11, 2020
2 parents 3be07e4 + 4c8e8d3 commit f89327b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
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,
);
}
}

0 comments on commit f89327b

Please sign in to comment.