Skip to content

Commit 48c919e

Browse files
committed
feat: simple shapes
1 parent 25f7d34 commit 48c919e

File tree

6 files changed

+84
-0
lines changed

6 files changed

+84
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ doc/api/
2525

2626
.flutter-plugins
2727
.flutter-plugins-dependencies
28+
29+
.DS_Store

lib/devspace.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ part 'models/geometry.dart';
247247

248248
part 'my_service/my_service.dart';
249249

250+
// shapes
251+
252+
part 'shapes/circle.dart';
253+
250254
// test_data
251255

252256
part 'test_data/test_data.dart';

lib/extended_theme/dimensions_theme_data.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ class DimensionsThemeData {
3131
this.lineThicknessS = 0.5,
3232
this.lineThicknessM = 1.0,
3333
this.lineThicknessL = 2.0,
34+
this.borderThicknessXS = 1.0,
3435
this.borderThicknessS = 2.0,
3536
this.borderThicknessM = 3.0,
3637
this.borderThicknessL = 5.0,
38+
this.borderThicknessXL = 8.0,
3739
this.iconSizeXS = 13.0,
3840
this.iconSizeS = 21.0,
3941
this.iconSizeM = 34.0,
@@ -73,9 +75,11 @@ class DimensionsThemeData {
7375
final double barHeightL;
7476
final double barHeightXL;
7577

78+
final double borderThicknessXS;
7679
final double borderThicknessS;
7780
final double borderThicknessM;
7881
final double borderThicknessL;
82+
final double borderThicknessXL;
7983

8084
final double lineThicknessS;
8185
final double lineThicknessM;

lib/shapes/circle.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
part of devspace;
2+
3+
4+
class Circle extends StatelessWidget
5+
{
6+
final double? strokeWidth;
7+
final Color? color;
8+
final Widget? child;
9+
10+
const Circle({
11+
super.key,
12+
this.color,
13+
// setting strokeWith to 0.0 will fill the circle entirely
14+
this.strokeWidth,
15+
this.child,
16+
});
17+
18+
@override
19+
Widget build(BuildContext context)
20+
{
21+
Color col = color ?? context.colors.primary;
22+
double width = strokeWidth ?? context.dimensions.borderThicknessM;
23+
24+
return CustomPaint(
25+
painter: CirclePainter(
26+
color: col,
27+
strokeWidth: width,
28+
),
29+
child: child,
30+
);
31+
}
32+
}
33+
34+
class CirclePainter extends CustomPainter {
35+
36+
final Color color;
37+
final double strokeWidth;
38+
39+
CirclePainter({
40+
required this.color,
41+
required this.strokeWidth,
42+
});
43+
44+
@override
45+
void paint(Canvas canvas, Size size)
46+
{
47+
Dev.log('CirclePainter.paint', 'size', size);
48+
final paint = Paint()
49+
..color = color
50+
..strokeWidth = strokeWidth
51+
..style = strokeWidth == 0.0 ? PaintingStyle.fill : PaintingStyle.stroke;
52+
53+
final center = Offset(size.width / 2, size.height / 2);
54+
55+
final radius = size.width / 2;
56+
57+
canvas.drawCircle(center, radius, paint);
58+
}
59+
60+
@override
61+
bool shouldRepaint(covariant CustomPainter oldDelegate)
62+
{
63+
return false;
64+
}
65+
}

lib/type_extensions/double.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ extension DoubleExtension on double {
1515
return math.Random().nextDouble() < this;
1616
}
1717

18+
/// Converts the double from degrees to radians.
1819
double toRadian()
1920
{
2021
return this / 180 * math.pi;
2122
}
2223

24+
/// Converts the double from radians to degrees.
2325
double toDegree()
2426
{
2527
return this / math.pi * 180;

lib/type_extensions/int.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ extension IntExtension on int {
2828
{
2929
return List.generate(this, generator);
3030
}
31+
32+
33+
/// Converts the int from degrees to radians.
34+
double toRadian()
35+
{
36+
return toDouble().toRadian();
37+
}
3138
}

0 commit comments

Comments
 (0)