Skip to content

Commit

Permalink
feat: implemented dayview quarter hour line
Browse files Browse the repository at this point in the history
  • Loading branch information
prabinlamsal19 committed Sep 29, 2023
1 parent 1c29475 commit ff3c085
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions lib/src/painters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,86 @@ class HalfHourLinePainter extends CustomPainter {
}
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return oldDelegate is HourLinePainter &&
(oldDelegate.lineColor != lineColor ||
oldDelegate.offset != offset ||
lineHeight != oldDelegate.lineHeight ||
minuteHeight != oldDelegate.minuteHeight);
}
}

//using HalfHourIndicatorSettings for this too
class QuarterHourLinePainter extends CustomPainter {
/// Color of quarter hour line
final Color lineColor;

/// Height of quarter hour line
final double lineHeight;

/// Offset of quarter hour line from left.
final double offset;

/// Height occupied by one minute of time stamp.
final double minuteHeight;

/// Style of the quarter hour line
final LineStyle lineStyle;

/// Line dash width when using the [LineStyle.dashed] style
final double dashWidth;

/// Line dash space width when using the [LineStyle.dashed] style
final double dashSpaceWidth;

/// Paint quarter hour lines
QuarterHourLinePainter({
required this.lineColor,
required this.lineHeight,
required this.offset,
required this.minuteHeight,
required this.lineStyle,
this.dashWidth = 4,
this.dashSpaceWidth = 4,
});

@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = lineColor
..strokeWidth = lineHeight;

for (var i = 0; i < Constants.hoursADay; i++) {
final dy1 = i * minuteHeight * 60 + (minuteHeight * 15);
final dy2 = i * minuteHeight * 60 + (minuteHeight * 45);

//for the 15 minute line
if (lineStyle == LineStyle.dashed) {
var startX = offset;
while (startX < size.width) {
canvas.drawLine(
Offset(startX, dy1), Offset(startX + dashWidth, dy1), paint);
startX += dashWidth + dashSpaceWidth;
}
} else {
canvas.drawLine(Offset(offset, dy1), Offset(size.width, dy1), paint);
}

// for the 45 minutes line
if (lineStyle == LineStyle.dashed) {
var startX = offset;
while (startX < size.width) {
canvas.drawLine(
Offset(startX, dy2), Offset(startX + dashWidth, dy2), paint);
startX += dashWidth + dashSpaceWidth;
}
} else {
canvas.drawLine(Offset(offset, dy2), Offset(size.width, dy2), paint);
}
}
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return oldDelegate is HourLinePainter &&
Expand All @@ -157,6 +237,7 @@ class HalfHourLinePainter extends CustomPainter {
}
}


/// Paints a single horizontal line at [offset].
class CurrentTimeLinePainter extends CustomPainter {
/// Color of time indicator.
Expand Down

0 comments on commit ff3c085

Please sign in to comment.