Exemple #1
0
 public HSLColor withLightness(float lightness)
 {
     return(HSLColor.fromAHSL(this.alpha, this.hue, this.saturation, lightness));
 }
Exemple #2
0
        public override Widget build(BuildContext context)
        {
            float thumbOffset = 15f;
            Color _thumbColor = Colors.black;

            return(new LayoutBuilder(builder: (BuildContext _, BoxConstraints box) =>
            {
                switch (trackType)
                {
                case TrackType.hue:
                    thumbOffset += (box.maxWidth - 30f) * hsvColor.hue / 360f;
                    _thumbColor = HSVColor.fromAHSV(1f, hsvColor.hue, 1f, 1f).toColor();
                    break;

                case TrackType.saturation:
                    thumbOffset += (box.maxWidth - 30f) * hsvColor.saturation;
                    _thumbColor =
                        HSVColor.fromAHSV(1f, hsvColor.hue, hsvColor.saturation, 1f)
                        .toColor();
                    break;

                case TrackType.saturationForHSL:
                    thumbOffset += (box.maxWidth - 30f) * Utils.hsvToHsl(hsvColor).saturation;
                    _thumbColor = HSLColor.fromAHSL(
                        1f, hsvColor.hue, Utils.hsvToHsl(hsvColor).saturation, 0.5f)
                                  .toColor();
                    break;

                case TrackType.value:
                    thumbOffset += (box.maxWidth - 30f) * hsvColor.value;
                    _thumbColor = HSVColor.fromAHSV(1f, hsvColor.hue, 1f, hsvColor.value)
                                  .toColor();
                    break;

                case TrackType.lightness:
                    thumbOffset += (box.maxWidth - 30f) * Utils.hsvToHsl(hsvColor).lightness;
                    _thumbColor = HSLColor.fromAHSL(
                        1f, hsvColor.hue, 1f, Utils.hsvToHsl(hsvColor).lightness)
                                  .toColor();
                    break;

                case TrackType.red:
                    thumbOffset += (box.maxWidth - 30f) * hsvColor.toColor().red / 0xff;
                    _thumbColor = hsvColor.toColor().withOpacity(1f);
                    break;

                case TrackType.green:
                    thumbOffset +=
                        (box.maxWidth - 30f) * hsvColor.toColor().green / 0xff;
                    _thumbColor = hsvColor.toColor().withOpacity(1f);
                    break;

                case TrackType.blue:
                    thumbOffset += (box.maxWidth - 30f) * hsvColor.toColor().blue / 0xff;
                    _thumbColor = hsvColor.toColor().withOpacity(1f);
                    break;

                case TrackType.alpha:
                    thumbOffset += (box.maxWidth - 30f) * hsvColor.toColor().opacity;
                    _thumbColor = Colors.black.withOpacity(hsvColor.alpha);
                    break;
                }//switch

                return new CustomMultiChildLayout(
                    layoutDelegate: new _SliderLayout(),
                    children: new List <Widget> {
                    new LayoutId(
                        id: _SliderLayout.track,
                        child: new ClipRRect(
                            borderRadius: BorderRadius.all(Radius.circular(3f)),
                            child: new CustomPaint(
                                painter: new TrackPainter(this.trackType, this.hsvColor)
                                ) //CustomPaint
                            )
                        ),        //LayoutId
                    new LayoutId(
                        id: _SliderLayout.thumb,
                        child: Transform.translate(
                            offset: new Offset(thumbOffset, 0f),
                            child: new CustomPaint(
                                painter: new ThumbPainter(
                                    thumbColor: !displayThumbColor ? null : _thumbColor,
                                    fullThumbColor: fullThumbColor
                                    ) //ThumbPainter
                                )     //CustomPaint
                            )         //Transform
                        ),            //LayoutId
                    new LayoutId(
                        id: _SliderLayout.gestureContainer,
                        child: new LayoutBuilder(
                            builder: (BuildContext __, BoxConstraints _box) => {
                        RenderBox getBox = context.findRenderObject() as RenderBox;
                        return new GestureDetector(
                            child: new Container(color: Colors.transparent),
                            onPanDown: (DragDownDetails details) => { slideEvent(getBox, box, details.globalPosition); },
                            onPanUpdate: (DragUpdateDetails details ) => { slideEvent(getBox, box, details.globalPosition); }
                            );
                    }
                            ) //LayoutBuilder
                        )     //LayoutId
                }             //list Widget
                    );        //CustomMultiChildLayout
            }));              //LayoutBuilder
        }
Exemple #3
0
 public HSLColor withSaturation(float saturation)
 {
     return(HSLColor.fromAHSL(this.alpha, this.hue, saturation, this.lightness));
 }
Exemple #4
0
 public HSLColorPainter(HSLColor hslColor, Color pointerColor = null)
 {
     this.hslColor     = hslColor;
     this.pointerColor = pointerColor;
 }