示例#1
0
        private void DrawThumb(ref ThumbDraw thumbDraw, RangeSliderThumbOptions thumbOptions)
        {
            // Colors
            thumbDraw.Paint.Color = SKColor.Parse((thumbOptions.BackgroundColor ?? _defaultColor));

            thumbDraw.ValueTextDraw.Paint.Color = SKColor.Parse((thumbOptions.TextColor ?? _defaultColor));

            float percentage = GetXPercentage(thumbOptions);

            if (percentage == -1f)
            {
                return;
            }

            // Calculate thumb bounds
            thumbDraw.Radius = _thumbsCanvasInfo.ImageInfo.Rect.MidY
                               - (_thumbsCanvasInfo.ImageInfo.Rect.MidY * 0.5f);

            thumbDraw.Point = new SKPoint
            {
                X = percentage * _thumbsCanvasInfo.ImageInfo.Width,
                Y = _thumbsCanvasInfo.ImageInfo.Rect.MidY
            };

            CheckThumbBounds(ref thumbDraw);

            _thumbsCanvasInfo.Canvas.DrawCircle(thumbDraw.Point, thumbDraw.Radius, thumbDraw.Paint);
        }
示例#2
0
        private float GetXPercentage(RangeSliderThumbOptions thumbOptions)
        {
            // Check values
            if (!HasValues())
            {
                return(-1);
            }

            // Calculate value index
            int index = Values.FindIndex(v => v == thumbOptions.Value);

            _lastPercentage = (float)index / (Values.Count - 1);

            return(_lastPercentage);
        }
示例#3
0
        private void DrawThumbIcon(ref ThumbDraw thumbDraw, RangeSliderThumbOptions thumbOptions)
        {
            // Set size
            thumbDraw.IconTextDraw.Paint.TextSize = thumbDraw.Radius * 0.75f;

            // Measure
            thumbDraw.IconTextDraw.Paint.MeasureText(thumbOptions.Icon,
                                                     ref thumbDraw.IconTextDraw.Bounds);

            // Update paint
            thumbDraw.IconTextDraw.Paint.Color = SKColor.Parse(thumbOptions.IconColor ?? _defaultColor);

            // Draw
            var point = new SKPoint
            {
                X = thumbDraw.Point.X - Math.Abs(thumbDraw.IconTextDraw.Bounds.MidX),
                Y = thumbDraw.Point.Y + Math.Abs(thumbDraw.IconTextDraw.Bounds.MidY)
            };

            _thumbsCanvasInfo.Canvas.DrawText(thumbOptions.Icon,
                                              point,
                                              thumbDraw.IconTextDraw.Paint);
        }