From ff3c085ca0a109697840c6542b2773d304e2d2c2 Mon Sep 17 00:00:00 2001 From: prabinlamsal19 Date: Fri, 29 Sep 2023 16:37:03 +0545 Subject: [PATCH] feat: implemented dayview quarter hour line --- lib/src/painters.dart | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/lib/src/painters.dart b/lib/src/painters.dart index 1c2a539b..1b91c6a5 100644 --- a/lib/src/painters.dart +++ b/lib/src/painters.dart @@ -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 && @@ -157,6 +237,7 @@ class HalfHourLinePainter extends CustomPainter { } } + /// Paints a single horizontal line at [offset]. class CurrentTimeLinePainter extends CustomPainter { /// Color of time indicator.