UnityTech / UIWidgets

UIWidget is a Unity Package which helps developers to create, debug and deploy efficient, cross-platform Apps.
Other
1.97k stars 256 forks source link

Paint.StrokeCap behaviour not match to Flutter doc #112

Closed JustinFincher closed 5 years ago

JustinFincher commented 5 years ago

Environment: Unity 2018.3.11f1, macOS, UIWidgets commit d73cf411752b0ab6e73587b4cc8d46707cb8cc46

When drawing lines in AbstractCustomPainter subclass, the behavior of Paint.strokeCap differs from the designated behavior described in the flutter doc, as StrokeCap.round shows a half-painted line cap.

Test Script:

using Unity.UIWidgets.engine;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;

namespace FinGameWorks.Scripts.Views.Test
{
    public class CurveTestPanel : UIWidgetsPanel
    {
        protected override Widget createWidget()
        {
            return new CustomPaint(foregroundPainter:new TestCurveCustomPainter());
        }
    }

    public class TestCurveCustomPainter : AbstractCustomPainter
    {
        public override void paint(Canvas canvas, Size size)
        {
            Paint bezierPaint = new Paint
            {
                style = PaintingStyle.stroke, 
                color = Color.black, 
                strokeWidth = 5, 
                strokeCap = StrokeCap.round,
                strokeJoin = StrokeJoin.round
            };
            Path bezierPath = new Path();
            float offset = 60.0f;
            bezierPath.moveTo(10, 10);
            bezierPath.bezierTo(10 + offset,10,size.width - 10 - offset,size.height-10,size.width - 10,size.height-10);

            canvas.drawPath(bezierPath, bezierPaint);
        }

        public override bool shouldRepaint(CustomPainter oldDelegate)
        {
            return true;
        }
    }
}

Test Image: image

Notice line caps are not rounded.

kgdev commented 5 years ago

https://github.com/UnityTech/UIWidgets/pull/114

fixed.