-
Notifications
You must be signed in to change notification settings - Fork 2
[FTD #4] support circle for multi lines text, updated images #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TobiasRump
wants to merge
1
commit into
main
Choose a base branch
from
bugfix/FTD-4-circled-text-breaks-in-multiple-lines
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// ignore_for_file: public_member_api_docs, sort_constructors_first | ||
import 'dart:math'; | ||
|
||
import 'package:flutter_text_decorator/src/modules/circle/painter/open_circle_painter.dart'; | ||
|
||
/// Defines a set of angles for rendering an "open circle" decoration. | ||
/// | ||
/// This class encapsulates the start and sweep angles for two arcs | ||
/// (typically one for the bottom part of the circle and one for the top part) | ||
/// that together form an open or stylized circle. | ||
/// | ||
/// It provides `const` factories for predefined angle configurations, | ||
/// such as `bottomLeft()` or `topLeft()`, which can be used with | ||
/// [OpenCirclePainter] to specify the orientation of the circle's opening. | ||
/// Instances of this class are immutable. | ||
class CircleAngleOption { | ||
const CircleAngleOption({ | ||
required this.startAngleBottomCircle, | ||
required this.sweepAngleBottomCircle, | ||
required this.startAngleTopCircle, | ||
required this.sweepAngleTopCircle, | ||
}); | ||
|
||
const factory CircleAngleOption.bottomLeft() = _BottomLeftCircleAngleOption; | ||
|
||
/// The starting angle for the bottom arc, in radians. | ||
final double startAngleBottomCircle; | ||
|
||
/// The sweep angle for the bottom arc, in radians. | ||
final double sweepAngleBottomCircle; | ||
|
||
/// The starting angle for the top arc, in radians. | ||
final double startAngleTopCircle; | ||
|
||
/// The sweep angle for the top arc, in radians. | ||
final double sweepAngleTopCircle; | ||
} | ||
|
||
class _BottomLeftCircleAngleOption extends CircleAngleOption { | ||
const _BottomLeftCircleAngleOption() | ||
: super( | ||
startAngleBottomCircle: -1.5 + pi, | ||
sweepAngleBottomCircle: pi + 1.5, | ||
startAngleTopCircle: (pi + 6.2) + pi, | ||
sweepAngleTopCircle: pi - 1, | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,11 +43,10 @@ class ClosedCirclePainter extends TextDecoratorPainter with CircleConstraints { | |
..strokeWidth = decoration.strokeWidth | ||
..style = PaintingStyle.stroke; | ||
|
||
final circleSize = getCircleSizes(text: text, textStyle: textStyle); | ||
final circleSize = getCircleSizes(text: text, textStyle: textStyle, size: size); | ||
|
||
final scaledHorizontalRadius = circleSize.horizontalRadius * 2.1; | ||
final scaledVerticalRadiusBottomCircle = circleSize.verticalRadius * 2.9; | ||
const verticalOffset = 1.8; | ||
final scaledVerticalRadiusBottomCircle = circleSize.verticalRadius * 3.5; | ||
const verticalOffset = 2.5; | ||
|
||
final centerOffset = Offset( | ||
size.width / 2, | ||
|
@@ -57,7 +56,7 @@ class ClosedCirclePainter extends TextDecoratorPainter with CircleConstraints { | |
canvas.drawOval( | ||
Rect.fromCenter( | ||
center: centerOffset, | ||
width: scaledHorizontalRadius, | ||
width: size.width * 1.1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we implement this magic number as a param? |
||
height: scaledVerticalRadiusBottomCircle, | ||
), | ||
paint, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import 'dart:math'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_text_decorator/src/modules/base/decoration_base.dart'; | ||
import 'package:flutter_text_decorator/src/modules/base/text_decoration_painter.dart'; | ||
import 'package:flutter_text_decorator/src/modules/circle/classes/circle_angle_option.dart'; | ||
import 'package:flutter_text_decorator/src/modules/circle/mixins/circle_mixin.dart'; | ||
|
||
/// A [CustomPainter] that draws an "open circle" decoration around text. | ||
|
@@ -35,25 +35,27 @@ class OpenCirclePainter extends TextDecoratorPainter with CircleConstraints { | |
required super.text, | ||
required super.textStyle, | ||
required super.decoration, | ||
this.circleAngleOption = const CircleAngleOption.bottomLeft(), | ||
}) : assert(text != '' && decoration.strokeWidth > 0, 'text should not be empty and decoration.strokeWidth should be greater than 0'); | ||
|
||
/// Defines the start and sweep angles for the two arcs forming the open circle. | ||
/// | ||
/// Defaults to [CircleAngleOption.bottomLeft] if not specified. | ||
final CircleAngleOption circleAngleOption; | ||
|
||
@override | ||
void paint(Canvas canvas, Size size) { | ||
final paint = Paint() | ||
..color = decoration.color | ||
..strokeWidth = decoration.strokeWidth | ||
..style = PaintingStyle.stroke; | ||
|
||
final circleSize = getCircleSizes(text: text, textStyle: textStyle); | ||
final circleSize = getCircleSizes(text: text, textStyle: textStyle, size: size); | ||
|
||
final scaledHorizontalRadius = circleSize.horizontalRadius * 2.1; | ||
final scaledVerticalRadiusBottomCircle = circleSize.verticalRadius * 2.9; | ||
final scaledHorizontalRadius = circleSize.horizontalRadius * 2; | ||
final scaledVerticalRadiusBottomCircle = circleSize.verticalRadius * 3; | ||
Comment on lines
+55
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make those magic numbers as params? |
||
final scaledVerticalRadiusTopCircle = circleSize.verticalRadius * 3.5; | ||
const verticalOffset = 1.8; | ||
const startAngleBottomCircle = -1.5; | ||
const sweepAngleBottomCircle = pi + 1.5; | ||
const startAngleTopCircle = pi + 6.2; | ||
const sweepAngleTopCircle = pi - 1; | ||
|
||
final centerOffset = Offset( | ||
size.width / 2, | ||
|
@@ -67,8 +69,8 @@ class OpenCirclePainter extends TextDecoratorPainter with CircleConstraints { | |
width: scaledHorizontalRadius, | ||
height: scaledVerticalRadiusBottomCircle, | ||
), | ||
startAngleBottomCircle, | ||
sweepAngleBottomCircle, | ||
circleAngleOption.startAngleBottomCircle, | ||
circleAngleOption.sweepAngleBottomCircle, | ||
false, | ||
paint, | ||
) | ||
|
@@ -78,15 +80,21 @@ class OpenCirclePainter extends TextDecoratorPainter with CircleConstraints { | |
width: scaledHorizontalRadius, | ||
height: scaledVerticalRadiusTopCircle, | ||
), | ||
startAngleTopCircle, | ||
sweepAngleTopCircle, | ||
circleAngleOption.startAngleTopCircle, | ||
circleAngleOption.sweepAngleTopCircle, | ||
false, | ||
paint, | ||
); | ||
} | ||
|
||
@override | ||
bool shouldRepaint(covariant CustomPainter oldDelegate) { | ||
return false; | ||
if (oldDelegate is OpenCirclePainter) { | ||
return oldDelegate.circleAngleOption.startAngleBottomCircle != circleAngleOption.startAngleBottomCircle || | ||
oldDelegate.circleAngleOption.sweepAngleBottomCircle != circleAngleOption.sweepAngleBottomCircle || | ||
oldDelegate.circleAngleOption.startAngleTopCircle != circleAngleOption.startAngleTopCircle || | ||
oldDelegate.circleAngleOption.sweepAngleTopCircle != circleAngleOption.sweepAngleTopCircle; | ||
} | ||
return true; // Repaint if the delegate type changes or for other unknown reasons | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The centering looks off now and this makes the circle still overlap the circle. See: