Skip to content

Commit 8c70bb1

Browse files
Update README.md
1 parent ab46f42 commit 8c70bb1

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
Bundle of Stylish customizable Color pickers, selectors, colorful sliders written with Jetpack
44
Compose enables users to choose from HSL, HSV or RGB color models to pick Solid colors or gradients.
5+
With colorful Sliders, panels, hex and color displays and various elements to create customized
6+
pickers based on preference.
7+
8+
There are 10(for now) different color pickers and 3 different color+gradient pickers available
9+
to choose from to use as Composables or inside dialogs that are available in demos.
10+
11+
512

613
Inspired
714
by [mchome's flutter_colorpicker for Flutter](https://github.com/mchome/flutter_colorpicker)
@@ -23,12 +30,139 @@ it's possible to create new ones either.
2330
| ----------|-----------|
2431
| <img src="./screenshots/colorpicker/cp_rect_hue_saturation_hsl.png"/> | <img src="./screenshots/colorpicker/cp_rect_hue_lightness_hsl.png"/> |
2532

33+
#### Implementation Hue Ring-Diamond HSL, Hue- Ring-Rect HSL,Hue Ring-Rect HSV
34+
35+
```
36+
ColorPickerRingRectHSL(
37+
modifier: Modifier = Modifier,
38+
initialColor: Color,
39+
ringOuterRadiusFraction: Float = .9f,
40+
ringInnerRadiusFraction: Float = .6f,
41+
ringBackgroundColor: Color = Color.Transparent,
42+
ringBorderStrokeColor: Color = Color.Black,
43+
ringBorderStrokeWidth: Dp = 4.dp,
44+
selectionRadius: Dp = 8.dp,
45+
onColorChange: (Color) -> Unit
46+
)
47+
```
48+
49+
ColorPicker with `SelectorRingHue` hue selector and `SelectorRectSaturationLightnessHSL` saturation lightness Selector that uses [HSL](https://en.wikipedia.org/wiki/HSL_and_HSV) color model as base.
50+
This color picker has tabs section that can be changed between HSL, HSV and RGB color models and color can be set using `CompositeSliderPanel` which contains sliders for each color models.
51+
52+
* **initialColor** color that is passed to this picker initially.
53+
* **ringOuterRadiusFraction** outer radius of `SelectorRingHue`.
54+
* **ringInnerRadiusFraction** inner radius of `SelectorRingHue`.
55+
* **ringBackgroundColor** background from center to inner radius of `SelectorRingHue`.
56+
* **ringBorderStrokeColor** stroke color for drawing borders around inner or outer radius.
57+
* **ringBorderStrokeWidth** stroke width of borders.
58+
* **selectionRadius radius** of white and black circle selector.
59+
* **onColorChange** callback that is triggered when `Color` is changed using `SelectorRingHue` `SelectorDiamondSaturationLightnessHSL` or `CompositeSliderPanel`
60+
61+
#### Implementation for other Color Pickers
62+
```
63+
ColorPickerCircleValueHSV(
64+
modifier: Modifier = Modifier,
65+
selectionRadius: Dp = 8.dp,
66+
initialColor: Color,
67+
onColorChange: (Color) -> Unit
68+
)
69+
```
70+
* **selectionRadius radius** of white and black circle selector.
71+
* **initialColor** color that is passed to this picker initially.
72+
* **onColorChange** callback that is triggered when `Color` is changed
73+
2674
### Gradient Color Pickers
2775

2876
| Hue Ring-Diamond HSL | Hue Ring-Diamond HSL2 | Hue- Ring-Rect HSL | Hue Ring-Rect HSV|
2977
| ----------|-----------| -----------| -----------|
3078
| <img src="./screenshots/colorpicker/cp_gradient_diamond_hsl.png"/> | <img src="./screenshots/colorpicker/cp_gradient_diamond_hsl2.png"/> | <img src="./screenshots/colorpicker/cp_gradient_rect_hsl.png"/> | <img src="./screenshots/colorpicker/cp_gradient_rect_hsv.png"/> |
3179

80+
### Implementation
81+
```
82+
ColorPickerGradientRingDiamondHSL(
83+
modifier: Modifier = Modifier,
84+
initialBrushColor: BrushColor,
85+
gradientColorState: GradientColorState = rememberGradientColorState(),
86+
ringOuterRadiusFraction: Float = .9f,
87+
ringInnerRadiusFraction: Float = .6f,
88+
ringBackgroundColor: Color = Color.Black,
89+
ringBorderStrokeColor: Color = Color.Black,
90+
ringBorderStrokeWidth: Dp = 4.dp,
91+
selectionRadius: Dp = 8.dp,
92+
onBrushColorChange: (BrushColor) -> Unit
93+
)
94+
```
95+
Gradients in Compose might require **Size**, Offset, or radius based on Linear, Radial, or Sweep
96+
gradient is implemented.
97+
98+
A `GradientColorState` should be provided to this picker that hold **brush**, **color** and
99+
other meta-data about the gradient or color. When no size is provided it's not possible
100+
to choose linear gradient other than with angle, or other gradients.
101+
102+
```
103+
@Composable
104+
fun rememberGradientColorState(
105+
color: Color = Color.Unspecified,
106+
size: DpSize = DpSize.Zero
107+
): GradientColorState {
108+
109+
val density = LocalDensity.current
110+
111+
return remember {
112+
113+
val sizePx = if (size == DpSize.Zero) {
114+
Size.Zero
115+
} else {
116+
with(density) {
117+
Size(
118+
size.width.toPx(),
119+
size.height.toPx()
120+
)
121+
}
122+
}
123+
GradientColorState(color, sizePx)
124+
}
125+
}
126+
```
127+
128+
Set size of your container that you wish to display gradients in and pass it
129+
```
130+
val size = DpSize(150.dp, 100.dp)
131+
132+
and initial color to be displayed on picker
133+
val gradientColorState = rememberGradientColorState(
134+
color = currentBrushColor.color,
135+
size = size
136+
)
137+
```
138+
139+
`BrushColor` class is a color and brush wrapper class that is returned from gradient pickers
140+
in **onChange** callback instead of **Color**
141+
142+
```
143+
/**
144+
* Data class that contains [Brush] and [Color] and can return either based on user selection.
145+
*/
146+
data class BrushColor(
147+
var color: Color = Color.Unspecified,
148+
var brush: Brush? = null
149+
) {
150+
/**
151+
* [Brush] that is not **null** [brush] property or [SolidColor] that is not nullable and
152+
* contains [color] property as [SolidColor.value]
153+
*/
154+
val activeBrush: Brush
155+
get() = brush ?: solidColor
156+
157+
/**
158+
* [SolidColor] is a [Brush] that
159+
* wraps [color] property that is used for [activeBrush] if [brush] property is **null**
160+
*/
161+
val solidColor = SolidColor(color)
162+
}
163+
```
164+
165+
32166
### Demos
33167

34168
* `SaturationSelectorDemo` different type of Hue/Saturation/Value/Lightness Selectors

0 commit comments

Comments
 (0)