All checks were successful
ci/woodpecker/push/build Pipeline was successful
Signed-off-by: Nikolai Rodionov <allanger@posteo.com>
90 lines
2.3 KiB
Dart
90 lines
2.3 KiB
Dart
import 'dart:math' as math;
|
|
import 'package:flutter/material.dart';
|
|
import 'package:softplayer_web/shared/ui/colors/light_mode.dart';
|
|
|
|
class AuthDecoration extends StatelessWidget {
|
|
final double spacing;
|
|
final Color color;
|
|
|
|
const AuthDecoration({
|
|
super.key,
|
|
this.spacing = 24,
|
|
this.color = Colors.blue,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
return Container(
|
|
color: LightModeColors.backgroundElevated,
|
|
child: FractionallySizedBox(
|
|
widthFactor: 0.3,
|
|
alignment: Alignment.centerLeft,
|
|
child: CustomPaint(
|
|
painter: _GridPainter(spacing: spacing, color: color),
|
|
child: const SizedBox.expand(),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
// todo: Some AI generated shite, that doesn't work
|
|
class _GridPainter extends CustomPainter {
|
|
final double spacing;
|
|
final Color color;
|
|
|
|
_GridPainter({required this.spacing, required this.color});
|
|
|
|
static const double maxSquare = 85;
|
|
static const double minSquare = 48; // 2x gap
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
final paint = Paint()..color = color;
|
|
|
|
// ✅ outer padding included in layout math
|
|
final innerWidth = size.width - spacing * 2;
|
|
final innerHeight = size.height - spacing * 2;
|
|
|
|
int columns = 10;
|
|
|
|
double calcSize(int cols) {
|
|
return (innerWidth - (cols - 1) * spacing) / cols;
|
|
}
|
|
|
|
// choose columns safely
|
|
while (columns > 1 && calcSize(columns) < minSquare) {
|
|
columns--;
|
|
}
|
|
|
|
double square = calcSize(columns);
|
|
square = math.min(square, maxSquare);
|
|
|
|
final rows = (innerHeight / (square + spacing)).ceil();
|
|
|
|
for (int row = 0; row < rows; row++) {
|
|
final y = spacing + row * (square + spacing);
|
|
|
|
for (int col = 0; col < columns; col++) {
|
|
final x = spacing + col * (square + spacing);
|
|
|
|
final rect = Rect.fromLTWH(x, y, square, square);
|
|
|
|
canvas.drawRRect(
|
|
RRect.fromRectAndRadius(rect, const Radius.circular(6)),
|
|
paint,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(covariant _GridPainter oldDelegate) {
|
|
return oldDelegate.spacing != spacing || oldDelegate.color != color;
|
|
}
|
|
}
|