39 lines
926 B
Dart
39 lines
926 B
Dart
class DayViewScale {
|
|
static const double defaultHourHeight = 34.0;
|
|
static const double minHourHeight = 34.0;
|
|
static const double maxHourHeight = 68.0;
|
|
|
|
final double hourHeight;
|
|
|
|
const DayViewScale({required this.hourHeight});
|
|
|
|
factory DayViewScale.defaultScale() {
|
|
return const DayViewScale(hourHeight: minHourHeight);
|
|
}
|
|
|
|
DayViewScale copyWith({double? hourHeight}) {
|
|
return DayViewScale(
|
|
hourHeight: _clampHourHeight(hourHeight ?? this.hourHeight),
|
|
);
|
|
}
|
|
|
|
DayViewScale zoomByFactor(double factor) {
|
|
if (factor <= 0) {
|
|
return this;
|
|
}
|
|
return copyWith(hourHeight: hourHeight * factor);
|
|
}
|
|
|
|
double pixelsForMinutes(int minutes) {
|
|
return (minutes / 60) * hourHeight;
|
|
}
|
|
|
|
double minutesForPixels(double pixels) {
|
|
return (pixels / hourHeight) * 60;
|
|
}
|
|
|
|
static double _clampHourHeight(double value) {
|
|
return value.clamp(minHourHeight, maxHourHeight);
|
|
}
|
|
}
|