Skip to content

Commit dbaecdf

Browse files
committed
[FTD #4] support circle for multi lines text, updated images
1 parent 3150524 commit dbaecdf

File tree

12 files changed

+97
-120
lines changed

12 files changed

+97
-120
lines changed

documentation/img/box.png

16.6 KB
Loading

documentation/img/circle.png

23.6 KB
Loading

documentation/img/highlight.png

-1.7 KB
Loading

documentation/img/overview.png

-56.1 KB
Binary file not shown.

documentation/img/underline.png

15.3 KB
Loading

example/lib/screens/examples/box_example_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class BoxExampleScreen extends StatelessWidget {
5656
TextDecorator.boxed(
5757
style: BoxStyle.curled,
5858
text: const Text(
59-
'Curcled Box',
59+
'Curled Box',
6060
style: TextStyle(fontSize: 16),
6161
),
6262
strokeWidth: 2,

example/lib/screens/examples/circle_example_screen.dart

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,34 @@ class CircleExampleScreen extends StatelessWidget {
2323
),
2424
),
2525
const SizedBox(height: 32),
26+
Padding(
27+
padding: const EdgeInsets.symmetric(horizontal: 30.0),
28+
child: TextDecorator.circled(
29+
style: CircleStyle.basic,
30+
text: const Text(
31+
'Franz jagt im komplett verwahrlosten Taxi quer durch Berlin',
32+
style: TextStyle(fontSize: 16),
33+
textAlign: TextAlign.center,
34+
),
35+
),
36+
),
37+
const SizedBox(height: 64),
2638
TextDecorator.circled(
2739
text: const Text(
2840
'Circled Text',
2941
style: TextStyle(fontSize: 32),
3042
),
3143
),
3244
const SizedBox(height: 32),
33-
TextDecorator.circled(
34-
style: CircleStyle.basic,
35-
text: const Text(
36-
'Franz jagt im komplett verwahrlosten Taxi quer durch Berlin',
37-
style: TextStyle(fontSize: 16),
45+
Padding(
46+
padding: const EdgeInsets.symmetric(horizontal: 30.0),
47+
child: TextDecorator.circled(
48+
style: CircleStyle.circled,
49+
text: const Text(
50+
'Franz jagt im komplett verwahrlosten Taxi quer durch Berlin',
51+
style: TextStyle(fontSize: 16),
52+
textAlign: TextAlign.center,
53+
),
3854
),
3955
),
4056
],

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

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ignore_for_file: public_member_api_docs, sort_constructors_first
2+
import 'dart:math';
3+
4+
import 'package:flutter_text_decorator/src/modules/circle/painter/open_circle_painter.dart';
5+
6+
/// Defines a set of angles for rendering an "open circle" decoration.
7+
///
8+
/// This class encapsulates the start and sweep angles for two arcs
9+
/// (typically one for the bottom part of the circle and one for the top part)
10+
/// that together form an open or stylized circle.
11+
///
12+
/// It provides `const` factories for predefined angle configurations,
13+
/// such as `bottomLeft()` or `topLeft()`, which can be used with
14+
/// [OpenCirclePainter] to specify the orientation of the circle's opening.
15+
/// Instances of this class are immutable.
16+
class CircleAngleOption {
17+
const CircleAngleOption({
18+
required this.startAngleBottomCircle,
19+
required this.sweepAngleBottomCircle,
20+
required this.startAngleTopCircle,
21+
required this.sweepAngleTopCircle,
22+
});
23+
24+
const factory CircleAngleOption.bottomLeft() = _BottomLeftCircleAngleOption;
25+
26+
/// The starting angle for the bottom arc, in radians.
27+
final double startAngleBottomCircle;
28+
29+
/// The sweep angle for the bottom arc, in radians.
30+
final double sweepAngleBottomCircle;
31+
32+
/// The starting angle for the top arc, in radians.
33+
final double startAngleTopCircle;
34+
35+
/// The sweep angle for the top arc, in radians.
36+
final double sweepAngleTopCircle;
37+
}
38+
39+
class _BottomLeftCircleAngleOption extends CircleAngleOption {
40+
const _BottomLeftCircleAngleOption()
41+
: super(
42+
startAngleBottomCircle: -1.5 + pi,
43+
sweepAngleBottomCircle: pi + 1.5,
44+
startAngleTopCircle: (pi + 6.2) + pi,
45+
sweepAngleTopCircle: pi - 1,
46+
);
47+
}

lib/src/modules/circle/mixins/circle_mixin.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter/widgets.dart';
23
import 'package:flutter_text_decorator/src/modules/circle/classes/circle_size.dart';
34

45
/// A mixin that provides a utility method to calculate dimensions
@@ -19,12 +20,13 @@ mixin CircleConstraints {
1920
CircleSize getCircleSizes({
2021
required String text,
2122
required TextStyle textStyle,
23+
required Size size,
2224
}) {
2325
final textSpan = TextSpan(text: text, style: textStyle);
2426
final textPainter = TextPainter(
2527
text: textSpan,
2628
textDirection: TextDirection.ltr,
27-
)..layout();
29+
)..layout(maxWidth: size.width);
2830

2931
const textHeightOffset = 2;
3032
const textWidthScale = 1.8;

0 commit comments

Comments
 (0)