Skip to content

Commit 73758f7

Browse files
committed
add horizontal padding
1 parent 70e0f99 commit 73758f7

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

example/lib/screens/examples/box_example_screen.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ class BoxExampleScreen extends StatelessWidget {
6363
borderRadius: 16,
6464
),
6565
const SizedBox(height: 32),
66-
TextDecorator.boxed(
67-
style: BoxStyle.curled,
68-
text: const Text(
69-
'Franz jagt im komplett verwahrlosten Taxi quer durch Berlin',
70-
style: TextStyle(fontSize: 16),
66+
Padding(
67+
padding: const EdgeInsets.all(16.0),
68+
child: TextDecorator.boxed(
69+
style: BoxStyle.curled,
70+
text: const Text(
71+
'Franz jagt im komplett verwahrlosten Taxi quer durch Berlin',
72+
style: TextStyle(fontSize: 16),
73+
),
74+
strokeWidth: 2,
75+
borderRadius: 16,
7176
),
72-
strokeWidth: 2,
73-
borderRadius: 16,
7477
),
7578
],
7679
),

lib/src/modules/box/painter/wavy_box_painter.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ class WavyBoxPainter extends CustomPainter {
3737
required this.text,
3838
required this.borderColor,
3939
this.padding = const EdgeInsets.all(8),
40+
this.nHorizontalSegments = 12,
41+
this.nVerticalSegments = 3,
4042
super.repaint,
4143
});
4244
// TODO(everyone): add padding?
4345
// TODO(everyone): add fill color?
4446
final Text text;
4547
final Color borderColor;
4648
final EdgeInsets padding;
49+
final int nHorizontalSegments;
50+
final int nVerticalSegments;
4751

4852
@override
4953
void paint(Canvas canvas, Size size) {
@@ -65,46 +69,44 @@ class WavyBoxPainter extends CustomPainter {
6569
final nLines = heightFactor.ceil();
6670
textHeight = nLines * textHeight;
6771

68-
const nHorizontalSegments = 10; // TODO: make available as param
69-
const nVerticalSegments = 2; // TODO: make available as param
70-
final availableWidth = min(textWidth, size.width);
71-
final availableHeight = max(textHeight, size.height);
72-
final widthHorizontalSegment = (availableWidth / nHorizontalSegments).ceil(); // TODO: remove ceil?
72+
final availableWidth = min(textWidth, size.width) + padding.horizontal;
73+
final availableHeight = max(textHeight, size.height) + padding.vertical;
74+
final widthHorizontalSegment = availableWidth / nHorizontalSegments;
7375
final heightVerticalSegment = availableHeight / nVerticalSegments;
7476

7577
const arcHeight = -10.0;
7678
const weight = 1.0;
77-
var lastX2 = 0.0;
79+
var lastX2 = 0.0 - padding.left;
7880

7981
// TODO(everyone): Fix corners, maybe with [arcTo]?
80-
final path = Path()..moveTo(0, 0);
82+
final path = Path()..moveTo(0 - padding.left, 0 - padding.top);
8183

8284
// Upper left to upper right
8385
for (var i = 1; i <= nHorizontalSegments; i++) {
84-
final x2 = i * widthHorizontalSegment / 1.0;
85-
path.conicTo(lastX2 + widthHorizontalSegment / 2, arcHeight, x2 / 1.0, 0, weight);
86+
final x2 = (i * widthHorizontalSegment / 1.0) - padding.left;
87+
path.conicTo(lastX2 + widthHorizontalSegment / 2, arcHeight - padding.top, x2 / 1.0, 0 - padding.top, weight);
8688
lastX2 = x2;
8789
}
8890

8991
// Upper right to lower right
90-
double lastY2 = 0;
92+
double lastY2 = 0 - padding.top;
9193
for (var i = 1; i <= nVerticalSegments; i++) {
92-
final y2 = i * heightVerticalSegment / 1.0;
94+
final y2 = (i * heightVerticalSegment / 1.0) - padding.top;
9395
path.conicTo(lastX2 - arcHeight, lastY2 + heightVerticalSegment / 2, lastX2, y2, weight);
9496
lastY2 = y2;
9597
}
9698

9799
// Lower right to lower left
98100
for (var i = nHorizontalSegments - 1; i >= 0; i--) {
99-
final x2 = i * widthHorizontalSegment / 1.0;
101+
final x2 = (i * widthHorizontalSegment / 1.0) - padding.left;
100102
path.conicTo(lastX2 - widthHorizontalSegment / 2, lastY2 - arcHeight, x2 / 1.0, lastY2, weight);
101103
lastX2 = x2;
102104
}
103105

104106
// Lower left to upper right
105107
for (var i = nVerticalSegments - 1; i >= 0; i--) {
106-
final y2 = i * heightVerticalSegment / 1.0;
107-
path.conicTo(arcHeight, y2 + heightVerticalSegment / 2, lastX2, y2, weight);
108+
final y2 = (i * heightVerticalSegment / 1.0) - padding.top;
109+
path.conicTo(arcHeight - padding.left, y2 + heightVerticalSegment / 2, 0 - padding.left, y2, weight);
108110
lastY2 = y2;
109111
}
110112

0 commit comments

Comments
 (0)