Esempio n. 1
0
        /// <summary>
        /// generate the path for the border
        /// </summary>
        /// <param name="paint">the paint object for the path</param>
        /// <returns>a skpath representing the border of the floating label entry</returns>
        private SKPath GeneratePath(SKPaint paint)
        {
            var path = new SKPath();

            Rectangle viewBounds = SkCanvasView.FromPixels(borderlessEntry.Bounds);

            var   strokeWidth = (float)SkCanvasView.FromPixels(new Point(0, paint.StrokeWidth)).Y;
            float arcHeight   = (float)viewBounds.Height + (float)strokeWidth;

            var textSize = SkCanvasView.FromPixels(new Size(
                                                       width: CalculateBounds.GetTextWidth(borderlessEntry.Placeholder, borderlessEntry.TitleFontSize),
                                                       height: CalculateBounds.GetTextHeight(borderlessEntry.Placeholder, borderlessEntry.TitleFontSize)));


            // move the point next to the placeholder label
            path.MoveTo(
                x: (float)viewBounds.X + (float)textSize.Width + 3,
                y: (float)viewBounds.Y);

            float xCurrent = path.LastPoint.X;
            float yCurrent = path.LastPoint.Y;

            // line above the entry
            path.LineTo((float)viewBounds.Width + (float)viewBounds.X, yCurrent);

            xCurrent = path.LastPoint.X;

            // draw the arc pointing down (right arc)
            path.ArcTo(
                oval: new SKRect(xCurrent - arcHeight / 2, yCurrent, xCurrent + arcHeight / 2, yCurrent + arcHeight),
                startAngle: -90,
                sweepAngle: 180,
                forceMoveTo: false);

            // draw the line below the entry
            path.LineTo((float)viewBounds.X, path.LastPoint.Y);

            xCurrent = path.LastPoint.X;
            yCurrent = path.LastPoint.Y;

            // draw the arc from below entry to above entry (left arc)
            path.ArcTo(
                oval: new SKRect(xCurrent - arcHeight / 2, yCurrent - arcHeight, xCurrent + arcHeight / 2, yCurrent),
                startAngle: 90,
                sweepAngle: 180,
                forceMoveTo: false);

            _borderPath      = path;
            _strokeDashStart = new DashedStroke(
                intervals: new float[] { 0, new SKPathMeasure(_borderPath).Length },
                phase: -0);

            _strokeDashEnd = new DashedStroke(
                intervals: new float[] { new SKPathMeasure(_borderPath).Length, new SKPathMeasure(_borderPath).Length },
                phase: -0);

            CreateShader();

            return(_borderPath);
        }
Esempio n. 2
0
        /// <summary>
        /// change the button style when the user starts to enter a text
        /// </summary>
        /// <returns></returns>
        async Task PlaceholderToTitle()
        {
            Confirm.HeightRequest = Frame.Height;

            if (!IsValid)
            {
                Confirm.BackgroundColor = ButtonBackgroundColor.WithLuminosity(0.45);
                Confirm.TextColor       = ViewBackgroundColor;
            }

            var buttonWidth = CalculateBounds.GetTextWidth(Confirm.Text, Convert.ToSingle(Confirm.FontSize));

#if __IOS__
#endif

#if __ANDROID__
            buttonWidth *= DeviceDisplay.MainDisplayInfo.Density;
#endif
            Confirm.WidthRequest = buttonWidth;

            await Task.WhenAll(Confirm.OpacityTo(0, 1, (o) => Confirm.Opacity    = o, 300),
                               Task.Run(() => floatingLabelEntry.VerticalOptions = LayoutOptions.End));

            Confirm.HeightRequest = this.Frame.Height;
            Confirm.WidthRequest  = buttonWidth;
        }