Skip to content

Dev #6

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

Merged
merged 2 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions lib/widgets/comment_child_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ class CommentChildWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
final EdgeInsets padding =
EdgeInsets.only(left: avatarRoot!.width + 8.0, bottom: 8, top: 8);
bool isRTL = Directionality.of(context) == TextDirection.rtl;
final EdgeInsets padding = EdgeInsets.only(
left: isRTL ? 0 : avatarRoot!.width + 8.0,
bottom: 8,
top: 8,
right: isRTL ? avatarRoot!.width + 8.0 : 0);

return CustomPaint(
painter: _Painter(
isLast: isLast!,
padding: padding,
textDirection: Directionality.of(context),
avatarRoot: avatarRoot,
avatarChild: avatar!.preferredSize,
pathColor: context.watch<TreeThemeData>().lineColor,
Expand All @@ -50,14 +55,15 @@ class _Painter extends CustomPainter {
bool isLast = false;

EdgeInsets? padding;

final TextDirection textDirection;
Size? avatarRoot;
Size? avatarChild;
Color? pathColor;
double? strokeWidth;

_Painter({
required this.isLast,
required this.textDirection,
this.padding,
this.avatarRoot,
this.avatarChild,
Expand All @@ -76,21 +82,24 @@ class _Painter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Path path = Path();
path.moveTo(avatarRoot!.width / 2, 0);
if (textDirection == TextDirection.rtl) canvas.translate(size.width, 0);
double rootDx = avatarRoot!.width / 2;
if (textDirection == TextDirection.rtl) rootDx *= -1;
path.moveTo(rootDx, 0);
path.cubicTo(
avatarRoot!.width / 2,
rootDx,
0,
avatarRoot!.width / 2,
rootDx,
padding!.top + avatarChild!.height / 2,
avatarRoot!.width,
rootDx * 2,
padding!.top + avatarChild!.height / 2,
);
canvas.drawPath(path, _paint);

if (!isLast) {
canvas.drawLine(
Offset(avatarRoot!.width / 2, 0),
Offset(avatarRoot!.width / 2, size.height),
Offset(rootDx, 0),
Offset(rootDx, size.height),
_paint,
);
}
Expand Down
13 changes: 10 additions & 3 deletions lib/widgets/root_comment_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RootCommentWidget extends StatelessWidget {
avatar.preferredSize,
context.watch<TreeThemeData>().lineColor,
context.watch<TreeThemeData>().lineWidth,
Directionality.of(context)
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -37,7 +38,8 @@ class RootPainter extends CustomPainter {
late Paint _paint;
Color? pathColor;
double? strokeWidth;
RootPainter(this.avatar, this.pathColor, this.strokeWidth) {
final TextDirection textDecoration;
RootPainter(this.avatar, this.pathColor, this.strokeWidth, this.textDecoration) {
_paint = Paint()
..color = pathColor!
..style = PaintingStyle.stroke
Expand All @@ -47,9 +49,14 @@ class RootPainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
if(textDecoration == TextDirection.rtl)
canvas.translate(size.width, 0);
double dx = avatar!.width / 2;
if(textDecoration == TextDirection.rtl)
dx *= -1;
canvas.drawLine(
Offset(avatar!.width / 2, avatar!.height),
Offset(avatar!.width / 2, size.height),
Offset(dx, avatar!.height),
Offset(dx, size.height),
_paint,
);
}
Expand Down