Skip to content

Commit e85f122

Browse files
committed
Fix hue ring rendering outside of it's bounds
The hue ring was rendering outside of it's bounds because drawCircle draws the stroke width half before the radius and the other half after. This commit fixes that by subtracting half the stroke width from the radius. HueRingPicker was adjusted to retain it's previous UI and to allow for larger stroke widths without clipping
1 parent 9b4942b commit e85f122

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

lib/src/colorpicker.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
library hsv_picker;
66

7+
import 'dart:math';
8+
79
import 'package:flutter/material.dart';
810
import 'palette.dart';
911
import 'utils.dart';
@@ -697,11 +699,11 @@ class _HueRingPickerState extends State<HueRingPicker> {
697699
ClipRRect(
698700
borderRadius: widget.pickerAreaBorderRadius,
699701
child: Padding(
700-
padding: const EdgeInsets.all(15),
702+
padding: const EdgeInsets.all(5),
701703
child: Stack(alignment: AlignmentDirectional.center, children: <Widget>[
702704
SizedBox(
703-
width: widget.colorPickerHeight,
704-
height: widget.colorPickerHeight,
705+
width: widget.colorPickerHeight + widget.hueRingStrokeWidth,
706+
height: widget.colorPickerHeight + widget.hueRingStrokeWidth,
705707
child: ColorPickerHueRing(
706708
currentHsvColor,
707709
onColorChanging,
@@ -710,8 +712,8 @@ class _HueRingPickerState extends State<HueRingPicker> {
710712
),
711713
),
712714
SizedBox(
713-
width: widget.colorPickerHeight / 1.6,
714-
height: widget.colorPickerHeight / 1.6,
715+
width: (widget.colorPickerHeight - widget.hueRingStrokeWidth) / 1.45,
716+
height: (widget.colorPickerHeight - widget.hueRingStrokeWidth) / 1.45,
715717
child: ColorPickerArea(currentHsvColor, onColorChanging, PaletteType.hsv),
716718
)
717719
]),
@@ -770,16 +772,16 @@ class _HueRingPickerState extends State<HueRingPicker> {
770772
ClipRRect(
771773
borderRadius: widget.pickerAreaBorderRadius,
772774
child: Padding(
773-
padding: const EdgeInsets.all(15),
775+
padding: const EdgeInsets.all(5),
774776
child: Stack(alignment: AlignmentDirectional.topCenter, children: <Widget>[
775777
SizedBox(
776-
width: widget.colorPickerHeight - widget.hueRingStrokeWidth * 2,
777-
height: widget.colorPickerHeight - widget.hueRingStrokeWidth * 2,
778+
width: widget.colorPickerHeight - widget.hueRingStrokeWidth,
779+
height: widget.colorPickerHeight - widget.hueRingStrokeWidth,
778780
child: ColorPickerHueRing(currentHsvColor, onColorChanging, strokeWidth: widget.hueRingStrokeWidth),
779781
),
780782
Column(
781783
children: [
782-
SizedBox(height: widget.colorPickerHeight / 8.5),
784+
SizedBox(height: widget.colorPickerHeight / 8.5 + widget.hueRingStrokeWidth / 2),
783785
ColorIndicator(currentHsvColor),
784786
const SizedBox(height: 10),
785787
ColorPickerInput(

lib/src/palette.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ class HueRingPainter extends CustomPainter {
526526
void paint(Canvas canvas, Size size) {
527527
Rect rect = Offset.zero & size;
528528
Offset center = Offset(size.width / 2, size.height / 2);
529-
double radio = size.width <= size.height ? size.width / 2 : size.height / 2;
529+
double radio = (size.width <= size.height ? size.width / 2 : size.height / 2) - strokeWidth /2;
530530

531531
final List<Color> colors = [
532532
const HSVColor.fromAHSV(1.0, 360.0, 1.0, 1.0).toColor(),

0 commit comments

Comments
 (0)